From 5ed97718640a10322841a3bffa35f380f04b8f01 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 11 Nov 2026 04:07:04 +0100 Subject: [PATCH] :paperclip: 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 --- .../test_helpers/composable/geometry.cljc | 11 +++++++++++ .../common/test_helpers/composable/shadow.cljc | 18 +++++++++++++++++- .../logic/composable_gen_test.cljc | 7 +++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/test_helpers/composable/geometry.cljc b/common/src/app/common/test_helpers/composable/geometry.cljc index 714336168b..c22bbdc44c 100644 --- a/common/src/app/common/test_helpers/composable/geometry.cljc +++ b/common/src/app/common/test_helpers/composable/geometry.cljc @@ -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; diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 16c061270e..b1d9ce0d2a 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -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)] diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 3a9ae9eea0..3430c7e0f8 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -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