Intersections: treat vertical segments correctly in ToleranceEdgeY - #393
Closed
anaelorlinski wants to merge 1 commit into
Closed
anaelorlinski wants to merge 1 commit into
anaelorlinski wants to merge 1 commit into
Conversation
ToleranceEdgeY interpolates a segment's y at the left and right edges of a tolerance square. For a vertical segment the x-span is zero, so whenever floating-point rounding puts the segment's raw x one ulp outside [x - eps/2, x + eps/2) the interpolation divides by zero and returns NaN. NaN fails every below/above comparison in breakupCrossingSegments, so the segment is never broken up at the squares it passes through in its column. That happens in practice when a shape is intersected with a clip whose edge nearly coincides with one of its own edges (within BentleyOttmannEpsilon): the crossing snaps to one grid point and the endpoint to the next one up, the clip's vertical edge should be split there, is not, and the result polygon walk finds no continuation. Outside debug mode the contour is closed early and a wedge of the shape goes missing; in debug mode it panics with "next node for result polygon is nil". A vertical segment has both endpoints in the column, so its y-values at the tolerance edges are just its endpoints. Return them directly. The regression test intersects a rounded rectangle with a same-size rectangle offset by 2e-9, with the shared edge on a snap half-grid line: the result had two subpaths and 35% of the area missing. The randomized variant fails about 5% of 1000 cases before this change and none after. This does not fix the dense merged-grid case from tdewolff#382, which fails at a vertex holding three identical overlapping segments and has a different cause. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
I asked claude to find the root of a bug I had in the past and workarounded with perturbation at clipping edges.
Bug has been reproduced and here is the fix.