-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unexpected intersection of two overlapping polygons - a multipoint #820
Comments
This looks similar to #784. It uses very high precision numbers as well. I think the reason it works in TestBuilder is that the numbers get rounded off slightly in the numeric parsing routines. |
Yeah, I figured that it is likely due to precision, e.g.
Somewhat of a side topic - maybe we are wrong to use the floating precision model in our app in the first place? Maybe you could suggest if it would seem that using a fixed precision model could be something worth pursuing? Our context is something like this:
For individual operations, I expect the fixed precision model would work flawlessly, but I'm a little worried that with all the serialization-deserialization and repeated/chained overlay operations the inaccuracies/rounding errors could add up. |
Interesting application! I understand your concern about always working in fixed precision. Although it sounds appealing, I can't give any guarantee that the inaccuracy won't cascade. My bet would be that it should be fine, especially if you carry a few more digits of precision than needed by the application. But you'd have to try it to see. Apart from that, you could do all overlay operations using the Snapping Noding technique (see this code). This is what JTS uses as a fallback when it encounters a robustness issue ( The problem is that JTS isn't detecting the incorrect answer after regular noding. I recently committed an improved heuristic check for overlay (#812), but unfortunately that isn't handling this case. (I have in mind another heuristic that will solve #784, but it won't work for this case either). There is another potential heuristic check that will catch this case. That is using a check based on Area-Only Overlay, which is fully robust. However, this is a WIP, and it will potentially degrade performance (which may not be an issue for your use case, which I assume involves relatively small geometries?). I will continue to work on this. It could be invoked using a runtime switch, so it would be optional. |
There is also the possibility that further investigation will reveal why these cases are failing, and identify a fix. I'll look into this when I can. |
Thanks a lot for the detailed answer! |
As you mention, something that is less invasive than a fixed-precision model is to round geometries slightly before overlay operations. Only a very small rounding should be sufficient. For better performance you could do a point-wise rounding first, and then check validity, and only if invalid use |
Version used: 1.18.2 with
jts.overlay
property set tong
.Result from JTS test builder (1.18.2) is correct - i.e. the whole smaller area is included:

Failing test case:
A few things I tried:
biggerArea.intersection(smallerArea)
) has no effectThe text was updated successfully, but these errors were encountered: