-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OverlayNG area check heuristic causing issues when snapping noder is used #951
Comments
Thanks for the detailed bug report. Sorry for the delay in looking into this. It looks like a design flaw in the heuristic area check. In this case the result is an empty geometry with zero area. The input geometries are essentially identical, but have rotated vertex sequences. Due to numeric precision issues (the eternal bugbear) the areas evaluate to be slightly different. This causes the area heuristic check to fail, incorrectly.
The heuristic needs to be modified to be less stringent when evaluating very small differences in area. I'm not sure what a suitable fix is, but will think about it. Suggestions welcome. |
In case of
If I understand correctly, the intention is to check that:
I tried to think of possible solutions, but did not come up with any definitive answer quickly (but I can think more of it if needed). One line of thinking was to add special handling for 0 or almost-zero values. But I did not come up with a way how to come up with "what is almost zero" without hardcoding a constant, e.g. Another idea was to base it on relative difference between sizes (one such example function is provided at the bottom of this page: https://c-faq.com/fp/fpequal.html), but then I think it does not work for non-near-zero cases as if there is no overlap between two similarly-sized polygons, the relative difference between area of the result (area A) and difference between areas (close to 0) can be very large. |
After upgrading JTS from 1.18.2 to 1.19.0 ran into a number of tests that use difference operation failing with
TopologyException: Result area inconsistent with overlay operation
.I tracked it down to
OverlayUtil#isResultAreaConsistent
(which was added in #812):In our case we are performing a difference operation on two almost-exactly-the-same geometries and expect an empty result.
Note: we are using snapping noder like in OverlayNGSnappingFunctions code.
Test case 1
This case fails with
TopologyException
:In this case
OverlayUtil#isResultAreaConsistent
is reached once, and the expression inisGreater
check works out to be:v1 >= v2 * (1 - tol);
0 >= 8.8819E-16 * (1 - 0.1)
==>false
Test case 2
This case passes with the same data:
In this case it seems
OverlayNGRobust
is used instead, which results in multiple calls toOverlayUtil#isResultAreaConsistent
(with slightly different values) and eventually it succeeds in passing the heuristic check.Question
To me this feels like a bug in the heuristic check, but maybe our utility function for the difference operation is implemented in a suboptimal way?
If it's indeed a bug, and the fix is relatively simple (for someone who does not know JTS internals well), we'd be happy to contribute a PR with the fix.
The text was updated successfully, but these errors were encountered: