diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index bb7a9e5c8e..3816496173 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2452,13 +2452,25 @@ :else plus))) +(defn- flips + "The flips of `shape`: its flags, or for a group or bool, which takes its + bounds from its children and keeps no flags, whether its transform + mirrors, as a horizontal flip." + [shape] + (if (#{:group :bool} (:type shape)) + (let [{:keys [a b c d]} (axes-matrix shape)] + {:flip-x (neg? (- (* a d) (* b c))) :flip-y false}) + {:flip-x (boolean (:flip-x shape)) :flip-y (boolean (:flip-y shape))})) + (defn orient-like "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)))] + (let [head-flips (flips head) + target-flips (flips target) + flip-x? (not= (:flip-x head-flips) (:flip-x target-flips)) + flip-y? (not= (:flip-y head-flips) (:flip-y target-flips))] (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?)) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 53ab0c56d7..8c4022dd28 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2472,6 +2472,11 @@ :ops [[:remove-child 1] [:delete] [:apply-token 0 1] [:style 0 3 0 1] [:apply-token 1] [:token-value 0 1] [:switch]]})))) +(t/deftest syncing-the-shapes-of-a-flipped-copy-group-keeps-them-flipped + (t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants true :text true :layout :flex + :layout-copies false :layout-children true}] + :ops [[:add-child 5] [:structure 12] [:transform 12 10 0 12]]})))) + (t/deftest settling-a-bool-in-a-grid-copy-twice-keeps-its-shapes-in-place (t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout :grid :layout-copies true :layout-children true}]