Skip to content

fix: remove duplicate consecutive points in simplifyPath#341

Open
tungnguyentu wants to merge 1 commit into
tscircuit:mainfrom
tungnguyentu:fix/trace-duplicate-points-78
Open

fix: remove duplicate consecutive points in simplifyPath#341
tungnguyentu wants to merge 1 commit into
tscircuit:mainfrom
tungnguyentu:fix/trace-duplicate-points-78

Conversation

@tungnguyentu
Copy link
Copy Markdown

Fixes #78

/claim #78

Root Cause

The simplifyPath function in TraceCleanupSolver did not handle duplicate consecutive points (zero-length segments). When two identical points appear back-to-back in a trace path, isVertical/isHorizontal return inconsistent results, causing the collinear-collapse passes to miss those segments. The result is extra visible line segments in the schematic output.

Fix

Added a dedupConsecutive helper that strips identical adjacent points before each collinear-collapse pass. Two collapse passes run in sequence to handle cases where the first pass exposes a new collinear run, followed by a final dedup to ensure a clean result.

input → dedupConsecutive → collapseCollinear
      → dedupConsecutive → collapseCollinear  
      → dedupConsecutive → output

Tests

Five focused tests in tests/solvers/TraceCleanupSolver/simplify-path.test.ts:

  1. Duplicate consecutive points are removed
  2. Collinear points on a straight path collapse to two endpoints
  3. Right-angle turns are preserved (not collapsed)
  4. Duplicates at start/end don't crash
  5. Idempotency — simplifying twice yields the same result

All 62 tests pass (4 skipped, 0 fail). No snapshot changes — the fix only affects degenerate paths not covered by existing examples.

Zero-length trace segments (two identical consecutive points) caused
`isVertical`/`isHorizontal` to behave inconsistently and left extra
visible line segments in the schematic output.

Fix: deduplicate consecutive equal points before each collinear-collapse
pass. Running two collapse passes after dedup handles back-to-back
collinear sequences that the first pass may expose.

Adds five focused tests: duplicate removal, collinear collapse,
right-angle preservation, duplicates at endpoints, and idempotency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 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 May 14, 2026 4:48pm

Request Review

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