Skip to content

fix: nearly identical input should give an intersection#1479

Merged
barendgehrels merged 1 commit into
boostorg:developfrom
barendgehrels:issue-1471
Jul 2, 2026
Merged

fix: nearly identical input should give an intersection#1479
barendgehrels merged 1 commit into
boostorg:developfrom
barendgehrels:issue-1471

Conversation

@barendgehrels

Copy link
Copy Markdown
Collaborator

Fixes: #1471

✅ AI assisted

Nearly identical polygons should intersect

Two almost-identical polygons (coordinates differing by ~1 epsilon) produced an empty intersection, a doubled union, and a wrong difference.

Root cause: such input yields zero turns, so select_rings decides containment from a single representative point — but that point is a ring vertex, which lands exactly on the other ring's boundary (range_in_geometry == 0), and an on-boundary point was treated as "not within".

Fix: in select_rings, when the overlay produced no turns, treat an entirely-on-boundary ring as "within" for the binary set operations (union/intersection/difference).

Related to commit 2780c9d (which changed this code, reversal would have fixed this as well - but would have given regression in other cases).

This PR also enhances the test (that initially passed for #1471): if two geometries intersect but don't touch, their intersection must be non-empty — independent of the overlay path, so it catches this class of bug that area-balance checks cannot.

@vissarion vissarion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGMT thanks!

@barendgehrels

Copy link
Copy Markdown
Collaborator Author

LGMT thanks!

@vissarion thanks for the quick review. It's a bugfix, 1.92 is still open, I think we can make that. Then I'll also include it in the release notes.
@tinko92 also OK with this?

@vissarion

Copy link
Copy Markdown
Member

@vissarion thanks for the quick review. It's a bugfix, 1.92 is still open, I think we can make that.

I agree, if Tinko is OK, I will merge it to main.

Then I'll also include it in the release notes. @tinko92 also OK with this?

Thanks, I will then update the boost release notes.

@tinko92 tinko92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry that I couldn't review this yesterday, there are some lines that were non-obvious to me (I left comments). I am OK with merging this before the release since it fixes cases and does not break anything, so my comments are not blockers.

Most comments are about passing something (constant false or a computed value) for overlay_has_turns being ambiguous. Maybe some argument name that indicates "decide within for the no turns special case" with a default value would be more clear here. But again, I am OK with merging this since it is well-limited to a special case, does not seem to break anything and fixes a real problem.

Comment thread include/boost/geometry/algorithms/detail/overlay/select_rings.hpp Outdated
Comment thread test/algorithms/set_operations/set_ops_areal_areal.cpp Outdated
Comment thread test/algorithms/overlay/select_rings.cpp Outdated
Comment thread include/boost/geometry/extensions/algorithms/dissolve.hpp Outdated
@barendgehrels

barendgehrels commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

overlay_has_turns

Maybe include_on_border is clearer (and then it should be reverted). I could give it a default value false (avoiding the change in dissolve - and then it will have turns.empty()).

@barendgehrels

Copy link
Copy Markdown
Collaborator Author

I'll update the PR later today. Thanks for the approvals!

@barendgehrels

Copy link
Copy Markdown
Collaborator Author

overlay_has_turns

Maybe include_on_border is clearer (and then it should be reverted). I could give it a default value false (avoiding the change in dissolve - and then it will have turns.empty()).

✅ (include_on_boundary seems the best OGC fitting term)

@tinko92

tinko92 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the quick changes and the fix! In my opinion this can be merged.

@barendgehrels barendgehrels merged commit a7875f6 into boostorg:develop Jul 2, 2026
17 checks passed
@barendgehrels

Copy link
Copy Markdown
Collaborator Author

Thanks, I will then update the boost release notes.

Merged! ✔️

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.

Two almost idential rectangles has no interesection

3 participants