Skip to content

feat: merge same-net collinear traces that are close together#143

Open
ayushopchauhan wants to merge 1 commit intotscircuit:mainfrom
ayushopchauhan:feat/merge-same-net-collinear-traces
Open

feat: merge same-net collinear traces that are close together#143
ayushopchauhan wants to merge 1 commit intotscircuit:mainfrom
ayushopchauhan:feat/merge-same-net-collinear-traces

Conversation

@ayushopchauhan
Copy link

Summary

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

When two traces belong to the same net (globalConnNetId) and have parallel segments running within 0.15 units of each other, this aligns them to the average coordinate, producing cleaner schematics.

What changed

New file: lib/solvers/TraceCleanupSolver/mergeCollinearTraces.ts

The merge algorithm:

  1. Groups traces by net - Only traces on the same globalConnNetId are candidates
  2. Extracts segments - Identifies horizontal and vertical segments from each trace path
  3. Proximity detection - Finds segments within MERGE_THRESHOLD (0.15 units) on the perpendicular axis
  4. Range overlap check - Only merges segments that actually overlap along the parallel axis (minimum 0.01 units)
  5. Coordinate averaging - Aligns clustered segments to their average fixed coordinate
  6. Endpoint preservation - Pin connection points (first/last trace points) are never moved

Modified: TraceCleanupSolver.ts

Added merging_collinear_traces as the 4th and final pipeline step:

  1. Untangling Traces
  2. Minimizing Turns
  3. Balancing L-Shapes
  4. Merging Collinear Traces (new)

New test: tests/examples/example31.test.ts

Circuit with two VCC traces connecting from opposite sides of U1 to R1 and R2, demonstrating the before/after merge behavior.

New page: site/examples/example31-merge-same-net-traces.page.tsx

Visual debugger page for inspecting the merge behavior interactively.

Before / After

Before: Two same-net traces may have parallel horizontal segments at y=0.18 and y=0.22, creating visual clutter.

After: Both segments align to y=0.20 (average), producing a cleaner schematic.

Testing

bun test tests/examples/example31.test.ts

…uit#34)

Add mergeCollinearTraces step to TraceCleanupSolver pipeline.

When two traces belong to the same net and have parallel segments
within 0.15 units of each other, this aligns them to the average
coordinate, producing cleaner schematics.

- New file: mergeCollinearTraces.ts with segment extraction,
  proximity detection, and coordinate averaging
- Integrated as final step in TraceCleanupSolver pipeline
- Preserves pin endpoints (only moves interior segments)
- New test: example31 with multi-chip same-net circuit
- New page: example31 for visual debugging
@vercel
Copy link

vercel bot commented Mar 24, 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 Mar 24, 2026 0:46am

Request Review

@ayushopchauhan
Copy link
Author

@seveibar Ready for review when you get a chance. This adds a new merging_collinear_traces phase to TraceCleanupSolver that detects and merges same-net parallel trace segments within a threshold distance. Includes snapshot tests with before/after visual proof (example31). All tests pass with zero regressions.

@ayushopchauhan
Copy link
Author

Hey @seveibar, friendly nudge - this is ready for review. CI is green, all tests passing. Let me know if you'd like any changes.

@ayushopchauhan
Copy link
Author

Note: This PR also addresses #29 ("New phase to combine same-net trace segments that are close together"). Both #29 and #34 describe the same core problem -- same-net traces with parallel segments running close together should be merged into cleaner paths. This PR implements that as a new pipeline phase (merging_collinear_traces) in TraceCleanupSolver.

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