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]]}))))