feat: add SameNetTraceSegmentMergingSolver pipeline phase to merge close same-net collinear segments#155
Open
CharlesWong wants to merge 2 commits intotscircuit:mainfrom
Open
Conversation
Implements new pipeline phase that combines collinear trace segments belonging to the same net when they are close together (gap ≤ 0.15 units) or overlapping. This reduces visual clutter in schematics where same-net traces run near each other. Closes tscircuit#29 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The new pipeline phase changes the visual output of schematic traces by merging close collinear same-net segments. Update snapshots accordingly.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #29
/claim #29
This PR implements a new pipeline phase — — that runs between
TraceCleanupSolverand the finalNetLabelPlacementSolverin theSchematicTracePipelineSolver. The phase reduces visual clutter in schematics by merging collinear trace segments belonging to the same net when they are close together (gap ≤ 0.15 units) or overlapping.Problem
As shown in issue #29, when two trace segments of the same net run near each other along the same axis, they appear as visually redundant parallel lines with a tiny gap. This is aesthetically distracting and informationally redundant — the two segments represent the same electrical connection and should appear as a single line.
Implementation
New file:
lib/solvers/SameNetTraceSegmentMergingSolver/SameNetTraceSegmentMergingSolver.tsA new
BaseSolversubclass with the following behavior:Groups traces by
globalConnNetId— only traces on the same net are candidates for merging.Extracts all axis-aligned segments from each trace path in the group, classifying each as
horizontalorverticalbased on which axis has the larger extent.Finds mergeable pairs across different trace paths in the same net:
ycoordinate within ±0.05 tolerance, and gap in x ≤ 0.15 units (or overlapping)xcoordinate within ±0.05 tolerance, and gap in y ≤ 0.15 units (or overlapping)Performs the merge:
Single-step synchronous solver — sets
this.solved = trueat the end of_step(), no iterative state machine needed.Pipeline integration:
lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.tssameNetTraceSegmentMergingSolver?: SameNetTraceSegmentMergingSolverpropertydefinePipelineStep(...)entry aftertraceCleanupSolverand before the finalnetLabelPlacementSolvernetLabelPlacementSolverusessameNetTraceSegmentMergingSolver?.getOutput().traceswith fallback totraceCleanupSolveroutputConstants (tunable):
Tests
Five new tests in
tests/solvers/same-net-trace-segment-merging.test.ts:All 5 tests pass:
TypeScript check clean:
Full test suite:
(9 visual snapshot tests were updated to reflect the improved merged output — all previously passing, now updated)
Visual Changes
The updated snapshots show the effect: in examples like
example29, the number of SVG line elements has been significantly reduced (from ~342 lines to much fewer) because formerly-redundant same-net segments are now merged into single longer lines.The net topology is preserved — this is purely a cosmetic/clarity improvement with no semantic change to which components are connected.
Edge Cases Handled
Math.max(0, ...), so overlapping segments (negative gap) correctly pass the ≤ 0.15 test[midpoint, midpoint]pair which downstream renderers ignoreDesign Decisions
Why collapse the second segment instead of removing points? Removing points from the middle of
tracePathcould invalidate segment indices being processed in the same pass. Collapsing to zero-length is safe, non-destructive to array structure, and produces correct visual output (zero-length SVG line = invisible).Why run after TraceCleanupSolver? TraceCleanup straightens, untangles, and L-balances traces first. Running the merger after ensures we operate on clean, already-simplified paths rather than fighting the cleanup.
Why before the final NetLabelPlacementSolver? Net labels need to know the final trace positions to avoid overlap. Merging first gives the label placer correct, final segment positions.