feat: merge close same-net trace segments#337
Open
ArtemisMoysen wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds a new pipeline phase to merge close, overlapping same-net orthogonal trace segments onto a shared axis (after trace cleanup), with accompanying tests and a Cosmos debug page to visualize behavior.
Changes:
- Introduces
SameNetTraceMergeSolver+mergeSameNetTraceSegmentsto align nearby same-net parallel segments. - Inserts the new solver into
SchematicTracePipelineSolverafterTraceCleanupSolverand feeds merged traces into downstream phases. - Adds Bun tests and a Cosmos debugger page for the new solver.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/solvers/SameNetTraceMergeSolver/SameNetTraceMergeSolver.ts |
Implements segment detection, component grouping, and coordinate alignment + visualization. |
lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver.ts |
Wires the new merge solver into the pipeline and uses its traces downstream. |
tests/functions/merge-same-net-trace-segments.test.ts |
Adds unit tests for merge behavior and solver output. |
site/SameNetTraceMergeSolver/SameNetTraceMergeSolver01.page.tsx |
Adds a Cosmos debug page to inspect merging results interactively. |
Comments suppressed due to low confidence (1)
tests/functions/merge-same-net-trace-segments.test.ts:72
- Same as above:
toBe(1.3)on a computed float can be flaky. UsetoBeCloseTofor coordinate assertions.
const result = mergeSameNetTraceSegments([traceA, traceB])
expect(result.mergeCount).toBe(0)
expect(getMiddleSegmentY(result.traces[0]!)).toBe(1)
expect(getMiddleSegmentY(result.traces[1]!)).toBe(1.3)
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+228
to
+240
| for (const component of components) { | ||
| const targetCoord = | ||
| component.reduce((sum, segment) => sum + segment.constantCoord, 0) / | ||
| component.length | ||
|
|
||
| for (const segment of component) { | ||
| moveSegmentToCoord( | ||
| outputTraces[segment.traceIndex]!.tracePath, | ||
| segment.segmentIndex, | ||
| segment.axis, | ||
| targetCoord, | ||
| ) | ||
| } |
Comment on lines
+151
to
+186
| const getMergeComponents = ( | ||
| segments: TraceSegment[], | ||
| mergeDistance: number, | ||
| minOverlap: number, | ||
| ) => { | ||
| const visited = new Set<number>() | ||
| const components: TraceSegment[][] = [] | ||
|
|
||
| for (let i = 0; i < segments.length; i++) { | ||
| if (visited.has(i)) continue | ||
|
|
||
| const queue = [i] | ||
| const component: TraceSegment[] = [] | ||
| visited.add(i) | ||
|
|
||
| while (queue.length > 0) { | ||
| const currentIndex = queue.shift()! | ||
| const current = segments[currentIndex]! | ||
| component.push(current) | ||
|
|
||
| for (let j = 0; j < segments.length; j++) { | ||
| if (visited.has(j)) continue | ||
|
|
||
| if ( | ||
| shouldMergeSegments( | ||
| current, | ||
| segments[j]!, | ||
| segments, | ||
| mergeDistance, | ||
| minOverlap, | ||
| ) | ||
| ) { | ||
| visited.add(j) | ||
| queue.push(j) | ||
| } | ||
| } |
Comment on lines
+56
to
+61
| const result = mergeSameNetTraceSegments([traceA, traceB]) | ||
|
|
||
| expect(result.mergeCount).toBe(0) | ||
| expect(getMiddleSegmentY(result.traces[0]!)).toBe(1) | ||
| expect(getMiddleSegmentY(result.traces[1]!)).toBe(1.08) | ||
| }) |
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.
Issue
Closes #29
/claim #29
Summary
SameNetTraceMergeSolverafter trace cleanup to merge close overlapping same-net orthogonal trace segments onto a shared axis.SameNetTraceMergeSolver01.Verification
npx bun testnpx biome format .npx -y -p typescript@5 tsc --noEmitgit diff --check