Skip to content

fix: remove extra trace lines from duplicate consecutive points#144

Open
ayushopchauhan wants to merge 1 commit intotscircuit:mainfrom
ayushopchauhan:fix/remove-extra-trace-lines-duplicate-points
Open

fix: remove extra trace lines from duplicate consecutive points#144
ayushopchauhan wants to merge 1 commit intotscircuit:mainfrom
ayushopchauhan:fix/remove-extra-trace-lines-duplicate-points

Conversation

@ayushopchauhan
Copy link

Closes #78\n\n## Root Cause\n\nUntangleTraceSubsolver._applyBestRoute() concatenates path segments when rerouting L-shaped corners:\n\nts\nconst newTracePath = [\n ...originalTrace.tracePath.slice(0, p2Index),\n ...bestRoute,\n ...originalTrace.tracePath.slice(p2Index + 1),\n]\n\n\nThe last point of slice(0, p2Index) can be identical to the first point of bestRoute, and the last point of bestRoute can be identical to the first point of slice(p2Index + 1). This produces consecutive duplicate points that render as zero-length extra trace segments.\n\n## Fix\n\n1. New utility: removeDuplicateConsecutivePoints() in simplifyPath.ts\n- Filters consecutive points that are within 1e-9 epsilon distance\n- Reusable across the codebase (same pattern already exists in TraceOverlapIssueSolver)\n\n2. Applied in _applyBestRoute() after the splice:\nts\nconst newTracePath = removeDuplicateConsecutivePoints([\n ...originalTrace.tracePath.slice(0, p2Index),\n ...bestRoute,\n ...originalTrace.tracePath.slice(p2Index + 1),\n])\n\n\n3. Applied as preprocessing in simplifyPath()\n- Deduplicates before collinear reduction, preventing edge cases where duplicates confuse the isVertical/isHorizontal checks\n\n## Files Changed\n\n| File | Change |\n|------|--------|\n| lib/solvers/TraceCleanupSolver/simplifyPath.ts | Added removeDuplicateConsecutivePoints(), applied as preprocessing in simplifyPath() |\n| lib/solvers/TraceCleanupSolver/sub-solver/UntangleTraceSubsolver.ts | Imported and applied dedup in _applyBestRoute() |\n| site/examples/example32-fix-extra-trace-lines.page.tsx | New example page with crossing traces that trigger rerouting |\n| tests/examples/example32.test.ts | Integration test for the fix |\n| tests/unit/removeDuplicateConsecutivePoints.test.ts | 8 unit tests for the dedup function + 2 for simplifyPath |\n\n## Test Results\n\n- 59 pass, 0 fail, 5 skip (full suite)\n- Zero snapshot regressions on existing tests\n- 8 new unit tests for removeDuplicateConsecutivePoints\n- 1 new integration test (example32)\n- TypeScript type-check: clean (tsc --noEmit zero errors)\n\n/claim #78"

…rcuit#78)

Root cause: UntangleTraceSubsolver._applyBestRoute() concatenates path
segments when rerouting L-shaped corners, producing consecutive duplicate
points that render as zero-length extra trace segments.

Fix:
- Add removeDuplicateConsecutivePoints() to simplifyPath.ts
- Apply dedup as preprocessing in simplifyPath() before collinear reduction
- Apply dedup in _applyBestRoute() after path splice

All 59 existing tests pass with zero snapshot regressions.
8 new unit tests + 1 integration test added.
@vercel
Copy link

vercel bot commented Mar 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
schematic-trace-solver Ready Ready Preview, Comment Mar 24, 2026 1:22pm

Request Review

@ayushopchauhan
Copy link
Author

@seveibar Ready for review. This fixes extra trace lines caused by consecutive duplicate points in _applyBestRoute(). Added removeDuplicateConsecutivePoints() utility (follows existing samePoint dedup pattern from TraceOverlapIssueSolver). 8 unit tests + integration test, zero regressions.

@ayushopchauhan
Copy link
Author

Hey @seveibar, friendly nudge - this one's also ready for review. CI green, tests passing. Happy to make changes if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix extra trace lines in post-processing step

1 participant