diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index bc492ddf17..53e5a918ff 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -418,21 +418,26 @@ #{:x :y :width :height :selrect :points :transform :transform-inverse :rotation :flip-x :flip-y :content-scale}) -(defn- same-footprint? - "Whether two shapes cover the same corners, in any order." +(defn- same-placement? + "Whether two shapes cover the same corners with the same transform, so + they differ at most in how rotation and flips decompose it." [shape other] - (let [corners (:points other)] + (let [corners (:points other) + transform (or (:transform shape) (gmt/matrix)) + other-tf (or (:transform other) (gmt/matrix))] (and (= (count (:points shape)) (count corners)) - (every? (fn [point] (some #(gpt/close? point %) corners)) (:points shape))))) + (every? (fn [point] (some #(gpt/close? point %) corners)) (:points shape)) + (every? #(mth/close? (get transform %) (get other-tf %)) [:a :b :c :d])))) (defn generate-sync-transformed-placement "Settle copy descendants after a reflection and untouched swapped heads after a parent turn, in the transform's change group. Reflection can leave descendant flip flags in another decomposition, so it only - re-decomposes shapes that keep their footprint; swapped content can have - a different size from its position frame. Keep this correction within - existing geometry: transforming a stale library copy must not accept - pending content, style, size or structural changes." + re-decomposes shapes whose corners and transform it keeps; swapped + content can have a different size from its position frame. Keep this + correction within existing geometry: transforming a stale library copy + must not accept pending content, style, size, flip or structural + changes." [changes file libraries page before ids] (let [objects (pcb/get-objects changes) orientation (fn [shape] @@ -474,7 +479,7 @@ attrs (cond-> placement-geometry-attrs (= :path (:type shape)) (conj :content))] (if (and (= (:type shape) (:type expected)) - (or resize? (same-footprint? shape expected))) + (or resize? (same-placement? shape expected))) (merge shape (select-keys expected attrs)) shape))) {:ignore-touched true}))) diff --git a/common/test/common_tests/logic/source_gen_test.cljc b/common/test/common_tests/logic/source_gen_test.cljc index 5cf1a7e165..287f791e55 100644 --- a/common/test/common_tests/logic/source_gen_test.cljc +++ b/common/test/common_tests/logic/source_gen_test.cljc @@ -6,11 +6,15 @@ (ns common-tests.logic.source-gen-test (:require + [app.common.test-helpers.composable.comp.files :as cf] [app.common.test-helpers.composable.comp.runner :as r] [app.common.test-helpers.composable.core :as tm] [app.common.test-helpers.composable.gen :as cg] [app.common.test-helpers.composable.oracle :as oracle] + [app.common.test-helpers.files :as thf] [app.common.test-helpers.ids-map :as thi] + [app.common.test-helpers.shapes :as ths] + [app.common.test-helpers.texts :as thtx] [clojure.test :as t])) (t/use-fixtures :each thi/test-fixture) @@ -35,6 +39,14 @@ :ops [[:library-transform 3 1 4 0] [:library-transform 0 4 4 0] [:library-undo] [:library-redo]]})))) +(t/deftest a-reflection-does-not-accept-a-pending-library-flip + ;; The dependent main nests a copy whose child the source flipped; the + ;; dependent library has not accepted that flip. + (t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true + :library-dependency true :library-text true}] + :ops [[:library-remove-child 0 0 0 0] [:library-transform 0 4 4 1] + [:library-transform 0 4 4 0] [:library-undo] [:library-redo]]})))) + (t/deftest source-transforms-keep-consumers-stale-until-acceptance (doseq [action (range 6) scope [0 1]] (let [initial (cg/initial-state source-world)