From 13905afc6072917e89d28a22de08be9459efb86f Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 23 Oct 2026 19:44:53 +0200 Subject: [PATCH] :bug: Keep authored root orientation as a switch override A switch places the new root in the old orientation before carrying attributes. When rotation is already equal, the carry step emits no write and drops its geometry group. Preserve that group for retained authored root orientation so later sync keeps the visible result. Extend the rotation regression to check touched and later sync: two assertions fail before the fix. Focused checks pass 43 tests and 166 assertions, including the two previously shrunk generated regressions. Benchmark vs Phase 1e: main 10/100/1000 0.64/0.65/0.97; levels 0.49; chain 0.59; library 0.58; many shapes 0.89; switch 0.60. No flags. AI-assisted-by: GPT-6 --- common/src/app/common/logic/variants.cljc | 57 ++++++++++--------- .../common_tests/logic/swap_group_test.cljc | 5 +- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 82cb43fe06..eab88f9abd 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -361,6 +361,31 @@ (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- keep-orientation-override + "Retained orientation that differs from the new component's expected + placement needs a geometry override to survive later sync." + [changes shape baseline page ldata component-id] + (let [parent (get-in page [:objects (:parent-id shape)]) + main (ctf/get-component-root ldata (ctkl/get-component ldata component-id)) + main-parent (get-in (ctf/get-component-container ldata (ctkl/get-component ldata component-id)) + [:objects (:parent-id main)]) + parent-delta (if (:shape-ref parent) 0 + (- (or (:rotation parent) 0) (or (:rotation main-parent) 0))) + rotation (mod (+ (or (:rotation baseline) 0) parent-delta) 360) + flip (fn [key] + (if (:shape-ref parent) + (boolean (get baseline 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)))] + (cond-> changes + changed? + (pcb/update-shapes [(:id shape)] + #(update % :touched (fnil conj #{}) :geometry-group) + {:ignore-touched true})))) + (defn generate-keep-touched "This is used as part of the switch process, when you switch from an original-shape to a new-shape. It generate changes to @@ -435,7 +460,12 @@ (keep-swapped-item changes new old ldata page libraries) (clsw/update-attrs-on-switch changes new old new-shape original-shape old-ref container))) changes - pairs)] + pairs) + changes (cond-> changes + (ctk/touched-group? original-shape :geometry-group) + (keep-orientation-override original-shape new-shape page + (or (get-in libraries [(:component-file new-shape) :data]) ldata) + (:component-id new-shape)))] [changes (mapv (comp :parent-id :new) pairs)])) (defn- shape-index @@ -445,31 +475,6 @@ (when-let [parent (get objects parent-id)] (or (d/index-of (:shapes parent) shape-id) 0))) -(defn- keep-orientation-override - "A plain swap keeps its old orientation. When that differs from the new - component's expected placement, the swap authors a geometry override." - [changes shape baseline page ldata component-id] - (let [parent (get-in page [:objects (:parent-id shape)]) - main (ctf/get-component-root ldata (ctkl/get-component ldata component-id)) - main-parent (get-in (ctf/get-component-container ldata (ctkl/get-component ldata component-id)) - [:objects (:parent-id main)]) - parent-delta (if (:shape-ref parent) 0 - (- (or (:rotation parent) 0) (or (:rotation main-parent) 0))) - rotation (mod (+ (or (:rotation baseline) 0) parent-delta) 360) - flip (fn [key] - (if (:shape-ref parent) - (boolean (get baseline 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)))] - (cond-> changes - changed? - (pcb/update-shapes [(:id shape)] - #(update % :touched (fnil conj #{}) :geometry-group) - {:ignore-touched true})))) - (defn generate-component-swap-in-place "Swap the copy head `shape` of `page` for a copy of the component `component-id` of library data `ldata`. The new head takes the old one's diff --git a/common/test/common_tests/logic/swap_group_test.cljc b/common/test/common_tests/logic/swap_group_test.cljc index f5e4df5d25..9e50d71178 100644 --- a/common/test/common_tests/logic/swap_group_test.cljc +++ b/common/test/common_tests/logic/swap_group_test.cljc @@ -642,7 +642,10 @@ copy (ths/get-shape file' :copy01) child (ths/get-shape-by-id file' (first (:shapes copy)))] (t/is (== 30 (mth/precision (:rotation copy) 2))) - (t/is (== 30 (mth/precision (:rotation child) 2))))) + (t/is (== 30 (mth/precision (:rotation child) 2))) + (t/is (ctk/touched-group? copy :geometry-group)) + (t/is (= (orientation file' :copy01) + (orientation (propagate file' :c02) :copy01))))) (t/deftest switch-turns-the-swap-with-the-child-of-the-new-variant (let [file (-> (thf/sample-file :file1)