fix(post-processing): remove zero-length segments left by diagonal fix#437
Open
sucloudflare wants to merge 2 commits into
Open
fix(post-processing): remove zero-length segments left by diagonal fix#437sucloudflare wants to merge 2 commits into
sucloudflare wants to merge 2 commits into
Conversation
Closes tscircuit#78 Root cause: when TraceOverlapShiftSolver.findAndFixNextDiagonalSegment fixes a near-zero diagonal segment it inserts an elbowPoint via splice(). If the chosen elbow coincides with the adjacent endpoint (p1 or p2), a zero-length segment is produced. simplifyPath did not remove duplicate consecutive points, so the spurious segment survived into final output. Fix 1 – simplifyPath.ts: add isSamePoint() guard that drops zero-length (duplicate) points in both simplification passes. Fix 2 – TraceOverlapShiftSolver.ts: before splice(), detect when the elbow equals p1 or p2 and snap the existing endpoint instead of inserting a duplicate. Tests: 5 unit tests for simplifyPath covering zero-length removal, tolerance handling, and preservation of valid paths.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
When the diagonal segment is near-zero length, the computed elbow can equal p1 or p2 within tolerance. Inserting via splice() produces a zero-length segment upstream of simplifyPath. Instead, snap the existing endpoint to make the segment axis-aligned.
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.
Closes #78
Root cause
TraceOverlapShiftSolver.findAndFixNextDiagonalSegmentfixes diagonalsegments by inserting an
elbowPointviasplice(). When the diagonalis near-zero length, the chosen elbow can coincide with
p1orp2,producing a zero-length segment.
simplifyPathonly removedcollinear points — it never checked for duplicate consecutive coords —
so the spurious segment survived into the final output as an extra trace
line.
Fix
Fix 1 —
simplifyPath.ts: addedisSamePoint()guard (tolerance1e-6) that drops zero-length points in both simplification passes.Fix 2 —
TraceOverlapShiftSolver.ts: before callingsplice(),detect when the elbow equals
p1orp2and snap the existingendpoint instead of inserting a duplicate.
Tests added
5 unit tests in
tests/solvers/TraceCleanupSolver/simplifyPath-zero-length.test.ts: