From fa0ba43c48b3f33e3c073672e1f266841746d6c8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 1 Nov 2026 18:37:23 +0100 Subject: [PATCH] :bug: Compare a switched head's orientation with its position in a copy A nested head whose position in the enclosing main has a geometry override, such as a resize, switched to a variant whose main is turned. The switch keeps the old head's orientation, which agrees with its position, the placement a sync gives a swapped head; but because the reference chain had a geometry override, the switch compared the kept orientation with the new main and marked a geometry override that no later sync needs. The kept orientation is compared with the new main only when an orientation override carries: the reference chain has a geometry override and the old and new variant mains share their orientation. Otherwise, inside a copy, it is compared with the position. Benchmark (scripts/bench-components, lower quantile in ms): | world | baseline | now | ratio | |------------------------------------+----------+--------+-------| | deepest-edit-through-three-levels | 35.215 | 20.017 | 0.57 | | edit-through-a-chain-of-dependents | 68.931 | 37.029 | 0.54 | | library-update-into-copies | 83.083 | 45.694 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.094 | 0.43 | | main-edit-into-10-copies | 1.79 | 0.95 | 0.53 | | main-edit-into-100-copies | 15.415 | 9.21 | 0.60 | | main-edit-into-1000-copies | 153.086 | 93.672 | 0.61 | | variant-switch-into-copies | 32.052 | 20.466 | 0.64 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 22 ++++++++++++++----- .../logic/composable_gen_test.cljc | 8 +++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 95c89c7b64..9d492213c7 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -362,6 +362,13 @@ (let [new-touched (ctf/get-touched-from-ref-chain-until-target-ref container libraries shape nil)] (assoc shape :touched (disj new-touched :swap-group))))) +(defn- same-orientation? + "Whether shapes `a` and `b` have the same rotation and flips." + [a b] + (and (mth/close? (mod (or (:rotation a) 0) 360) (mod (or (:rotation b) 0) 360) 0.01) + (= (boolean (:flip-x a)) (boolean (:flip-x b))) + (= (boolean (:flip-y a)) (boolean (:flip-y b))))) + (defn- keep-orientation-override "Retained orientation that differs from the new component's expected placement needs a geometry override to survive later sync." @@ -524,18 +531,21 @@ o-ref-shapes-p-map new-paths counterpart)) changes grid-pairs) - root-geometry? (some #(and (= (:id %) (:id original-shape)) - (ctk/touched-group? % :geometry-group)) orig-touched) + new-ldata (or (get-in libraries [(:component-file new-shape) :data]) ldata) + new-main (ctf/get-component-root new-ldata (ctkl/get-component new-ldata (:component-id new-shape))) + ;; An authored orientation carries only where both variants share it + carried-orientation? (and (some #(and (= (:id %) (:id original-shape)) + (ctk/touched-group? % :geometry-group)) orig-touched) + (same-orientation? orig-base-ref-shape new-main)) parent (get page-objects (:parent-id original-shape)) ;; A switch keeps orientation even when the old main supplied it. - ;; If no geometry was carried, placement from an enclosing copy is + ;; If no orientation was carried, placement from an enclosing copy is ;; still inherited rather than authored by this switch. - position (when (and (not root-geometry?) (:shape-ref parent)) + position (when (and (not carried-orientation?) (:shape-ref parent)) (ctf/find-ref-shape nil page libraries original-shape :include-deleted? true :with-context? true)) changes (keep-orientation-override changes original-shape new-shape page - (or (get-in libraries [(:component-file new-shape) :data]) ldata) - (:component-id new-shape) position) + new-ldata (:component-id new-shape) position) ;; A carried size changes the frame its untouched children follow. ;; Place them through the same constraints as an ordinary copy sync. changes (cond-> changes diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 5c46250667..b3f45b5a5a 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -942,3 +942,11 @@ (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library true :rich-variants true :layout-copies true :text true}] :ops [[:switch 6 0 0 0] [:rotate 0 0 0 0] [:reset 5 0 0 0]]})))) + +(t/deftest generated-switch-to-a-turned-variant-keeps-the-orientation-of-its-position + ;; a nested head whose position in the enclosing main has a resize override + ;; switches to a variant turned 45 degrees; it keeps the orientation of its + ;; position, which sync gives it, so it has no geometry override + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :variant-diff false :rich-variants true + :layout-copies true :text true}] + :ops [[:transform 3 3 0 0] [:resize 0 0 0 0] [:switch 4 0 0 0]]}))))