From 487514d897a04cf31141f3fca9295fe1db1d4c46 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 11 Nov 2026 07:19:30 +0100 Subject: [PATCH] :bug: Carry no turn a mirrored copy child only stores the other way A mirror can store 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 values looked different and the switch took them for an override. The agreement check for mirrors then let the turn carry, marking the child's geometry touched for no change. The check for values already equal now uses the same comparison as the agreement, so the two turns of one mirror count as equal and nothing carries. Test: switching-a-copy-carries-no-turn-a-mirrored-child-only-stores-the- other-way (the variant gate program of round 13, seed 164135730). Common suite: 2431 tests, 0 failures. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+--------+--------| | deepest-edit-through-three-levels | 35.215 | 22.408 | 22.761 | 0.64 | | edit-through-a-chain-of-dependents | 68.931 | 40.015 | 41.455 | 0.58 | | library-update-into-copies | 83.083 | 47.581 | 50.082 | 0.57 | | main-edit-among-many-shapes | 4.837 | 2.3 | 2.431 | 0.48 | | main-edit-into-10-copies | 1.79 | 1.059 | 1.116 | 0.59 | | main-edit-into-100-copies | 15.415 | 9.513 | 9.981 | 0.62 | | main-edit-into-1000-copies | 153.086 | 107.092 | 108.68 | 0.7 | | variant-switch-into-copies | 32.052 | 20.943 | 21.854 | 0.65 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/swap.cljc | 22 +++++++++++-------- .../logic/composable_gen_test.cljc | 6 +++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index eb1a009b6d..3e40341ced 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -175,6 +175,17 @@ [shape] (not= (boolean (:flip-x shape)) (boolean (:flip-y shape)))) +(defn- close-geometry? + "Whether `a` and `b` hold the geometry `attr` within its precision. A + mirror stores its turn either way, so the turns of two mirrors are also + close where both point their axes alike." + [attr a b] + (or (gsh/close-attrs? attr (get a attr) (get b attr)) + (and (= attr :rotation) + (mirrored? a) + (mirrored? b) + (gmt/close? (cll/axes-matrix a) (cll/axes-matrix b))))) + (defn- switch-attr-operations "The `[attr value]` pairs that carry `attr` over a variant switch, from `previous-shape`, the copy shape before the switch placed like @@ -202,7 +213,7 @@ ;; If the values are already equal, don't copy them; geometry ;; within its precision (if (= sync-group :geometry-group) - (gsh/close-attrs? attr (get previous-shape attr) (get current-shape attr)) + (close-geometry? attr previous-shape current-shape) (= (get previous-shape attr) (get current-shape attr))) ;; If :selrect/:points values are already equal ignoring displacement, @@ -222,17 +233,10 @@ ;; 3. We set Copy’s bg to green (so it it has an override on the bg). ;; 4. We switch Copy to use C2 as base. ;; 5. The bg of Copy now is blue (we ignore the override) - ;; A mirror stores its turn either way, so the turns of two - ;; mirrors also agree where both point their axes alike. (and (not (contains? #{:points :selrect :content} attr)) (not (if (= sync-group :geometry-group) - (or (gsh/close-attrs? attr (get origin-ref-shape attr) (get current-shape attr)) - (and (= attr :rotation) - (mirrored? origin-ref-shape) - (mirrored? current-shape) - (gmt/close? (cll/axes-matrix origin-ref-shape) - (cll/axes-matrix current-shape)))) + (close-geometry? attr origin-ref-shape current-shape) (= (get origin-ref-shape attr) (get current-shape attr))))) ;; The :content attr cant't be copied to elements of different type diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 5f299f6f7a..7a53f2e5aa 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2188,6 +2188,12 @@ (t/is (seq turned)) (t/is (every? geom/decomposes? turned)))) +(t/deftest switching-a-copy-carries-no-turn-a-mirrored-child-only-stores-the-other-way + (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] [: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