Skip to content

feat: add SameNetTraceMergeSolver pipeline phase#336

Open
Dannier314 wants to merge 1 commit into
tscircuit:mainfrom
Dannier314:same-net-merge
Open

feat: add SameNetTraceMergeSolver pipeline phase#336
Dannier314 wants to merge 1 commit into
tscircuit:mainfrom
Dannier314:same-net-merge

Conversation

@Dannier314
Copy link
Copy Markdown

Adds a new pipeline phase SameNetTraceMergeSolver that merges trace segments belonging to the same electrical net when they run close together, reducing visual clutter in schematic output.

Changes

  • New solver: SameNetTraceMergeSolver (groups traces by net, finds parallel overlapping segments, merges them)
  • Integrated into pipeline after TraceCleanupSolver
  • Downstream solvers (2nd NetLabelPlacementSolver, Example28Solver) prefer traces from the new solver

Algorithm

  1. Group traces by net ID (dcConnNetId / globalConnNetId / userNetId)
  2. For each group with >=2 traces, scan for parallel (H or V) segments within 0.5 units
  3. Create a junction point at the overlap centroid and merge the paths
  4. Iterate until no more mergeable pairs remain

Add a new pipeline phase that combines same-net trace segments
that are close together into shared paths, reducing visual clutter.
@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 9:04am

Request Review

@Dannier314
Copy link
Copy Markdown
Author

Implementation Notes

This implements the request from issue #29 to add a new pipeline phase that combines same-net trace segments that are close together.

How it works

  1. Groups all traces by net ID (dcConnNetId / globalConnNetId / userNetId)
  2. For each group with ≥2 traces, iterates over trace pairs
  3. Checks each segment of trace A against each segment of trace B:
    • Horizontal segments: detects parallel (both horizontal) with Y-distance ≤ 0.5 AND overlapping X-range
    • Vertical segments: detects parallel (both vertical) with X-distance ≤ 0.5 AND overlapping Y-range
  4. When parallel overlapping segments are found:
    • Creates a junction point at the centroid of the overlap
    • Reroutes both traces through the junction point using simplifyPath
    • Preserves mspPairId, pinId1, pinId2 from both original traces
  5. Exits when no more mergeable pairs are found in an iteration

Integration

  • Added to the pipeline immediately after TraceCleanupSolver (line 222-237 in pipeline def)
  • Downstream solvers (netLabelPlacementSolver 2nd pass, example28Solver) fall back from SameNetTraceMergeSolverTraceCleanupSolverTraceLabelOverlapAvoidanceSolver

Testing

I wasn't able to run bun tests locally (missing bun in my environment). The code follows the same BaseSolver pattern as the other pipeline solvers. Would appreciate it if you could run bun test to verify.

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.

1 participant