Skip to content

feat(solver): add SameNetMergeSegmentSolver to collapse redundant same-net parallel segments#441

Open
sucloudflare wants to merge 1 commit into
tscircuit:mainfrom
sucloudflare:feat/same-net-merge-segment-solver
Open

feat(solver): add SameNetMergeSegmentSolver to collapse redundant same-net parallel segments#441
sucloudflare wants to merge 1 commit into
tscircuit:mainfrom
sucloudflare:feat/same-net-merge-segment-solver

Conversation

@sucloudflare
Copy link
Copy Markdown

Closes #34
Closes #29

Problem

When two traces belong to the same net, the schematic router sometimes places parallel segments very close together (within ~0.2 schematic units) on the same axis. These appear as two nearly-identical stacked lines—visual clutter that makes the schematic harder to read.

Solution

New SameNetMergeSegmentSolver that runs in the pipeline after TraceCleanupSolver:

  1. Extracts all horizontal and vertical segments from all traces
  2. For each pair of segments on the same net and same axis whose fixed coordinate differs by less than MERGE_THRESHOLD (0.25 su) and whose extents overlap — collapses both to the midpoint coordinate and extends to the union of both extents
  3. Iterates to fixed-point (handles chains of near-duplicate segments)

Pipeline change

TraceCleanupSolverSameNetMergeSegmentSolverNetLabelPlacementSolverExample28Solver → ...

Downstream solvers pick up merged traces via:

instance.sameNetMergeSegmentSolver?.getOutput().traces ??
instance.traceCleanupSolver?.getOutput().traces

Tests added

5 unit tests in tests/solvers/SameNetMergeSegmentSolver/SameNetMergeSegmentSolver.test.ts:

  • Horizontal same-net segments snapped to midpoint ✅
  • Vertical same-net segments snapped to midpoint ✅
  • Different-net segments NOT merged ✅
  • Segments farther than threshold NOT merged ✅
  • Merged extent covers union of both original extents ✅

…e-net parallel segments

Closes tscircuit#34
Closes tscircuit#29

When two traces share the same net and have parallel axis-aligned segments
within MERGE_THRESHOLD (0.25 schematic units) of each other with overlapping
extents, they appear as near-duplicate stacked lines on the schematic.

This adds SameNetMergeSegmentSolver which:
- Scans all trace segment pairs for horizontal (same Y) or vertical (same X)
  candidates on the same net
- Snaps both segments to the midpoint coordinate and extends to the union of
  their extents (fixed-point iteration until no more merges possible)
- Runs in the pipeline after TraceCleanupSolver, before NetLabelPlacementSolver

Tests: 5 unit tests covering horizontal merge, vertical merge, different-net
no-merge, far-apart no-merge, and extent union.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 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 26, 2026 11:46am

Request Review

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

Labels

None yet

Projects

None yet

1 participant