Skip to content

fix: Merge same-net trace lines that are close together (make at the same Y or same X) (#34)#344

Open
IbrahimLaeeq wants to merge 2 commits into
tscircuit:mainfrom
IbrahimLaeeq:fix/bounty-issue-34
Open

fix: Merge same-net trace lines that are close together (make at the same Y or same X) (#34)#344
IbrahimLaeeq wants to merge 2 commits into
tscircuit:mainfrom
IbrahimLaeeq:fix/bounty-issue-34

Conversation

@IbrahimLaeeq
Copy link
Copy Markdown

Fixes #34.

/claim #34

ine only shifted different-net traces apart (via TraceOverlapShiftSolver); nothing pulled close same-net parallel segments together, so two traces on one net could leave the schematic as two near-parallel lines a small offset apart.

Changes

  • lib/solvers/TraceCleanupSolver/mergeSameNetCloseTraces.ts (new): pure function that, for each global-conn-net, finds parallel internal segments from different traces whose perpendicular distance is below a small threshold (default 0.15) and whose parallel ranges overlap, then snaps both to the midpoint coordinate. Only internal segments (pi ∈ [1, length-3]) are touched, so pin-anchored endpoints are never moved.
  • lib/solvers/TraceCleanupSolver/TraceCleanupSolver.ts: adds a "merging_same_net_traces" step between the untangling and turn-minimization phases. It runs the new merge once, then proceeds to the existing minimize/balance phases (which will simplify any redundant geometry it leaves behind).
  • tests/solvers/TraceCleanupSolver/mergeSameNetCloseTraces.test.ts (new): 6 cases covering horizontal merge, vertical merge, different-net no-op, too-far no-op, endpoint-only no-op, and non-overlapping no-op.

Verification

  • bunx tsc --noEmit clean.
  • bun test: 63 pass / 4 skip / 0 fail (was 57/4/0; the 6 new tests are the delta). All existing example snapshots are unchanged — the new step is a no-op on current fixtures and only activates when same-net parallel segments fall within the close-together threshold.

Verified against the repository's own test suite before submission.

Copilot AI review requested due to automatic review settings May 14, 2026 17:45
@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 6:12pm

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new trace-cleanup step that snaps parallel internal segments of same-net traces onto a shared coordinate when they are close enough, resolving the issue where same-net parallel lines remained slightly offset.

Changes:

  • New mergeSameNetCloseTraces pure function that aligns nearby parallel same-net internal segments to their midpoint coordinate.
  • Inserts a new "merging_same_net_traces" pipeline step into TraceCleanupSolver between untangling and turn-minimization.
  • Adds unit tests covering merge, no-merge (different nets / too-far / endpoints / non-overlapping) scenarios.

Reviewed changes

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

File Description
lib/solvers/TraceCleanupSolver/mergeSameNetCloseTraces.ts New helper that groups traces by net and snaps close parallel internal segments to a midpoint coord.
lib/solvers/TraceCleanupSolver/TraceCleanupSolver.ts Adds the new pipeline step and wires it in after untangling.
tests/solvers/TraceCleanupSolver/mergeSameNetCloseTraces.test.ts Unit tests verifying merge/no-merge behavior.

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

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