📎 Judge the turns of two mirrored children by their axes in the model

A mirror stores one turn as two rotations, such as 315 and 45, with the
same transform. On a switch, the old copy child stored 315 and its new
copy 45, so the editor rightly carried nothing, while the composable
model compared the rotations by number and expected the turn to carry.
The turns of two mirrored child shapes now differ in the model only
where their placed axes do.

Test: switching-a-copy-carries-no-mirrored-turn-stored-the-other-way-in-
the-model (the variant gate program of round 15, seed 164135730).
Common suite: 2438 tests, 0 failures (with the next commit).

Harness only; the benchmark is not run.

Also in this commit:

- Model only the turn a resized top root shows against its parent. A top copy
  root that authors its geometry inherits its parent's turn, and update-main
  pushes only the turn it shows against that parent. In a turned parent, a
  resized root then leaves the main root and a swapped head pushed with it
  unturned. The composable model took the whole turn of such a root as pushed
  and expected the new head turned with it. It now takes a root that authors its
  geometry as inheriting its parent's turn, as a nested root does; only a top
  root that authors none inherits all of its turn.
- The harness changes that check the next commit, "Keep on the copy a layout
  child override no layout parent pushes".

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 11:46:23 +01:00
parent f7627ec5e0
commit 35f4b5ef91
3 changed files with 36 additions and 13 deletions

View File

@ -552,13 +552,13 @@
(select-keys target [:component-id :component-file])))
:else
(let [source-parent (get source-objects (:parent-id source))
item-group (.startsWith (name group) "layout-item-")
(let [item-group (.startsWith (name group) "layout-item-")
intrinsic (and (:layout source)
(#{:layout-item-h-sizing :layout-item-v-sizing} group)
(#{:fix :auto} (get source group)))
;; only a layout parent in the main pushes layout child groups
push-item (or intrinsic
(and (not= id root-id) (:layout source-parent)))
(and (not= id root-id) (:layout (get objects (:parent-id target)))))
target (if (and item-group (not push-item)) kept target)
expected (if (= group :layout-grid-cells)
(get (grid/remap-groups {group (shadow/values source group)}

View File

@ -449,12 +449,14 @@
main-parent (get before (:parent-id main-root) {})
;; the way the rotation of `shape` stores its turn
sign (geom/turn-sign shape)
;; the turn the copy root inherits places it and is not pushed
;; the turn the copy root inherits places it and is not pushed:
;; all of a top root's that authors no geometry, else its parent's
inherits-all? (and (:component-root root) (not (get-in model [root-id :geometry-group])))
geometry (cond-> (values shape :geometry-group)
(and (:component-root root) (not (get-in model [root-id :geometry-group])))
inherits-all?
(in-orientation root main-root sign)
(and (not (:component-root root)) root-parent)
(and (not inherits-all?) root-parent)
(in-orientation root-parent main-parent sign))
replaced (when (and (contains? groups :swap-group)
(not= (:shape-ref shape) (:shape-ref updated)))
@ -501,10 +503,17 @@
;; a variant main keeps its set's name, and the copy root its own
kept-name (when (and (= id root-id) (:variant-id ref)) (:name-group groups))
groups (cond-> groups kept-name (dissoc :name-group))
;; only a layout parent pushes layout child groups; the copy keeps the others
kept-items (when (and (not= id root-id) (not (ctl/any-layout? (get after (:parent-id ref)))))
(into {} (filter #(.startsWith (name (key %)) "layout-item-")) groups))
groups (apply dissoc groups (keys kept-items))
result (cond-> (dissoc result id)
(and (contains? groups :swap-group)
(not= (:component-id updated) (:component-id ref)))
(assoc id {:swap-group {}})
(seq kept-items)
(update id merge kept-items)
kept-name
(assoc-in [id :name-group] kept-name)
(and (:shape-ref ref) (seq groups))
@ -816,14 +825,14 @@
:else
(same? (get old-placed attr) (get placed attr))))
;; the same turn of two mirrors differs where they point
;; their axes apart
;; a mirror stores its turn either way: the turns of two
;; mirrors differ where they point their axes apart
differs? (fn [attr]
(or (not (same? (get old attr) (get placed attr)))
(and (= attr :rotation) (not root?) old-parent new-parent
(mirrored? old) (mirrored? placed)
(not (geom/same-placed-axes? old old-parent new-parent
main (get after (:parent-id main)) new-parent)))))
(if (and (= attr :rotation) (not root?) old-parent new-parent
(mirrored? old) (mirrored? placed))
(not (geom/same-placed-axes? old old-parent new-parent
main (get after (:parent-id main)) new-parent))
(not (same? (get old attr) (get placed attr)))))
carried (filter (fn [attr]
(and (attribute-applicable? main attr)
(agrees? attr)

View File

@ -2201,6 +2201,13 @@
:ops [[:swap] [:make-variant 12] [:rotate 0 0 1] [:delete] [:transform 6 5]
[:transform 3 9 7 13] [:switch]]}))))
(t/deftest switching-a-copy-carries-no-mirrored-turn-stored-the-other-way-in-the-model
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout :grid :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies false :text true}]
:ops [[:swap] [:make-variant 12] [:rotate] [:delete] [:transform 6 5]
[:transform 3 0 0 13] [:switch]]}))))
(t/deftest updating-a-turned-main-from-a-swapped-head-turns-the-new-head-with-its-parent
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :flex :variant-diff false
:layout-item-margins false :grid-square false :rich-variants false
@ -2230,6 +2237,13 @@
[:add-variant] [:switch 22] [:duplicate 1] [:detach 20] [:text-style 23 0 1]
[:switch 6] [:update-main 22]]}))))
(t/deftest updating-a-main-from-a-resized-root-keeps-the-turn-its-parent-gives-a-swapped-head
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff true
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty true :layout-copies false :text false}]
:ops [[:make-variant 3] [:nest 4] [:combine 4] [:rotate 2] [:detach 1] [:combine 3]
[:switch] [:update-main] [:detach 2] [:resize 2] [:switch 5] [:update-main]]}))))
(t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false
:layout-item-margins false :grid-square true :rich-variants false