Skip to content

feat: add SameNetTraceMergeSolver — merge close same-net trace segments#351

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

feat: add SameNetTraceMergeSolver — merge close same-net trace segments#351
BuckyQ wants to merge 1 commit into
tscircuit:mainfrom
BuckyQ:feat/same-net-trace-merge-solver

Conversation

@BuckyQ
Copy link
Copy Markdown

@BuckyQ BuckyQ commented May 15, 2026

Fixes #29
Also addresses #34 (same-net trace lines at same X or same Y)

What this adds

A new SameNetTraceMergeSolver pipeline phase that iteratively merges trace segments belonging to the same electrical net when their endpoints are within a configurable gap (default 0.12 units).

This directly addresses both:

Implementation

Algorithm:

  1. Group all traces by net key: userNetId > globalConnNetId > dcConnNetId
  2. For each net group, O(n²) scan all endpoint pairs
  3. Select closest endpoint pair; check against maxEndpointGap threshold (default 0.12)
  4. Reverse trace paths as needed to align head-to-tail
  5. Insert a single L-shaped bridge when the join is not axis-aligned (for collinear same-Y/same-X cases, no bridge is needed — paths connect directly)
  6. Deduplicate consecutive identical points
  7. Repeat until no more pairs are within threshold (convergence)

Pipeline integration

Inserted after traceCleanupSolver and before netLabelPlacementSolver.

Tests

8 new unit tests covering: collinear touching, small gap, cross-net isolation, gap threshold, L-bridge, multi-chain, single trace, reversed endpoints.

Test results

65 pass, 4 skip, 0 fail

Snapshots updated for examples 01, 02, 13, 14, 15, 18, 19.

Adds a new pipeline phase that merges trace segments belonging to the
same electrical net when their endpoints are within maxEndpointGap units
(default 0.12) of each other.

Implementation details:
- Traces are grouped by userNetId > globalConnNetId > dcConnNetId
- O(n²) scan per net group (groups are typically small in practice)
- Closest endpoint pair is selected; paths are reversed as needed
- A single L-shaped bridge is inserted when the join is not axis-aligned
- Duplicate consecutive points are removed from the merged path
- Iterates until no more mergeable pairs remain in any group

The solver is inserted into the pipeline after TraceCleanupSolver and
before NetLabelPlacementSolver so downstream label placement sees the
merged trace geometry.

All 65 tests pass. Updated snapshots for examples where same-net traces
were merged (examples 01, 02, 13, 14, 15, 18, 19).

Closes tscircuit#29
@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 11:32pm

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

Development

Successfully merging this pull request may close these issues.

New Phase To combine same-net trace segments that are close together

1 participant