Endless loop and OOM while adding constraint to a IncrementalTin. #113
Replies: 4 comments 2 replies
-
I will look at this over the weekend. Sorry I can't jump on it right away. But your timing is good because I am getting ready to release a new version of the Tinfour library. I will delay the release until I fix the issue you've identified. In the meantime, one thing you could try is to use the Tinfour LinearConstraint class rather than the PolygonConstraint. I realize that won't accomplish quite what you're trying to do here, but it may yield some insights into the problem. A quick question... One of the features of JTS is the ability to check a polygon geometry for correctness. Do you know if the operations your code performs such a verification? In particular, Tinfour has no explicit protection from self-intersecting polygons. JTS is a pretty awesome package and their geometry checker ought to be able to find anything that would present a problem for Tinfour. Right now, my working hypothesis is that the input geometry is fine and that there is a bug in the Tinfour code. But if you have the means to do a check, it would help me moving forward. Also, one other thing. I notice in the code snippet that you provide, there is an "++iSegment" operation. This puzzles me because I never use the pre-increment operator in my code (no important reason, just personal style). I also can't find a instance of it in the current code base. Would it be possible to download the latest Tinfour code and try processing your data with it? |
Beta Was this translation helpful? Give feedback.
-
I copied out your data and coded your example without using the JTS. When I run the data in clockwise order (the order specified in the raw coordinate string), it works fine. However, when I run it in counter-clockwise order, I get the same infinite loop that you saw.
|
Beta Was this translation helpful? Give feedback.
-
I am still investigating this problem, so some of what I say here is speculation. I suspect that there is a bug in the code that is only triggered under unusual conditions. When I constructed the constraint in the order of the coordinates from your original example (clockwise), they did not trigger the bug. But when I reoriented them to the opposite order (counterclockwise), they did trigger the bug. From your discussion, I'm pretty sure that counterclockwise is the desired ordering. Counterclockwise encloses an area with a polygon. Clockwise encodes a "hole" in a polygon. So what I need to do is to find the bug and fix it. Do you have a picture of your polygon? That might help expedite my work. Since this is a free, open-source project, I only have time to work on it when I am not at my job or doing family obligations. So I won't be able to work on the code until the weekend. Finally, I feel that I am fortunate to have an example of a polygon that triggers the bug. It is the only way I can find (and fix) problems. So I am grateful to you for providing such an excellent example. 谢谢 Gary |
Beta Was this translation helpful? Give feedback.
-
I investigated further. Although the constraint polygon in your test is valid (not self-intersecting), it is challenging. Its shape is nearly flat. I've attached a picture of the vertices. I am still working on the problem, but there is one change that you could make to your code that would give you a temporary solution. When you construct your TIN, try this variation:
The Tinfour IncrementalTIN class uses a "nominal point spacing" value (in this case 0.1) to establish numerical thresholds for how to handle the limits of numerical precision in floating-point arithmetic. For example, we compute a distance threshold to tell the code when to treat two closely spaced vertices as a single vertex. When you construct IncrementalTIN with no arguments, it assumes a nominal point spacing of 1.0. But for your constraints, 1.0 is too large. The alternate 0.1 does work. 0.01 would work too. I still consider this an open problem, but I hope this temporary solution will allow you to move forward with your work until I have a way for IncrementalTin to handle the problematic geometry. The image below show views of the geometry for constraint polygon and the vertices from which it is formed. |
Beta Was this translation helpful? Give feedback.
-
Here's the code to reproduce the ptoblem.
I debugged and found that the code was stuck at org.tinfour.standard.IncrementalTin#processConstraint, in a for-loop:

Any suggestions on how to deal with such case?
Beta Was this translation helpful? Give feedback.
All reactions