Skip to content

Add lower bound to the OverlayNG area check for symDifference - #1241

Open
adityaanikam wants to merge 1 commit into
locationtech:masterfrom
adityaanikam:fix/1239-symdifference-area-check
Open

adityaanikam wants to merge 1 commit into
locationtech:masterfrom
adityaanikam:fix/1239-symdifference-area-check

Conversation

@adityaanikam

Copy link
Copy Markdown

Fixes #1239

OverlayUtil.isResultAreaConsistent checked only an upper bound for SYMDIFFERENCE, so a result with negative area was accepted. For the input in #1239, the first snapping attempt of OverlayNGRobust builds an inverted polygon, the check accepts it, and the retry with a larger snap tolerance never happens.

A symmetric difference cannot be smaller than the difference of the input areas, so this adds that lower bound. It is relaxed by the same area tolerance that the other operations use (a fraction of the larger input area). Without the relaxation, nearly identical inputs would be rejected: their areas differ only by rounding and the correct result is empty (the case from #951 and #1005). The lower bound is the one proposed in the issue.

This only fixes the safety net. The first snapping attempt still builds an inverted polygon, which is not changed here.

Testing

OverlayNGRobustTest.testSymDifferencePolygonLineInvertedResult uses the input from the issue and checks that the result is valid and has the area of the polygon.

  • With the change, mvn test -pl modules/core runs 2308 tests with no failures (Windows, JDK 17, Maven 3.9.16, with the project's checkstyle).
  • With OverlayUtil.java reverted and the new test kept, the new test fails on result is valid. The other 7 tests in OverlayNGRobustTest pass.

OverlayUtil.isResultAreaConsistent only checked an upper bound for
SYMDIFFERENCE, so a result with negative area was accepted. For the
input in locationtech#1239 this stopped OverlayNGRobust from retrying with a larger
snap tolerance, and an inverted polygon was returned.

A symmetric difference cannot be smaller than the difference of the
input areas. Check that, relaxed by the area tolerance as it is for
DIFFERENCE, so that nearly identical inputs still give an empty result.

Fixes locationtech#1239

Signed-off-by: adityaanikam <adityanikam9502@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 20:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OverlayNGRobust symDifference returns an inverted polygon: the area check has no lower bound for SYMDIFFERENCE

2 participants