Skip to content

feat: implement SameNetTraceMergeSolver to snap and fuse collinear traces (#34)#323

Open
IssacDanny wants to merge 3 commits into
tscircuit:mainfrom
IssacDanny:feat/merge-same-net-traces
Open

feat: implement SameNetTraceMergeSolver to snap and fuse collinear traces (#34)#323
IssacDanny wants to merge 3 commits into
tscircuit:mainfrom
IssacDanny:feat/merge-same-net-traces

Conversation

@IssacDanny
Copy link
Copy Markdown

/claim #34

Intuition:
Schematic traces belonging to the same net often run parallel and
close together. Snapping these to a common axis and fusing them into a single
path improves schematic readability and reduces the total number of trace
objects in the final layout.

Approach:
The SameNetTraceMergeSolver is implemented using a Hylomorphism pattern
to separate data deconstruction from merging logic:

  1. Deconstruction (Coalgebra): The solver deconstructs SolvedTracePath objects
    into individual segments. Each segment is tagged with its NetId and
    orientation (Horizontal/Vertical).
  2. Transformation (Algebra - Snapping): Segments are grouped by NetId and
    sorted by their fixed coordinate. A greedy clustering algorithm identifies
    segments within a 0.1 unit tolerance that share an overlapping range. These
    clusters are snapped to their calculated average coordinate.
  3. Reconstruction (Algebra - Fusion): A fixed-point iteration joins collinear
    segments that touch at their endpoints. This collapses fragmented segments
    back into a minimal set of continuous SolvedTracePath objects.
  4. Simplification: Redundant collinear points created during the snapping
    process are removed using simplifyPath.

Complexity:

  • Time Complexity: O(N log N), where N is the total number of segments across
    all traces. The complexity is dominated by the sorting step required for
    greedy clustering.
  • Space Complexity: O(N), as intermediate segment references are stored on the
    heap to ensure O(1) stack depth.

Verification Results

  • Verified in the playground that parallel GND/VCC traces snap and fuse into
    single paths.
  • Updated 8 visual snapshots to reflect the improved trace geometry. All 61
    tests are passing (with 4 expected skips).

@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 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 12, 2026 8:37pm

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