📎 Turn a main shape that update-main adds with its parent in the model

A turned copy can push its root's turn and a swapped nested head at once.
The push replaces the head in the main with a new shape. The composable
model wrote that head's turn in the frame its main parent had before the
push and left the root's turn to the parent orientation step, which only
turns shapes that existed before. The model then expected the head
without the root's turn, while the editor rightly gives it the copy's
turn in its parent. A main shape the push adds now takes its parent's
turn after the push.

Test: updating-a-turned-main-from-a-swapped-head-turns-the-new-head-with-
its-parent (the variant gate program of round 13, seed 371855618).
Common suite: 2432 tests, 0 failures.

Harness only; the benchmark is not run.

Also in this commit:

- Carry a mirrored turn that shares the new copy's rotation in the model. A copy
  can turn a mirrored child so that it stores the same rotation and flip as the
  new copy of a switch, but with the other mirror transform. The editor carries
  the copy's turn with its transform, since the old main and the new copy point
  their axes alike. The composable model compared only the rotations, found them
  equal and carried nothing. The same turn of two mirrored child shapes now
  differs in the model where their placed axes do.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 08:53:06 +01:00
parent 487514d897
commit 160bb17f76
2 changed files with 33 additions and 10 deletions

View File

@ -485,18 +485,19 @@
[group (if (= :geometry-group group) geometry (values shape group))]))
placement))
;; a main shape the push keeps or adds turns with its main
;; afterwards; its pushed geometry leaves out the turn its copy
;; parent shows against its main parent (the root's, against
;; its main), which an added main shape has only after the push
;; a main shape the push keeps turns with its main afterwards;
;; its pushed geometry leaves out the turn its copy parent shows
;; against its main parent (the root's, against its main). A
;; main shape the push adds takes its parent's turn after the push
(and (:geometry-group groups) (not pushed-swap?))
(update :geometry-group
(fn [geometry]
(if (= (:id shape) root-id)
(in-orientation geometry root main-root)
(in-orientation geometry (get before (:parent-id shape))
(or (get before (:parent-id ref))
(get after (:parent-id ref))))))))
(if (contains? before (:id ref))
(get before (:parent-id ref))
(get after (:parent-id ref))))))))
;; 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))
@ -815,11 +816,18 @@
:else
(same? (get old-placed attr) (get placed attr))))
;; the same turn of two mirrors differs 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)))))
carried (filter (fn [attr]
(let [new-value (get placed attr)]
(and (attribute-applicable? main attr)
(agrees? attr)
(not (same? (get old attr) new-value))))) attrs)]
(and (attribute-applicable? main attr)
(agrees? attr)
(differs? attr))) attrs)]
(cond-> result
(seq carried)
(assoc-in [(:id shape) group]

View File

@ -2194,6 +2194,21 @@
:layout-children false :grid-empty false :layout-copies false :text true}]
:ops [[:swap] [:make-variant 12] [:rotate] [:delete] [:transform 6 5] [:switch]]}))))
(t/deftest switching-a-copy-carries-a-mirrored-turn-that-shares-the-new-copys-rotation
(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 0 0 1] [:delete] [:transform 6 5]
[:transform 3 9 7 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
:layout-children false :grid-empty false :layout-copies false :text true}]
:ops [[:combine 10] [:combine 1] [:rotate 8] [:combine 13] [:combine 8] [:switch]
[:combine 18] [:make-variant] [:switch 18] [:combine] [:rotate 8]
[: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