feat: add OverlapResolutionSolver to fix residual chip overlaps in final layout#114
feat: add OverlapResolutionSolver to fix residual chip overlaps in final layout#114ElecTream wants to merge 3 commits into
Conversation
…nal layout Closes the gap between the assertion already present in RP2040Circuit.test.ts (`expect(overlaps.length).toBe(0)`) and the actual output of the pipeline, which today leaves 4 overlapping chip pairs in the RP2040 layout (U3/C14, C10/C7, C10/C12, C19/C15). ## What this adds A new pipeline phase, `OverlapResolutionSolver`, that runs after `PartitionPackingSolver` and iteratively pushes overlapping chip pairs apart along their minimum-penetration axis. Movement is weighted by chip area so a small passive moves more than a large anchor chip (RP2040, MCUs, etc), preserving the overall shape produced by the earlier phases. ## Behavior - Inflates each chip's AABB by `chipGap/2` per side so the configured `inputProblem.chipGap` is enforced (not just zero-overlap). - Processes the worst overlap first each pass (largest area), then iterates until no overlaps remain or `maxRelaxationIterations` (200) is reached. - Deep-clones the input layout — never mutates the caller's placements. - `getOutputLayout()` and `visualize()` now prefer the de-overlapped result, falling back to `partitionPackingSolver.finalLayout` for code that steps the pipeline manually and skips this phase. ## Verified - RP2040 circuit: 4 final overlaps → 0 (resolved in 17 relaxation iters) - Existing tests: all green - New unit tests cover: pair separation, no-op on clean layouts, input immutability, area-weighted movement, end-to-end regression for RP2040 /attempt tscircuit#12
|
@ElecTream is attempting to deploy a commit to the tscircuit Team on Vercel. A member of the Team first needs to authorize it. |
…m test fixtures Resolves type-check failure on CI.
Before / After on RP2040 circuitQuick numeric demonstration of what this PR fixes, run against
The biggest single overlap was C10↔C12 at 0.36 area — roughly half a capacitor's footprint of co-location. That's the kind of layout artifact that's visible in the rendered schematic and indistinguishable from "the placer got confused." On competing PRsI noticed several other open PRs targeting #12 with broader scope (full layout rewrites, new packing phases, voltage-bias logic). I deliberately kept this one narrow — only overlap resolution as a post-process, without touching the upstream packing decisions. That means:
Happy to fold in feedback or split this differently if there's a different scope you'd prefer. |
Reviewers can now see at a glance which chips moved (green, with a red ghost of the original position and a connecting line) versus chips that stayed put (blue). Makes the impact of the phase obvious in the cosmos debugger.
/claim #12
Closes #12
Why
The RP2040 circuit test already asserts that the final layout has zero chip overlaps:
But the current pipeline output leaves 4 overlapping pairs on that circuit —
U3/C14,C10/C7,C10/C12,C19/C15. ThecheckForOverlapshelper exists, the warning fires fromgetOutputLayout(), but there's no phase that actually resolves the overlaps once detected.This PR adds that phase.
What
OverlapResolutionSolver— a new final pipeline phase that runs afterPartitionPackingSolver. It iteratively pushes overlapping chip pairs apart along their minimum-penetration axis until no overlaps remain (ormaxRelaxationIterationsis hit, default 200).Key behaviors:
inputProblem.chipGap, not just zero-overlap. Bounding boxes are inflated bychipGap/2per side before detection so the configured gap is actually preserved.w₁ = area₂ / (area₁ + area₂)so the bigger chip — usually the connection hub the rest of the partition was packed around — stays close to where the earlier phases placed it.finalLayout.LayoutPipelineSolver.getOutputLayout()andLayoutPipelineSolver.visualize()now preferoverlapResolutionSolver.finalLayout, falling back topartitionPackingSolver.finalLayoutfor code that steps the pipeline manually and skips this phase.Results
RP2040Circuit complete pipelineOverlapResolutionSolver01The RP2040 case resolves in 17 relaxation iterations.
Test plan
bun test tests/OverlapResolutionSolver/— 5/5 passbun test tests/LayoutPipelineSolver/RP2040Circuit.test.ts— 2/2 pass; overlap assertion now satisfiedbun test— no new failures (pre-existingcircuit-to-svgexport error is unrelated to this change)What this PR does NOT change
checkForOverlapshelper onLayoutPipelineSolver(kept for backwards compat, the new solver has its own gap-aware detector)Notes for the reviewer
Warning: chip overlaps detectedyou'll see during the test run originates fromtscircuit's bundled (older) copy of matchpack insidenode_modules, not from this branch's pipeline. The actualgetOutputLayout()output of this branch has zero overlaps.PackInnerPartitionsSolver/PartitionPackingSolver.