From a59fcb8b2661fe6b583668dabc0ad90728c155ee Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 1 Nov 2026 21:50:33 +0100 Subject: [PATCH] :bug: Keep a head switched in a turned main at its first corner A head in a main turned 45 degrees switched to a wider variant. The new head was placed at the old one's untransformed top-left and turned about its own centre, so it landed off the old head's first corner, while its copies follow the main at their first corner through sync. The turned new head now moves so its first corner meets the old head's, the place a turned or flipped swap takes in a copy. Switching and then turning the main gives the same result as turning and then switching. Benchmark (scripts/bench-components, lower quantile in ms): | world | baseline | now | ratio | |------------------------------------+----------+--------+-------| | deepest-edit-through-three-levels | 35.215 | 20.289 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 39.832 | 0.58 | | library-update-into-copies | 83.083 | 45.839 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.079 | 0.43 | | main-edit-into-10-copies | 1.79 | 0.933 | 0.52 | | main-edit-into-100-copies | 15.415 | 9.056 | 0.59 | | main-edit-into-1000-copies | 153.086 | 99.369 | 0.65 | | variant-switch-into-copies | 32.052 | 21.489 | 0.67 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/swap.cljc | 15 ++++++++++----- .../common_tests/logic/composable_gen_test.cljc | 8 ++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index 8b228be4ca..2c64dfceb3 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -327,13 +327,18 @@ (defn- generate-keep-orientation "Give the new head of a swap, and its subtree, the flips and the rotation of the shape it replaces, around the head's own center. They come from - its parent, as when the parent is rotated, and are not overrides." + its parent, as when the parent is rotated, and are not overrides. The + turned head takes the place of the old one at their first corner, so it + turns rigidly with its parent." [changes new-shape shape] (if-let [orient (cll/orient-like new-shape shape (gsh/shape->center new-shape))] - (pcb/update-shapes changes - (cfh/get-children-ids-with-self (pcb/get-objects changes) (:id new-shape)) - orient - {:ignore-touched true}) + (let [ids (cfh/get-children-ids-with-self (pcb/get-objects changes) (:id new-shape)) + delta (gpt/subtract (first (:points shape)) (first (:points (orient new-shape))))] + (pcb/update-shapes changes ids + (cond->> orient + (not (gpt/almost-zero? delta)) + (comp #(gsh/move % delta))) + {:ignore-touched true})) changes)) (defn- generate-swap-in-copy diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index b3f45b5a5a..659e694260 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -950,3 +950,11 @@ (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]]})))) + +(t/deftest generated-switch-in-a-turned-main-keeps-the-first-corner + ;; a head in a main turned 45 degrees switches to a wider variant; it + ;; keeps its first corner, as its copies do through sync + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true + :library-depth 1 :library true :rich-variants true :library-text true + :layout-copies true :text true}] + :ops [[:rotate 1 0 0 0] [:switch 3 0 0 0]]}))))