fix(layout): manualEdits position no longer double-counts parent group anchor#2282
Open
gsdali wants to merge 2 commits intotscircuit:mainfrom
Open
fix(layout): manualEdits position no longer double-counts parent group anchor#2282gsdali wants to merge 2 commits intotscircuit:mainfrom
gsdali wants to merge 2 commits intotscircuit:mainfrom
Conversation
The board's manualEdits.pcb_placements positions a component via _computePcbGlobalTransformBeforeLayout, but the auto-packer in each group then re-positioned the same component, silently undoing the user's pin. Group_doInitialPcbLayoutPack marked a child as static (skip-repack) only if isRelativelyPositioned() returned true — and that helper checks pcbX/pcbY/pcbLeftEdgeX/etc., not manualEdits. Components placed via the IDE drag-and-pin flow weren't covered. Walk every descendant of the group being packed and ask the nearest subcircuit for a manual placement. If one exists, add the pcb_component_id to staticPcbComponentIds — the packer then leaves it where the manual edit pinned it. Repro test in tests/pcb-packing/ — chip + 4 caps inside an anchored region, manualEdits pinning each cap to a different corner. Without the fix every cap collapses to the chip's network-minimum (x=0); with the fix they land at the requested coordinates. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…p anchor
A component placed via `manualEdits.pcb_placements` inside a positioned
`<group pcbX={N}>` landed at `(N + manual.x, manual.y)` instead of
`(manual.x, manual.y)` — the group's anchor was added on top of the
absolute manual position. Both `_computePcbGlobalTransformBeforeLayout`
(initial render) and `applyPackOutput` (post-pack write-back) had the
same shape:
compose(parent_or_group_transform, translate(manualPlacement), ...)
`manualPlacement` is the result of
`applyToPoint(subcircuit.globalTransform, position.center)` — for the
top-level board (transform = identity) it equals `position.center`,
which the IDE writes in board-absolute coordinates. Composing the
parent group's transform on top of that translates by the group anchor
a second time.
Fix in two places:
1. `_computePcbGlobalTransformBeforeLayout` (PrimitiveComponent.ts):
when manualPlacement is set, return JUST the manual translate +
rotate, without composing the parent's transform.
2. `applyPackOutput`: when the component being written back has a
matching entry in the subcircuit's manualEdits.pcb_placements,
skip the pack transform entirely — its child pcb primitives are
already at the absolute manual position from initial render. The
`position_mode` is still flipped to "packed" so downstream code
sees a consistent state.
Companion to fix tscircuit#2280 (packer respects manualEdits as static). Both
together make the IDE drag-and-pin flow behave correctly for
components inside positioned regions.
Repro test: `tests/pcb-packing/manual-edits-position-no-double-count.test.tsx`
- Cap manually placed at (11.4, 4.3) inside `<group pcbX={16}>`.
- Pre-fix: cap lands at (27.4, 4.3). Post-fix: (11.4, 4.3).
- Second test asserts no regression for a group at (0, 0).
Both new tests + the static-marking repro from tscircuit#2280 pass. Wider PCB /
group / packing suites run clean (53 pass, 2 pre-existing timing-flaky
tests pass when run in isolation).
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 #2281.
A component placed via
manualEdits.pcb_placementsinside a positioned<group pcbX={N}>landed at(N + manual.x, manual.y)instead of(manual.x, manual.y)— the group's anchor was added on top of the absolute manual position. From the user's perspective, every IDE drag inside a regional group ended up shifted by that group's anchor on the next rebuild.Both
_computePcbGlobalTransformBeforeLayout(initial render) andapplyPackOutput(post-pack write-back) had the same shape:manualPlacementis the result ofapplyToPoint(subcircuit.globalTransform, position.center). For the top-level board (transform = identity) it equalsposition.center, which the IDE writes in board-absolute coordinates. Composing the parent group's transform on top of that translates by the group anchor a second time.Repro
tests/pcb-packing/manual-edits-position-no-double-count.test.tsx:Pre-fix:
c1.center = (27.4, 4.3)(the +16 region anchor was added on top of the absolute manual position).Post-fix:
c1.center = (11.4, 4.3)(lands exactly where the user dragged it).A second test asserts a group at
pcbX={0} pcbY={0}continues to work — no regression for the existing-correct case.Fix
Two edits, same root cause:
1.
_computePcbGlobalTransformBeforeLayout(PrimitiveComponent.ts):when
manualPlacementis set, return JUST the manual translate + rotate, without composing the parent's transform.2.
applyPackOutput(Group_doInitialPcbLayoutPack/):when the component being written back has a matching entry in the subcircuit's manualEdits.pcb_placements, skip the pack transform — the component's child pcb primitives are already at the absolute manual position from initial render.
position_modeis still flipped to"packed"so downstream code sees a consistent state.Stacked on #2280
This PR is stacked on #2280 (packer respects manualEdits as static). Without that fix, the packer overrides the manual position with its own (different, also wrong) value, masking this bug. Together both fixes make the IDE drag-and-pin flow behave correctly end-to-end.
Test plan
tests/pcb-packing/manual-edits-position-no-double-count.test.tsx(positioned group + zero-anchored group)tests/pcb-packing(3 tests),tests/components/pcb(47),tests/groups(2),tests/features/pcb-pack-layout(1) — all pass when run individually; two unrelated timing-sensitive tests in the wider parallel run flaked twice but green when re-run alone_getSchematicGlobalManualPlacementTransform) at line ~890 has the same shape and may want a parallel fix in a follow-up PR🤖 Generated with Claude Code