From bb909e383f628e44d07e2abbc88b174fa49a0c93 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 1 Nov 2026 11:55:28 +0100 Subject: [PATCH] :bug: Measure a reset head's turn after the mirror of its main's parent A library turns and flips an outer component; a file that has not accepted it resets a nested head of an unturned copy. The loaded main is turned onto the copy's parent with the angle between the parents, but under a mirror apply-transform negates the rotation before adding the turn: the head and its child got rotation 90 with an identity transform. The angle is now measured against the parent once transformed, as orient-like does. Benchmark (scripts/bench-components, lower quantile in ms): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 18.135 | 0.51 | | edit-through-a-chain-of-dependents | 68.931 | 39.807 | 0.58 | | library-update-into-copies | 83.083 | 44.721 | 0.54 | | main-edit-among-many-shapes | 4.837 | 1.972 | 0.41 | | main-edit-into-10-copies | 1.79 | 0.964 | 0.54 | | main-edit-into-100-copies | 15.415 | 9.318 | 0.60 | | main-edit-into-1000-copies | 153.086 | 90.874 | 0.59 | | variant-switch-into-copies | 32.052 | 20.887 | 0.65 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 4 +++- common/test/common_tests/logic/composable_gen_test.cljc | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 2109d034c2..ac98f0e52f 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -356,7 +356,9 @@ (gmt/unit? relative)) main-container (let [transform (gmt/transform-in (gsh/shape->center shape-main) relative) - angle (- (or (:rotation target) 0) (or (:rotation origin) 0)) + ;; a mirror negates the rotation before the turn adds to it + angle (- (or (:rotation target) 0) + (or (some-> origin (gsh/apply-transform transform) :rotation) 0)) flip (fn [shape key] (cond-> (get shape key) (not= (boolean (get origin key)) (boolean (get target key))) not)) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index b8c64326c1..e8cb371579 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -908,3 +908,12 @@ (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library true :rich-variants true :layout-copies true :text true}] :ops [[:swap 6 0 0 0] [:transform 17 3 0 0] [:swap 9 0 0 0] [:edit 0 0 1 1] [:update-main 0]]})))) + +(t/deftest generated-reset-under-a-stale-mirrored-main-keeps-a-consistent-rotation + ;; the library turns and flips an outer component; a file that has not + ;; accepted it resets a nested head of an unturned copy, which keeps a + ;; rotation its transform agrees with + (t/is (map? (cg/run {:world [2 1 {:library true :stale-libraries true :library-dependency true :library-text true}] + :ops [[:library-transform 2 3 4 0] [:library-delete 0] [:library-sync] [:library-restore 0] + [:library-sync] [:library-undo 0 0 0 0] [:library-transform 16 4 4 0] + [:edit 17 1 1 :copy-head] [:reset 17]]}))))