📎 Judge a switched child's turn by its axes in the composable model

A mirror stores its turn either way, so two variants can hold a flipped
child with one transform and the rotations 315 and 45. The switch model
compared the rotation numbers, saw the variants disagree, and expected the
switch to drop the copy's turn. The turns of a child whose old and new
mains are both mirrors, as the copy places them, now also agree where they
point their axes alike.

Test (the variant gate program of round 12, seed 164135730):
switching-a-copy-carries-the-turn-of-a-mirrored-child-stored-as-the-other-turn

Harness only; the benchmark is not run.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 04:07:04 +01:00
parent 5b223cb8f5
commit 5ed9771864
3 changed files with 35 additions and 1 deletions

View File

@ -24,6 +24,17 @@
vertical (gpt/unit (gpt/point c d))]
(gmt/matrix (:x horizontal) (:y horizontal) (:x vertical) (:y vertical) 0 0)))
(defn same-placed-axes?
"Whether `a`, moved from its parent `a-parent` into `a-target`, points its
axes as `b` does moved from `b-parent` into `b-target`. A mirror stores
its turn either way, so the axes tell what the rotations may not."
[a a-parent a-target b b-parent b-target]
(let [placed (fn [shape parent target]
(gmt/multiply (orientation-matrix target)
(gmt/inverse (orientation-matrix parent))
(orientation-matrix shape)))]
(gmt/close? (placed a a-parent a-target) (placed b b-parent b-target))))
(defn turn-sign
"-1 when `shape` is a mirror whose rotation is only the opposite of the
turn its transform holds, so it stores a turn of its subtree subtracted;

View File

@ -614,6 +614,11 @@
[(assoc result (:id shape) [p ordinal]) (update counts p (fnil inc 0))]))
[{} {}] (reverse (subtree-shapes objects root-id))))))
(defn- mirrored?
"Whether `values` hold exactly one flip."
[values]
(not= (boolean (:flip-x values)) (boolean (:flip-y values))))
(defn swap
"Predict switch carry from authored groups and the two mains. Matching
uses main names and ancestor kinds; copy renames never change a match."
@ -796,8 +801,19 @@
;; the head's turn and flips carry as one: only where the
;; mains share all of them
agrees? (fn [attr]
(if (and root? (contains? orientation attr))
(cond
(and root? (contains? orientation attr))
(every? #(same? (get old-placed %) (get placed %)) orientation)
;; 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)))
:else
(same? (get old-placed attr) (get placed attr))))
carried (filter (fn [attr]
(let [new-value (get placed attr)]

View File

@ -2159,6 +2159,13 @@
[:add-variant 0 6 7] [:combine 4 4 7] [:resize 3 7 4] [:switch 6] [:delete 5]
[:restore 0 5 7 5] [:swap 1 3 1 5] [:style 0 30 1] [:reset 3]]}))))
(t/deftest switching-a-copy-carries-the-turn-of-a-mirrored-child-stored-as-the-other-turn
(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 9 0 13] [:switch]]}))))
(t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry
(t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true