📎 Anchor the geometry a switch carries to its new parent in the model

The model records an authored geometry with the parent it sits in, so a
later resize of that parent moves and sizes it through its constraints,
as production does. The geometry a switch carries into the new copy was
recorded without it: after a variant main shrank, the switched copy's
child, which authors its geometry and stretches left and right, followed
its parent in production while the model kept its old width. A carried
geometry below the head now records its new parent.

Test (the stale gate program of seed 175377838):
resizing-a-variant-main-resizes-a-switched-copy-child-through-its-constraint
Harness only; the benchmark is not run.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-12 11:24:02 +01:00
parent 2588315b9a
commit 3b8a2ce11a
2 changed files with 15 additions and 4 deletions

View File

@ -890,10 +890,14 @@
(cond-> result
(seq carried)
(assoc-in [(:id shape) group]
(merge placed
(when (and root? (= :geometry-group group)) position-orientation)
;; an attribute the copy leaves unset carries as unset
(into {} (map #(vector % (get old %))) carried)))))))
(cond-> (merge placed
(when (and root? (= :geometry-group group)) position-orientation)
;; an attribute the copy leaves unset carries as unset
(into {} (map #(vector % (get old %))) carried))
;; a carried geometry sits in the new parent, whose later
;; resizes move and size it through its constraints
(and (= :geometry-group group) new-parent (not root?))
(vary-meta assoc ::position {:shape shape :parent new-parent :sized? false})))))))
result (cond->> (dissoc groups :swap-group)
;; the head carries only its own layout item overrides
(= root-id (:id shape))

View File

@ -2423,6 +2423,13 @@
[:combine 5] [:switch 0] [:variant-property 0 0 0 0] [:switch 1] [:combine 0] [:switch 4]
[:combine 0] [:switch 0]]}))))
(t/deftest resizing-a-variant-main-resizes-a-switched-copy-child-through-its-constraint
(t/is (map? (cg/run {:world [1 0 {:variants true :text-styles false :library-variants false :stale-libraries false
:layout :grid :layout-item-margins false :grid-square false :library-depth 2
:library false :rich-variants true :layout-children false :library-text false
:grid-empty false :layout-copies false :text false}]
:ops [[:transform 0 2 0 7] [:delete] [:switch] [:transform 1 1]]}))))
(t/deftest random-shape-structure-compositions
(let [coverage (atom {})
failure (atom nil)]