From dfa7e63147e003bc819fe591d5d996e15253c262 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 6 Nov 2026 01:11:35 +0100 Subject: [PATCH] :bug: Keep a switched head's authored turn against its parent's turn too A switch that carries an authored orientation marks a geometry override when the head's turn differs from its new main's placement. Inside a copy the placement left out the turn of the head's parent: a head whose near main's half turn cancelled its turned copy parent's showed the main's own turn, looked unchanged and lost its override. The placement includes the parent's turn and flips inside a copy too. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.589 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 39.264 | 0.57 | | library-update-into-copies | 83.083 | 48.997 | 0.59 | | main-edit-among-many-shapes | 4.837 | 2.377 | 0.49 | | main-edit-into-10-copies | 1.79 | 1.031 | 0.58 | | main-edit-into-100-copies | 15.415 | 9.145 | 0.59 | | main-edit-into-1000-copies | 153.086 | 97.525 | 0.64 | | variant-switch-into-copies | 32.052 | 21.316 | 0.67 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 10 ++++------ .../test/common_tests/logic/composable_gen_test.cljc | 9 +++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 2c2c75fd1a..551f818694 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -391,14 +391,12 @@ main-parent (if position (get-in (meta position) [:container :objects (:parent-id position)]) main-parent) - parent-delta (if (and (:shape-ref parent) (nil? position)) 0 + rotation (mod (+ (or (:rotation baseline) 0) (- (or (:rotation parent) 0) (or (:rotation main-parent) 0))) - rotation (mod (+ (or (:rotation baseline) 0) parent-delta) 360) + 360) flip (fn [key] - (if (and (:shape-ref parent) (nil? position)) - (boolean (get baseline key)) - (odd? (count (filter identity [(get baseline key) (get parent key) - (get main-parent key)]))))) + (odd? (count (filter identity [(get baseline key) (get parent key) + (get main-parent key)])))) changed? (or (not (mth/close? (mod (or (:rotation shape) 0) 360) rotation 0.01)) (not= (boolean (:flip-x shape)) (flip :flip-x)) (not= (boolean (:flip-y shape)) (flip :flip-y)))] diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index dd058efafb..12dca7c569 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1210,3 +1210,12 @@ :layout-item-margins false :grid-square false :rich-variants true :layout-children false :grid-empty false :layout-copies true :text true}] :ops [[:rotate 0 0 0 0] [:update-main 0 0 0 0] [:resize 0 0 0 0] [:switch 4 0 0 0]]})))) + +(t/deftest generated-switch-in-a-copy-keeps-a-turn-that-cancels-its-parents + ;; a copy child shows no turn: its near main's half turn cancels its turned + ;; copy parent's; a switch keeps that authored turn as an override + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:duplicate 0 0 0 0] [:rotate 16 0 7 0] [:duplicate 0 0 0 0] [:rotate 16 0 7 0] + [:switch 12 0 0 0]]}))))