From a9c31f8b5a1723eda100a75389728cb4f965b084 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 6 Nov 2026 23:08:59 +0100 Subject: [PATCH] :bug: Turn a copy's subtree by its target's axes, not its raw transform A board below its minimum size keeps the scale of a resize in its transform: a 0.01 px nested copy in a turned main resized from 140 to 120 high stored a transform scaled by 6/7. A full sync turned that copy's children by the raw transform of the target, so they came out scaled by 6/7, while the settled sync left them at their size. Turning a subtree to match a target takes only the directions of the target's axes; the lengths are left to constraints. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.727 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 38.407 | 0.56 | | library-update-into-copies | 83.083 | 48.07 | 0.58 | | main-edit-among-many-shapes | 4.837 | 2.187 | 0.45 | | main-edit-into-10-copies | 1.79 | 1.058 | 0.59 | | main-edit-into-100-copies | 15.415 | 10.201 | 0.66 | | main-edit-into-1000-copies | 153.086 | 96.625 | 0.63 | | variant-switch-into-copies | 32.052 | 19.74 | 0.62 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 8 ++++---- .../logic/comp_expected_geometry_test.cljc | 13 +++++++++++++ .../common_tests/logic/composable_gen_test.cljc | 11 +++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 31b25ef3ff..b5c0523876 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2094,16 +2094,16 @@ plus))) (defn orient-like - "Turn the subtree of `head` around `center` to match `target`'s matrix. - Compose flip flags with the roots, independent of rotation step size." + "Turn the subtree of `head` around `center` so its axes point like + `target`'s; the lengths of the axes are left to constraints. Compose flip + flags with the roots, independent of rotation step size." [head target center] (let [flip-x? (not= (boolean (:flip-x head)) (boolean (:flip-x target))) flip-y? (not= (boolean (:flip-y head)) (boolean (:flip-y target)))] (when-not (and (= (:transform head) (:transform target)) (mth/close? (or (:rotation head) 0) (or (:rotation target) 0) 0.01) (not flip-x?) (not flip-y?)) - (let [relative (gmt/multiply (or (:transform target) (gmt/matrix)) - (or (:transform-inverse head) (gmt/matrix))) + (let [relative (gmt/multiply (axes-matrix target) (gmt/inverse (axes-matrix head))) transform (gmt/transform-in center relative) turned (gsh/apply-transform head transform) angle (- (or (:rotation target) 0) (or (:rotation turned) 0))] diff --git a/common/test/common_tests/logic/comp_expected_geometry_test.cljc b/common/test/common_tests/logic/comp_expected_geometry_test.cljc index 43c59c9ec3..981a271e4b 100644 --- a/common/test/common_tests/logic/comp_expected_geometry_test.cljc +++ b/common/test/common_tests/logic/comp_expected_geometry_test.cljc @@ -528,3 +528,16 @@ (t/is (every? true? (map #(mth/close? %1 %2 1e-6) [a b c d] [(- (/ (mth/sqrt 2) 2)) (/ (mth/sqrt 2) 2) (/ (mth/sqrt 2) 2) (/ (mth/sqrt 2) 2)]))))) + +(t/deftest a-turn-leaves-out-the-scale-a-tiny-targets-transform-keeps + ;; a 0.01 px board resized below its minimum size keeps the scale in its + ;; transform; turning a subtree like it turns it without that scale + (let [head (cts/setup-shape {:type :frame :x 0 :y 0 :width 0.01 :height 0.01}) + scaled (gmt/matrix 0 1 (- (/ 6 7)) 0 0 0) + target (assoc head :transform scaled :transform-inverse (gmt/inverse scaled) :rotation 90) + child (cts/setup-shape {:type :rect :x 10 :y 10 :width 20 :height 20}) + turned ((cll/orient-like head target (gsh/shape->center head)) child) + [p1 p2 _ p4] (:points turned)] + (t/is (mth/close? 90 (:rotation turned) 0.01)) + (t/is (mth/close? 20 (gpt/distance p1 p2) 1e-6)) + (t/is (mth/close? 20 (gpt/distance p1 p4) 1e-6)))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index a0061baaa9..aebf51e0c7 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1268,3 +1268,14 @@ [:update-main 10] [:undo 0 0 0 0] [:nest 19 0 0 0] [:detach 1 0 0 0] [:detach 2 0 0 0] [:delete 23 0 0 0] [:restore 3 0 0 0] [:swap 13 0 0 0] [:nest 21 0 0 0]]})))) + +(t/deftest generated-tiny-copy-in-a-resized-turned-main-keeps-its-children-size + ;; a turned main resized past the minimum size of a nested 0.01 px copy + ;; leaves a scale in that copy's transform; a full sync turns its children + ;; without that scale, as the settled sync does + (t/is (map? (cg/run {:world [2 1 {:text true :text-styles true :layout nil :layout-children false + :layout-item-margins false :grid-square false :grid-empty false}] + :ops [[:duplicate 0 0 0 0] [:edit 8 0 0 0] [:resize 2 0 2 0] [:nest 0 0 0 0] + [:nest 12 0 0 0] [:delete 6 0 0 0] [:detach 8 0 0 0] [:restore 0 0 0 0] + [:duplicate 0 0 0 0] [:transform 3 3 0 8] [:delete 0] [:restore 0] + [:edit 4 0 1 1] [:update-main 4] [:delete 0 0 0 0] [:transform 2 2 0 0]]}))))