Skip to content

feat: merge same-net collinear trace segments#562

Open
singhaditya21 wants to merge 3 commits into
tscircuit:mainfrom
singhaditya21:bounty-merge-collinear-traces
Open

feat: merge same-net collinear trace segments#562
singhaditya21 wants to merge 3 commits into
tscircuit:mainfrom
singhaditya21:bounty-merge-collinear-traces

Conversation

@singhaditya21

Copy link
Copy Markdown

Summary

Fixes #34

/claim #34

  • Added mergeCollinearTraces() in lib/utils/mergeCollinearTraces.ts that groups SolvedTracePath traces by globalConnNetId, finds horizontal/vertical segments sharing the same constant coordinate, and merges overlapping or adjacent 1-D intervals into a single longer segment.
  • Integrated the function into SchematicTracePipelineSolver.getOutput() so callers automatically receive deduplicated traces without any pipeline restructuring.
  • Added 8 unit tests covering overlapping horizontal segments, adjacent (touching) segments, vertical segments, three-way merges, multi-segment traces, cross-net isolation, and an end-to-end integration scenario.

How it works

The algorithm:

  1. Groups all input traces by globalConnNetId.
  2. Extracts every axis-aligned segment from each trace.
  3. Buckets horizontal segments by Y-coordinate and vertical segments by X-coordinate.
  4. Within each bucket, sorts by the interval start and greedily merges overlapping/adjacent intervals.
  5. The "winning" trace absorbs the extended interval; the "absorbed" trace is either fully removed or trimmed to its non-overlapping portion.
  6. Repeats until no further merges are possible.

Test plan

  • bun test tests/functions/mergeCollinearTraces.test.ts — all 8 new tests pass
  • bunx tsc --noEmit — no type errors
  • bun test — all 79 pre-existing tests still pass (4 pre-existing skips; 1 unrelated pre-existing failure in an untracked file from another branch)

🤖 Generated with Claude Code

Add mergeCollinearTraces() utility that groups traces by net, finds
horizontal/vertical segments sharing the same constant coordinate, and
merges overlapping or adjacent 1-D intervals into a single longer segment.
This eliminates visual clutter from redundant same-net trace lines.

Integrate the function into SchematicTracePipelineSolver.getOutput() so
callers receive deduplicated traces without modifying the internal pipeline.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
schematic-trace-solver Ready Ready Preview, Comment Jun 26, 2026 4:42pm

Request Review

Renames mergeCollinearTraces.ts → merge-collinear-traces.ts
and the corresponding test file to satisfy the repo's
useFilenamingConvention biome rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@singhaditya21

Copy link
Copy Markdown
Author

Friendly nudge 🙂 — CI is green and this is mergeable whenever you have a moment. Happy to rebase or address any feedback if it helps. Thanks for the great project!

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.

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

1 participant