diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 807315fd99..fba12644d5 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2031,7 +2031,8 @@ "The rotation that `shape`, just turned by `angle` with its subtree, stores: `rotation` plus `angle`, or minus it when only that one decomposes its transform with its flips. A mirror that flips after its turn turns the - other way." + other way. When neither does, as when the turn changes its flips, the + rotation its transform decomposes into." [shape rotation angle] (let [{:keys [a b c d]} (or (:transform shape) (gmt/matrix)) mirrored (not= (boolean (:flip-x shape)) (boolean (:flip-y shape))) @@ -2044,9 +2045,16 @@ (and (:flip-x shape) (:flip-y shape) (same? value (+ turn 180))))) plus (mod (+ rotation angle) 360) minus (mod (- rotation angle) 360)] - (if (and (= mirrored (neg? (- (* a d) (* b c)))) - (not (stores? plus)) (stores? minus)) + (cond + (and (= mirrored (neg? (- (* a d) (* b c)))) + (not (stores? plus)) (stores? minus)) minus + + ;; a turn that drops or adds a flip leaves neither; the transform decides + (and (not (stores? plus)) (not (stores? minus))) + (mod turn 360) + + :else plus))) (defn orient-like diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 78f9c420d6..2e55f5d5a1 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1230,3 +1230,13 @@ [:swap 2 0 0 0] [:duplicate 4 0 0 0] [:delete 8] [:restore 8] [:undo 0 0 0 0] [:text-style 4 0 1] [:delete 0 0 0 0] [:nest 21 0 0 0] [:duplicate 0 0 0 0] [:swap 16 0 0 0] [:switch 0 0 0 0]]})))) + +(t/deftest generated-switch-to-a-flipped-variant-stores-the-turn-its-transform-has + ;; a switch to a variant whose main is flipped keeps the copy's unflipped + ;; turn; the new head stores the rotation its transform decomposes into + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true + :layout nil :layout-item-margins false :grid-square false :library-depth 2 + :library true :rich-variants true :layout-children false :library-text true + :grid-empty false :layout-copies true :text true}] + :ops [[:library-transform 9 3 4 0] [:delete 5] [:restore 5] [:library-transform 9 4 0 0] + [:library-transform 4 3 0 0] [:library-sync 0 0 0 0] [:switch 13 0 0 0]]}))))