Introduce self‑intersection normalization for polygons#22
Open
JimBobSquarePants wants to merge 58 commits intomainfrom
Open
Introduce self‑intersection normalization for polygons#22JimBobSquarePants wants to merge 58 commits intomainfrom
JimBobSquarePants wants to merge 58 commits intomainfrom
Conversation
|
|
||
| // Exteriors are the even-depth contours. | ||
| List<int> externals = []; | ||
| for (int i = 0; i < count; i++) |
Contributor
There was a problem hiding this comment.
You could join this with the for loop of line 317
Member
Author
There was a problem hiding this comment.
Yeah we can merge this!
|
|
||
| if (hasHoleInfo) | ||
| { | ||
| for (int i = 0; i < polygon.Count; i++) |
Contributor
There was a problem hiding this comment.
This could probably also be joined with the for loop on l 459 to 467.
Member
Author
There was a problem hiding this comment.
I don’t think merging those loops is worthwhile or clean. The first loop exists to decide which containment mode to use (hole‑aware vs XOR). Until you’ve scanned all contours, you can’t safely choose the hole‑aware path. If you merge, you either:
- Do partial XOR work and then throw it away if you later discover hole metadata, or
- Add extra bookkeeping (cache externals + a restart), which doesn’t really save work.
Contributor
There was a problem hiding this comment.
Yeah.
But does the first loop really do all iterations? There's a break statement in there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
This PR introduces PolygonClipper.RemoveSelfIntersections, a new opt‑in normalization step that converts self‑intersecting contours into a valid polygon representation using a positive fill rule. It is intentionally separate from the core boolean pipeline so existing workflows remain unchanged, but consumers can call it explicitly when their input geometry is not guaranteed to be simple.
The new method is especially useful for real‑world inputs such as stroked text outlines, compound paths, or imported artwork where contours may cross or touch themselves. By normalizing these shapes first, the main Martinez boolean operations can be applied reliably to inputs that would otherwise be invalid or produce undefined results.
CC @stefannikolei