Skip to content

feat: implement collinear trace merging phase to simplify layout (#34)#115

Open
AliakbarArshadi wants to merge 8 commits intotscircuit:mainfrom
AliakbarArshadi:feat/merge-traces-34
Open

feat: implement collinear trace merging phase to simplify layout (#34)#115
AliakbarArshadi wants to merge 8 commits intotscircuit:mainfrom
AliakbarArshadi:feat/merge-traces-34

Conversation

@AliakbarArshadi
Copy link

Overview

This PR implements a new cleanup phase to merge collinear trace segments belonging to the same net (#34). It simplifies the schematic layout by reducing fragmented segments into single, continuous lines when they are aligned and close to each other.

Fixes #34

Proposed Changes

  • New Utility: Added mergeCollinearTraces.ts which implements the core logic for identifying and merging overlapping or adjacent collinear segments.
  • Solver Integration: Added "merging_collinear_traces" as a final step in the TraceCleanupSolver pipeline.
  • Threshold Management: Introduced a configurable merge threshold (default: 0.05 units) to handle minor offsets while ensuring connectivity.
  • Documentation: Added an implementation summary and a new example page (example29.page.tsx) for visual verification.

Logic Details

  1. Grouping: Segments are grouped by their netId.
  2. Collinear Check: The algorithm identifies strictly horizontal (same Y) or vertical (same X) segments.
  3. Iterative Merging: Segments that overlap or are within the distance threshold are combined into a single segment spanning the full length.

Proof of Implementation

  • Unit Tests: Created mergeCollinearTraces.test.ts with 6 test cases covering horizontal/vertical merging, multi-segment chains, and net-id isolation.
  • Test Results: All tests passed successfully using bun test.
  • Visual Verification: Verified via the new example page that fragmented "jogs" are now rendered as straight lines.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works

@vercel
Copy link

vercel bot commented Feb 5, 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 6, 2026 11:41am

Request Review

Copy link

@rushabhcodes rushabhcodes left a comment

Choose a reason for hiding this comment

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

You need to recreate an example of the problem, then show that you fixed the problem in a snapshot (this issue is probably too hard)

@AliakbarArshadi
Copy link
Author

AliakbarArshadi commented Feb 6, 2026 via email

Copy link

@rushabhcodes rushabhcodes left a comment

Choose a reason for hiding this comment

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

Please don't add readme files, there is no snapshot

Choose a reason for hiding this comment

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

remove this

Choose a reason for hiding this comment

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

remove this

DELIVERY.md Outdated

Choose a reason for hiding this comment

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

remove this

Choose a reason for hiding this comment

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

remove this

… examples

- Remove ISSUE-34-FIX-PROOF.md documentation
- Remove ISSUE-34-PROOF-SUMMARY.md documentation
- Remove DELIVERY.md documentation
- Remove generated snapshot file
- Keep test code: tests/repro-issue-34.test.ts (with overlapping case for tscircuit#29)
- Keep example: site/examples/issue-34-reproduction.page.tsx
- Keep integration test: tests/issue-34-integration.test.ts
…isting test suite

- Remove separate test files (repro-issue-34.test.ts, issue-34-integration.test.ts)
- Remove example file (site/examples/issue-34-reproduction.page.tsx)
- Add Issue tscircuit#34 test case to existing mergeCollinearTraces.test.ts:
  * Tests three fragmented collinear segments merge into one (0 to 10)
- Add Issue tscircuit#29 test case to existing mergeCollinearTraces.test.ts:
  * Tests overlapping segments on same net merge correctly (0 to 10 with overlap)
- Keep only production code changes in TraceCleanupSolver.ts
- Maintain project's native testing patterns
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)

2 participants