Skip to content

feat: merge nearby same-net trace segments (#34)#553

Open
XananasX7 wants to merge 2 commits into
tscircuit:mainfrom
XananasX7:feat/merge-same-net-trace-lines
Open

feat: merge nearby same-net trace segments (#34)#553
XananasX7 wants to merge 2 commits into
tscircuit:mainfrom
XananasX7:feat/merge-same-net-trace-lines

Conversation

@XananasX7

Copy link
Copy Markdown

/claim #34

Summary

Implements issue #34: Merge same-net trace lines that are close together (at the same Y or same X).

Adds a new merging_close_same_net_segments cleanup phase to the TraceCleanupSolver pipeline that snaps nearby parallel same-net trace segments onto a shared coordinate, eliminating the visually confusing closely-spaced parallel lines shown in the issue screenshot.

Changes

New file: lib/solvers/TraceCleanupSolver/mergeNearbySameNetSegments.ts

  • Scans all interior trace segments (excluding pin-attachment endpoints to preserve routing geometry)
  • Groups segments that share: the same net ID + same orientation (H or V) + overlapping free-axis range + within 0.18 units along the fixed axis
  • Uses BFS clustering to handle groups of 3+ collinear close segments
  • Snaps the entire group to their average fixed-axis coordinate
  • Calls simplifyPath after snapping to clean up any resulting collinear points

Modified: lib/solvers/TraceCleanupSolver/TraceCleanupSolver.ts

  • Added merging_close_same_net_segments as the final pipeline step after balancing_l_shapes
  • The step runs once (not per-trace) via mergeNearbySameNetSegments()

New tests: tests/solvers/TraceCleanupSolver/mergeNearbySameNetSegments.test.ts

7 unit tests covering:

  • Horizontal merging
  • Vertical merging
  • 3-trace group merging
  • Different-net isolation (must NOT merge)
  • Distance threshold (segments > 0.18 apart must NOT merge)
  • Non-overlapping ranges (must NOT merge)
  • Endpoint/pin coordinate preservation

Test Results

bun test
 77 pass
 4 skip (pre-existing)
 0 fail

bunx tsc --noEmit — clean, no errors.

Add a merging_close_same_net_segments phase to TraceCleanupSolver that
snaps close parallel same-net trace segments onto a shared coordinate.

- New mergeNearbySameNetSegments() function in TraceCleanupSolver/
- Groups interior segments by net + orientation + overlapping range
- Snaps segment groups to their average fixed-axis coordinate
- Preserves endpoint/pin segments (first and last segment of each trace)
- Runs as the final step in the TraceCleanupSolver pipeline
- 7 new unit tests covering all edge cases
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
schematic-trace-solver Ready Ready Preview, Comment Jun 18, 2026 6:28pm

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.

1 participant