Skip to content

fix: snap same-net close parallel traces to shared coordinate (#34)#346

Open
tungnguyentu wants to merge 2 commits into
tscircuit:mainfrom
tungnguyentu:fix/snap-same-net-parallel-traces-34
Open

fix: snap same-net close parallel traces to shared coordinate (#34)#346
tungnguyentu wants to merge 2 commits into
tscircuit:mainfrom
tungnguyentu:fix/snap-same-net-parallel-traces-34

Conversation

@tungnguyentu
Copy link
Copy Markdown

Summary

Adds a snapping_same_net_parallel_traces cleanup step inside TraceCleanupSolver that runs after untangling and before turn-minimisation.

When two (or more) traces on the same net have internal horizontal segments within 0.15 schematic units of each other and overlapping X ranges, the step snaps both to their shared midpoint Y (same logic applies for close vertical segments and X). This makes near-parallel same-net traces appear as a single line.

Changes

  • lib/solvers/TraceCleanupSolver/snapSameNetParallelTraces.ts (new): pure function — groups traces by globalConnNetId, iterates until stable finding pairs of internal parallel segments within the snap threshold, snaps both to the midpoint coordinate. Pin-anchored endpoints (first and last path segments) are never touched.
  • lib/solvers/TraceCleanupSolver/TraceCleanupSolver.ts: adds "snapping_same_net_parallel_traces" step; the untangling sub-solver now transitions to it before turn-minimisation.
  • tests/solvers/TraceCleanupSolver/snapSameNetParallelTraces.test.ts (new): 6 focused unit tests covering horizontal snap, vertical snap, different-net no-op, too-far no-op, non-overlapping no-op, and anchor-only no-op.

Verification

  • bunx tsc --noEmit — clean
  • bun test — 63 pass / 4 skip / 0 fail; all existing snapshots unchanged (new step is a no-op on current fixtures)

Fixes #34
/claim #34

…uit#34)

Adds a new `snapping_same_net_parallel_traces` step in TraceCleanupSolver
(after untangling, before turn minimisation). For each net that has multiple
traces, the step finds internal horizontal/vertical segment pairs that are
within 0.15 schematic units of each other and have overlapping ranges, then
snaps both to their midpoint coordinate so they appear as a single line.

Pin-anchored endpoints (first and last path segments) are never moved,
preserving port positions. The loop iterates until stable to handle chains
of 3+ nearly-aligned traces converging to a common coordinate.

Fixes tscircuit#34
/claim tscircuit#34
@vercel
Copy link
Copy Markdown

vercel Bot commented May 15, 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 15, 2026 4:24am

Request Review

…files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Merge same-net trace lines that are close together (make at the same Y or same X)

1 participant