Skip to content

Add same-net trace combining phase#290

Open
grantf04 wants to merge 4 commits into
tscircuit:mainfrom
grantf04:grantf04/same-net-trace-combining
Open

Add same-net trace combining phase#290
grantf04 wants to merge 4 commits into
tscircuit:mainfrom
grantf04:grantf04/same-net-trace-combining

Conversation

@grantf04
Copy link
Copy Markdown

@grantf04 grantf04 commented May 9, 2026

Summary

  • add SameNetTraceCombiningSolver as a dedicated post-cleanup pipeline phase
  • group traces by globalConnNetId and snap close overlapping parallel same-net segments onto a shared run
  • keep terminal trace segments fixed so pin endpoints do not detach
  • recompute segment refs after each snap and iterate until stable so close runs collapse consistently
  • preserve different-net geometry and add focused regression coverage for all of the above

/claim #29
/claim #34

Tests

  • npx --yes bun test tests/solvers/SameNetTraceCombiningSolver/SameNetTraceCombiningSolver.test.ts
  • npx --yes bun run format:check
  • npx --yes tsc --noEmit
  • npx --yes bun run build
  • npx --yes bun test

Review feedback addressed

  • terminal/source endpoints are no longer moved during snapping
  • segment references are rebuilt after every successful snap by iterating one combine at a time until stable

@vercel
Copy link
Copy Markdown

vercel Bot commented May 9, 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 May 9, 2026 7:44am

Request Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8dac37f136

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +159 to +164
if (segment.axis === "horizontal") {
firstPoint.y = coordinate
secondPoint.y = coordinate
} else {
firstPoint.x = coordinate
secondPoint.x = coordinate
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep trace endpoints attached when snapping

When the source segment is the first or last segment of a trace, these assignments move the trace endpoint itself. In the pipeline those endpoints represent the pins for the SolvedTracePath, so a simple two-point or terminal run that gets combined with a nearby same-net run will no longer start/end at its component pin coordinates, leaving the rendered/solved connection detached. Terminal segments need to be skipped or rewritten with an added jog so the pin endpoint remains fixed.

Useful? React with 👍 / 👎.

Comment on lines +71 to +78
const segments = groupTraces.flatMap((trace) =>
this.getSegmentRefs(
this.outputTraces[traceIndexById.get(trace.mspPairId)!]!,
).map((segment) => ({
...segment,
traceIndex: traceIndexById.get(trace.mspPairId)!,
})),
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recompute segment refs after each snap

segments captures each run's constantCoord before any modifications, but later comparisons still use those stale coordinates after snapSegmentToCoordinate mutates the trace. With three overlapping same-net runs at y=0, y=0.1, and y=0.2 and mergeDistance=0.15, the y=0.1 run first snaps to y=0, then the y=0.2 run is compared against the stale y=0.1 ref and snaps to y=0.1, leaving two separate runs that should have collapsed onto the shared run. Updating/rebuilding refs or iterating until stable avoids this order-dependent partial combine.

Useful? React with 👍 / 👎.

@grantf04
Copy link
Copy Markdown
Author

grantf04 commented May 9, 2026

Addressed the automated review feedback in b1442d9: terminal trace segments are no longer moved, and segment refs are rebuilt by iterating one combine at a time until stable. Added regressions for endpoint preservation and multi-run collapse. Full bun test, format, type-check, build, Vercel, and GitHub Actions are green.

@grantf04
Copy link
Copy Markdown
Author

grantf04 commented May 9, 2026

/claim #34

This PR also addresses issue #34: it merges close same-net horizontal/vertical trace lines onto the same Y/X run while preserving terminal pin endpoints and iterating to collapse multi-run clusters consistently.

@grantf04
Copy link
Copy Markdown
Author

grantf04 commented May 9, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1442d9c0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

],
),
definePipelineStep(
"netLabelPlacementSolver",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use a distinct name for the second label placement phase

Adding another pipeline entry named netLabelPlacementSolver creates two sibling stages with the same identifier; the stage table keys rows by stage.solverName and solveUntilPhase(stage.solverName) stops at the first match, so the post-combine label-placement phase cannot be targeted/downloaded separately and its timing/instance data overwrites the earlier phase. This also violates React's requirement that list keys be unique among siblings (https://react.dev/learn/rendering-lists). Give this new phase its own solver property/name or otherwise disambiguate the two runs.

Useful? React with 👍 / 👎.

@grantf04
Copy link
Copy Markdown
Author

grantf04 commented May 9, 2026

Addressed the latest Codex review feedback in ff339e1: the second net-label placement pass now uses a distinct postCombineNetLabelPlacementSolver stage/property, so pipeline phase keys and targeted downloads are unique. Updated the affected SVG snapshots because the pipeline visualization now shows the pre-combine and post-combine label placement stages separately.

Verification:

  • npx --yes bun test tests/solvers/SameNetTraceCombiningSolver/SameNetTraceCombiningSolver.test.ts
  • npx --yes bun test
  • npx --yes bun run format:check
  • npx --yes tsc --noEmit
  • npx --yes bun run build

@grantf04
Copy link
Copy Markdown
Author

grantf04 commented May 9, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff339e1f97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +176 to +181
if (segment.axis === "horizontal") {
firstPoint.y = coordinate
secondPoint.y = coordinate
} else {
firstPoint.x = coordinate
secondPoint.x = coordinate
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck collisions before snapping segments

When this phase runs after TraceCleanupSolver in the pipeline, snapSegmentToCoordinate rewrites the segment endpoints unconditionally. In cases where the snapped segment has adjacent legs, moving a horizontal/vertical run toward a nearby same-net run can extend those legs through the gap that cleanup had routed around; if a different-net trace, chip, or label sits there, the final output can reintroduce a collision because no obstacle/collision check is performed before committing the new coordinates.

Useful? React with 👍 / 👎.

@grantf04
Copy link
Copy Markdown
Author

grantf04 commented May 9, 2026

Addressed the latest Codex review feedback in 5c65323: same-net segment snaps are now transactional and only commit if they do not introduce new chip, net-label, or different-net trace collisions. The pipeline now passes input-problem obstacles and current net-label placements into the combiner, and the solver has regressions for both different-net trace blockers and net-label obstacles.\n\nVerification:\n- npx --yes bun test tests/solvers/SameNetTraceCombiningSolver/SameNetTraceCombiningSolver.test.ts\n- npx --yes bun test\n- npx --yes bun run format:check\n- npx --yes tsc --noEmit\n- npx --yes bun run build

@grantf04
Copy link
Copy Markdown
Author

grantf04 commented May 9, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@grantf04
Copy link
Copy Markdown
Author

grantf04 commented May 9, 2026

This is ready for maintainer review from my side. All repo checks and the Vercel preview are green, and the latest Codex review found no major issues after the collision-safety follow-up.

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.

1 participant