fix(layout): inherit pack bounds from ancestor when group lacks width/height#2274
Open
gsdali wants to merge 1 commit intotscircuit:mainfrom
Open
fix(layout): inherit pack bounds from ancestor when group lacks width/height#2274gsdali wants to merge 1 commit intotscircuit:mainfrom
gsdali wants to merge 1 commit intotscircuit:mainfrom
Conversation
…/height Closes tscircuit#2272. When a `<group>` runs the auto-packer on its children but doesn't itself specify `width` and `height`, the packer was invoked with `bounds = undefined` — so candidate positions outside the actual board were never rejected. Components packed in an unbounded column going far past the board edges. On a 50x14 mm board with a `region_mcu` group at (-18, 0) holding ~10 small SMTs and one 12x12 mm chip, the small siblings ended up at Y = -2, -4, -6, ..., -22 — entirely off the bottom edge. Fix: when the packed group has no own `width/height`, walk up the parent chain to the nearest ancestor that does (typically the board), accumulate `pcbX/pcbY` offsets along the way, and translate the ancestor's bounds into this group's local packing frame. The packer then enforces them as it would for any explicitly-bounded group. Test: `tests/components/pcb/large-chip-off-board-repro.test.tsx` reproduces the original symptom — 12x12 mm chip + 9 small SMTs in a region group with no width/height — and asserts every resulting pcb_component lands within the board's bounds. Before the fix the small siblings packed at X=-18, Y down to -22.99 (16+ mm below the board's bottom edge); after the fix every component is at |x| <= 25 and |y| <= 7. Wider tests/components/pcb (19 tests) and tests/components/primitive-components (150 tests) suites still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
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 #2272.
When a
<group>runs the auto-packer on its children but doesn'titself specify
widthandheight, the packer was invoked withbounds = undefined. Candidate positions outside the actual boardwere never rejected, and components packed in an unbounded column
going far past the board edges. On a 50x14 mm board with a
region_mcugroup at (-18, 0) holding ~10 small SMTs and one12x12 mm chip — exactly the configuration in the linked issue —
the small siblings landed at Y = -2, -4, -6, ..., -22, entirely
off the bottom edge.
Repro
Before the fix:
The packer's
SingleComponentPackSolvercorrectly rejectsout-of-bounds candidates when
boundsis set, but in this casethe
boundsargument was undefined because the inner group had noown
width/height.Fix
When the packed group has no own
width/height, walk up theparent chain to the nearest ancestor that does (typically the
board), accumulate
pcbX/pcbYoffsets along the way, and translatethe ancestor's bounds into this group's local packing frame. The
packer then enforces them as it would for any explicitly-bounded
group.
Total diff: ~50 source lines + a new test file.
Tests
tests/components/pcb/large-chip-off-board-repro.test.tsxmirrorsthe issue's repro and asserts every resulting
pcb_componentlands within the board's bounds:
Pre-fix: assertion fails on small siblings going off Y bound.
Post-fix: all 10 components placed within bounds.
Wider suites:
tests/components/pcb/(19 tests, including the new one) — all passtests/components/primitive-components/(150 tests) — all passTest plan
main(pre-fix) atthe
expect(...y).toBeGreaterThanOrEqual(-7)line for thepushed-off siblings
board no longer requires hand-pinning the chip with explicit
pcbX/pcbYto avoid the off-board columnRelated / future
The wider problem of "auto-placer doesn't always make optimal
choices when a dominant component competes with many small
siblings" is broader than this specific bug. This PR fixes the
extreme case where the packer effectively had infinite room to
work in. Smarter ordering / scoring is out of scope here.
🤖 Generated with Claude Code