Repository navigation
Handle interiorcuts edge cases - #350
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The cut from a hole's lowest vertex attaches to the enclosing edge at a lattice point, which kinks that edge by up to a unit. Rounded inward, the kink can cross a hole vertex just inside the edge; rounded outward, it can cross the contour's next edge where that folds back at an acute vertex. Use the nearer lattice point unless its kink crosses a segment and the other's does not. A hole whose lowest vertex Clipper rounded to just outside its enclosing contour had nothing below it and was silently dropped. Pinch it onto the nearest edge instead, and warn if no edge is within a unit. Drop consecutive repeated points, left by a cut landing on a vertex or a hole touching its enclosing contour. The PolyText GDS fingerprints shrink accordingly: same polygons, 34 fewer points in the characters demo.
gpeairs
force-pushed
the
gp/interiorcuts-edge-cases
branch
from
October 29, 2026 12:10
e69cd3a to
b3c3c4d
Compare
gpeairs
marked this pull request as ready for review
October 29, 2026 12:10
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.
Close #317.
A hole whose lowest vertex Clipper rounded to just outside its enclosing contour had nothing below it and was silently dropped. Fix in simple cases, throw an error when the problematic case is detected. In principle this can still miss problems when the near-touch is another hole or a non-neighboring edge but is generally conservative (may warn with nothing technically wrong in rare cases). Also even the detectable case is very rare, not encountered in fuzzing at um scale on fm grid. No performance consequences. Need to clean up comments at least.
Also drop consecutive repeated points, left by a cut landing on a vertex or a hole touching its enclosing contour.
Encountered a different bug fuzzing this, where floating point issues could cause a ray not to see a vertex it was exactly above, and fixed it here (more exact Int128 computation for intersections).
Original version of this PR: Pinch it onto the nearest edge instead, and warn if no edge is within a unit.
Also drop consecutive repeated points, left by a cut landing on a vertex or a hole touching its enclosing contour.
This has no performance hit for axis-aligned geometry (
far == near) and a measurable one otherwise.kink_crossesqueries the interval tree over the full x-extent of the enclosing edge, which for a long sloped edge with many attached holes looked potentially quadratic. In practice each attachment splits the edge intosub-nodes, so later queries cover only the sub-segment's x-range. Measured on a rotated (10°) 1000×1000 square with a grid of square holes (every cut has a non-integer hit, so every hole pays the check):
This is could be worth adding more complexity to improve, but the fix itself is already unpleasantly complex. Trying to put a point on a diagonal line is dangerous when working with integer grids, whether for Clipper or GDS. Clipper2 has at least one hole-dropping bug itself, for a union that closes off a concavity on a diagonal that gets unlucky, which is pretty hard to hit accidentally in a realistic design. I don't know if we want to be in the business of patching together our own integer-grid geometry library. Maybe we just detect when something goes wrong and throw an error that tells the user to split T-junctions first (which the conformal rendering pipeline requires anyway), or something. These cases feel too rare in real devices to be worth the performance and complexity cost of a full fix.