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

A switch carries a copy's turn only where the old and the new main agree
on it. Two mirrors can store the same rotation while their placed axes
point 180 degrees apart, and the model let them agree by that number, so
it expected a carried geometry override the editor rightly drops. The
turns of two mirrored mains now agree only where their placed axes do.

Harness only; the benchmark is not run.

Also in this commit:

- The harness changes that check the next commit, "Author the size a sync resize
  gives a swapped head".

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 13:47:44 +01:00
parent b9a62f23ea
commit 67484aff60
3 changed files with 39 additions and 5 deletions

View File

@ -815,6 +815,7 @@
model (-> model
(shadow/parent-orientation (all-objects situation) (all-objects settled))
(shadow/layout-released (all-objects situation) (all-objects settled))
(shadow/sync-scaled-heads (all-objects situation) (all-objects settled))
(settle-model settled true))
all (into (set (synchronizable-components situation)) (r/pending-components situation))
full-before (r/settle situation all)
@ -1079,7 +1080,8 @@
next-model (cond-> (or next-model model)
(not (#{:undo :redo} kind))
(-> (shadow/parent-orientation (all-objects situation) (all-objects after))
(shadow/layout-released (all-objects situation) (all-objects after))))
(shadow/layout-released (all-objects situation) (all-objects after))
(shadow/sync-scaled-heads (all-objects situation) (all-objects after))))
next-model (settle-model next-model after (empty? (r/pending-components after)))
meaningful (not (oracle/equivalent? (oracle/design-snapshot situation {:free-head-placement false})
(oracle/design-snapshot after {:free-head-placement false})))

View File

@ -572,6 +572,30 @@
result)))
model model))
(defn sync-scaled-heads
"A copy parent that a sync resizes sizes its untouched swapped heads
through their constraints. A head it gives another size authors that
size, placed in the parent."
[model before after]
(let [sized-alike? #(and (mth/close? (:width %1) (:width %2))
(mth/close? (:height %1) (:height %2)))]
(reduce-kv
(fn [result id groups]
(let [old (get before id)
shape (get after id)
old-parent (get before (:parent-id old))
parent (get after (:parent-id shape))]
(if (and (contains? groups :swap-group)
(not (contains? groups :geometry-group))
old shape old-parent parent
(= (:parent-id old) (:parent-id shape))
(:shape-ref parent)
(not (sized-alike? old-parent parent))
(not (sized-alike? old shape)))
(assoc-in result [id :geometry-group] (author-geometry shape parent))
result)))
model model)))
(defn settle
"A detached position turns its copies into ordinary shapes. Their former
component choice stops applying; other authored groups stay in place.
@ -818,10 +842,10 @@
;; a mirror stores its turn either way: the turns of two
;; mirrored mains agree where they point their axes alike
(and (= attr :rotation) old-main old-parent new-parent)
(or (same? (get old-placed attr) (get placed attr))
(and (mirrored? old-placed) (mirrored? placed)
(geom/same-placed-axes? old-main (get before (:parent-id old-main)) old-parent
main (get after (:parent-id main)) new-parent)))
(if (and (mirrored? old-placed) (mirrored? placed))
(geom/same-placed-axes? old-main (get before (:parent-id old-main)) old-parent
main (get after (:parent-id main)) new-parent)
(same? (get old-placed attr) (get placed attr)))
:else
(same? (get old-placed attr) (get placed attr))))

View File

@ -2274,6 +2274,14 @@
[:update-main 22 21 23 7] [:text-style 18 0 25 10] [:variant-property 1 9 23 5]
[:switch 20]]}))))
(t/deftest switching-a-copy-carries-no-mirrored-turn-its-mains-store-alike-but-point-apart
(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 5] [:restore] [:transform 6 5]
[:transform 3 9 7 13] [:switch] [:undo] [:update-main 1] [:duplicate 2]
[:update-main 15] [:switch]]}))))
(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