diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 824a459bea..3f74b75daa 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -522,9 +522,10 @@ (let [objects (pcb/get-objects changes) resized? (fn [id] (let [old (get before id) shape (get objects id)] + ;; sizes are pixels: a hundredth of one is float noise (and old shape - (not (and (mth/close? (-> old :selrect :width) (-> shape :selrect :width)) - (mth/close? (-> old :selrect :height) (-> shape :selrect :height))))))) + (not (and (mth/close? (-> old :selrect :width) (-> shape :selrect :width) 0.01) + (mth/close? (-> old :selrect :height) (-> shape :selrect :height) 0.01)))))) heads (into [] (comp (filter #(and (:shape-ref (get objects %)) (resized? %))) (mapcat #(cfh/get-children-ids objects %)) @@ -636,14 +637,16 @@ (declare flips) (defn- close-geometry? - "Whether `shape` and `other` have the same geometry: a bool keeps its - corners in one order whatever its flips, so they count too." - [shape other] - (and (gsh/close-attrs? :selrect (:selrect shape) (:selrect other)) - (gsh/close-attrs? :points (:points shape) (:points other)) - (mth/close? (:content-scale shape 1) (:content-scale other 1)) - (or (not (#{:group :bool} (:type shape))) - (= (flips shape) (flips other))))) + "Whether `shape` and `other` have the same geometry, within `precision`: + a bool keeps its corners in one order whatever its flips, so they count + too." + ([shape other] (close-geometry? shape other mth/float-equal-precision)) + ([shape other precision] + (and (gsh/close-attrs? :selrect (:selrect shape) (:selrect other) precision) + (gsh/close-attrs? :points (:points shape) (:points other) precision) + (mth/close? (:content-scale shape 1) (:content-scale other 1)) + (or (not (#{:group :bool} (:type shape))) + (= (flips shape) (flips other)))))) (defn- authored-constraints "The constraints that the copy shapes `ids` author, by the id of the main @@ -2267,8 +2270,9 @@ ([shape main main-parent parent sized] (let [main-parent (when-not (cfh/root? main-parent) main-parent) flip? (fn [key] (odd? (count (filter key [main main-parent parent]))))] - (and (or (contains? sized :width) (mth/close? (-> shape :selrect :width) (-> main :selrect :width))) - (or (contains? sized :height) (mth/close? (-> shape :selrect :height) (-> main :selrect :height))) + ;; sizes are pixels: a hundredth of one is float noise + (and (or (contains? sized :width) (mth/close? (-> shape :selrect :width) (-> main :selrect :width) 0.01)) + (or (contains? sized :height) (mth/close? (-> shape :selrect :height) (-> main :selrect :height) 0.01)) (gmt/close? (axes-matrix shape) (gmt/multiply (axes-matrix parent) (gmt/inverse (axes-matrix main-parent)) @@ -2324,9 +2328,11 @@ (not (#{:group :bool} (:type shape))) (if (and (some? (:shape-ref parent)) (not layout-placed?)) (and (some? main-parent) + ;; a place a hundredth of a pixel away is float noise (not (close-geometry? shape (get (placed-like main-objects main-parent parent (authored-constraints objects [id])) - (:id main))))) + (:id main)) + 0.01))) (not (turned-like-parent? shape main main-parent parent (if layout-placed? (layout-sized objects shape) #{}))))) (pcb/update-shapes changes [id] #(update % :touched ctk/set-touched-group :geometry-group) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 16e0c1e4da..543983921e 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -705,9 +705,10 @@ size authors that size, placed in its parent. The resize starts at the topmost resized ancestor of the head." [model before after] - (let [sized-alike? #(let [a (geom/boxed %1) b (geom/boxed %2)] - (and (mth/close? (:width a) (:width b)) - (mth/close? (:height a) (:height b)))) + (let [;; sizes are pixels: a hundredth of one is float noise + sized-alike? #(let [a (geom/boxed %1) b (geom/boxed %2)] + (and (mth/close? (:width a) (:width b) 0.01) + (mth/close? (:height a) (:height b) 0.01))) ;; whether `id` keeps its parent and has another size in `after` resized? (fn [id] (let [old (get before id) shape (get after id)] diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 4b2596d87e..550935de91 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4542,3 +4542,8 @@ :ops [[:style 1 1 1 0] [:add-child 0] [:structure 0 0 0] [:add-child 0] [:structure 1 4 0] [:transform 1 1 0 1]]})))) +(t/deftest generated-a-detach-authors-no-geometry-for-float-noise + ;; after a turn and a fill resize, the nested copies a detach advances sit + ;; a few thousandths of a pixel from their new mains' places: no override + (t/is (map? (cg/run {:world [3 2 {:variants true :layout :grid :rich-variants true :grid-empty true :layout-copies true :text true}] :ops [[:nest 7 2 4 2] [:rotate 6 2 4 1] [:duplicate 1 3 1 0] [:make-variant 2] [:duplicate 8 2 8 6] [:style 2 29 1] [:detach 8 6 8 2]]})))) +