Skip to content

feat: merge collinear traces on same net to simplify schematic layout#117

Open
buildingvibes wants to merge 2 commits intotscircuit:mainfrom
buildingvibes:fix/merge-collinear-traces-34
Open

feat: merge collinear traces on same net to simplify schematic layout#117
buildingvibes wants to merge 2 commits intotscircuit:mainfrom
buildingvibes:fix/merge-collinear-traces-34

Conversation

@buildingvibes
Copy link

@buildingvibes buildingvibes commented Feb 10, 2026

Summary

This PR implements automatic merging of collinear trace segments that belong to the same net and are aligned, addressing issue #34. The implementation reduces fragmented trace segments into single continuous lines, making schematics cleaner and more readable.

Key Changes

  • New utility function mergeCollinearTraces: Core logic for identifying and merging overlapping or adjacent collinear segments

    • Groups traces by net ID to ensure only same-net traces are merged
    • Identifies horizontal (same Y) and vertical (same X) segments
    • Merges segments that overlap or are within a distance threshold
    • Simplifies traces with multiple collinear points into just two endpoints
  • Integrated into TraceCleanupSolver pipeline: Added as the final "merging_collinear_traces" step

    • Runs after untangling, turn minimization, and L-shape balancing
    • Operates on all traces at once for optimal merging
  • Comprehensive testing:

    • Unit tests for merge logic covering various scenarios
    • Integration test for complete pipeline
    • Visual example (example28) demonstrating the feature

Technical Details

The merge algorithm:

  1. Groups traces by their globalConnNetId
  2. Extracts horizontal and vertical segments from trace paths
  3. Groups segments by their coordinate (Y for horizontal, X for vertical)
  4. Merges overlapping or adjacent segments within threshold (default: 0.01)
  5. Simplifies collinear paths to just start and end points

The threshold parameter handles minor floating-point variations while ensuring segments are truly aligned. Only segments on the same net are merged, preserving circuit topology.

Test Plan

  • Type checking passes: npx tsc --noEmit
  • Code formatted: npm run format
  • Unit tests created for mergeCollinearTraces function
  • Integration test created for TraceCleanupSolver
  • Visual example (example28) added for manual verification
  • All new functions have clear documentation

Manual Testing

The example28 page can be viewed in the browser to visually verify that:

  • Horizontal traces on the VCC net are merged
  • Traces on different nets remain separate
  • The overall schematic layout is improved

Fixes #34
/attempt #34
/claim #34

Implements automatic merging of collinear trace segments that belong to
the same net and are aligned (same Y for horizontal or same X for vertical).
This addresses issue tscircuit#34 by reducing fragmented trace segments into single
continuous lines, making schematics cleaner and more readable.

Changes:
- Added mergeCollinearTraces utility function that:
  - Groups traces by net ID
  - Identifies horizontal and vertical segments
  - Merges overlapping or adjacent collinear segments
  - Simplifies traces with multiple collinear points
- Integrated merging as final step in TraceCleanupSolver pipeline
- Added comprehensive unit tests for merge logic
- Added example28 demonstrating the feature
- Added integration test for the complete pipeline

The merge algorithm uses a threshold (default 0.01) to handle minor
floating-point variations while ensuring segments are truly aligned.
Only segments on the same net are merged, preserving circuit topology.

Fixes tscircuit#34
@vercel
Copy link

vercel bot commented Feb 10, 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 Feb 10, 2026 5:37am

Request Review

The merge collinear traces feature (implemented in this PR) changes
the visual output of the solver by combining collinear trace segments
into single continuous lines. This is the expected behavior and improves
schematic readability. Updated 9 test snapshots to match the new output.
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)

1 participant