Skip to content

Merge close same-net trace segments#401

Open
qkzdreamer wants to merge 1 commit into
tscircuit:mainfrom
qkzdreamer:codex/merge-close-same-net-traces
Open

Merge close same-net trace segments#401
qkzdreamer wants to merge 1 commit into
tscircuit:mainfrom
qkzdreamer:codex/merge-close-same-net-traces

Conversation

@qkzdreamer
Copy link
Copy Markdown

@qkzdreamer qkzdreamer commented May 21, 2026

Summary

  • Add a TraceCleanupSolver pass that merges close, parallel trace segments on the same net
  • Keep pin endpoints stable by only snapping internal segments
  • Add focused tests for same-net merging and different-net preservation

Fixes #34
/claim #34

Tests

  • bun test tests\solvers\TraceCleanupSolver\mergeCloseSameNetTraceSegments.test.ts
  • npm run format:check
  • npx tsc --noEmit
  • npm run build

Copilot AI review requested due to automatic review settings May 21, 2026 16:37
@vercel
Copy link
Copy Markdown

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

Request Review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new TraceCleanupSolver pipeline pass that merges (snaps) close, parallel trace segments that belong to the same net, with the intent of producing cleaner, aligned routing while avoiding modifications to pin-adjacent segments.

Changes:

  • Added mergeCloseSameNetTraceSegments pass and wired it into TraceCleanupSolver as a new pipeline step.
  • Implemented same-net, parallel-segment snapping with post-pass simplifyPath.
  • Added unit tests to verify same-net merging and different-net non-merging.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
lib/solvers/TraceCleanupSolver/TraceCleanupSolver.ts Adds a new pipeline step to run same-net segment merging after L-shape balancing.
lib/solvers/TraceCleanupSolver/mergeCloseSameNetTraceSegments.ts Implements the segment-snapping/merging algorithm and returns simplified paths.
tests/solvers/TraceCleanupSolver/mergeCloseSameNetTraceSegments.test.ts Adds focused tests for same-net merge behavior and different-net preservation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +120 to +124
const distance = Math.abs(segmentA.fixedCoord - segmentB.fixedCoord)
if (distance < EPS || distance > mergeDistance) continue

setSegmentFixedCoord(
traceB.tracePath,
Comment on lines +123 to +128
setSegmentFixedCoord(
traceB.tracePath,
segmentB.segmentIndex,
segmentB.orientation,
segmentA.fixedCoord,
)
Comment on lines +77 to +79
const isInternalSegment = (trace: SolvedTracePath, segmentIndex: number) =>
segmentIndex > 0 && segmentIndex < trace.tracePath.length - 2

Comment on lines 28 to 33
type PipelineStep =
| "minimizing_turns"
| "balancing_l_shapes"
| "merging_close_same_net_segments"
| "untangling_traces"

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.

Merge same-net trace lines that are close together (make at the same Y or same X)

2 participants