diff --git a/common/src/app/common/test_helpers/composable/comp/undo_check.cljc b/common/src/app/common/test_helpers/composable/comp/undo_check.cljc index ca913497ed..4a133aca5c 100644 --- a/common/src/app/common/test_helpers/composable/comp/undo_check.cljc +++ b/common/src/app/common/test_helpers/composable/comp/undo_check.cljc @@ -176,6 +176,13 @@ [points] (geom/ordered-corners points)) +(defn- any-corner-order? + "Whether the corners of `shape` are compared in any order: a bool computes + them again from its children, and a masked group takes those of its mask." + [shape] + (and (contains? shape :parent-id) + (or (= :bool (:type shape)) (:masked-group shape)))) + (defn same-state? "Compare exact data with an absolute tolerance only in shape geometry. Undo defaults to 1e-10; design equivalence can supply its own tolerance." @@ -204,10 +211,10 @@ (and (#{:flip-x :flip-y} key) (#{:group :bool} (:type expected)) (contains? expected :parent-id)) (same-state? (cond-> (get expected key) - (and (= :points key) (= :bool (:type expected)) (contains? expected :parent-id)) + (and (= :points key) (any-corner-order? expected)) corner-order) (cond-> (get actual key) - (and (= :points key) (= :bool (:type expected)) (contains? expected :parent-id)) + (and (= :points key) (any-corner-order? expected)) corner-order) ;; a bool or path stores its segments in single precision, and ;; a bool or group computes its bounds again from its children diff --git a/common/src/app/common/test_helpers/composable/gen.cljc b/common/src/app/common/test_helpers/composable/gen.cljc index 714e82e073..7be4c6cace 100644 --- a/common/src/app/common/test_helpers/composable/gen.cljc +++ b/common/src/app/common/test_helpers/composable/gen.cljc @@ -1127,7 +1127,11 @@ changed? (or (not (shadow/same-value? shape-after group (shadow/values shape group))) ;; a stored turn may read the same under one flip while the transform turns (not (gmt/close? (or (:transform shape) (gmt/matrix)) (or (:transform shape-after) (gmt/matrix)))) - (and position? (not (gsh/close-attrs? :points (:points shape) (:points shape-after) 1e-10))))] + (and position? (not (gsh/close-attrs? :points (:points shape) (:points shape-after) 1e-10))) + ;; a path stores no width or height: its size is that of its bounds + (and (nil? (:width shape)) + (not (and (mth/close? (:width (:selrect shape)) (:width (:selrect shape-after)) 1e-10) + (mth/close? (:height (:selrect shape)) (:height (:selrect shape-after)) 1e-10)))))] (if (and (:shape-ref shape) changed?) (assoc-in model [id group] (shadow/author-geometry shape-after origin (not position?))) model)) diff --git a/common/src/app/common/test_helpers/composable/oracle.cljc b/common/src/app/common/test_helpers/composable/oracle.cljc index 8c12cdb919..86f39ba6d3 100644 --- a/common/src/app/common/test_helpers/composable/oracle.cljc +++ b/common/src/app/common/test_helpers/composable/oracle.cljc @@ -106,8 +106,12 @@ (or (not (mth/close? (mod (or (:rotation shape) 0) 360) 0)) (not (mth/close? (or b 0) 0 1e-6)) (not (mth/close? (or c 0) 0 1e-6)))) - width-owned (or width-owned turned) - height-owned (or height-owned turned)] + ;; the shapes of a group or bool a layout sizes are sized with it + parent (get objects (:parent-id shape)) + sized-by-parent (when (#{:group :bool} (:type parent)) + (derived-attributes objects parent)) + width-owned (or width-owned turned (contains? sized-by-parent :width)) + height-owned (or height-owned turned (contains? sized-by-parent :height))] (cond-> #{} layout-child (into #{:x :y}) width-owned (conj :width) @@ -537,6 +541,10 @@ auto-width (and (= :text (:type ownership)) (= :auto-width (:grow-type ownership))) auto-height (and (= :text (:type ownership)) (#{:auto-width :auto-height} (:grow-type ownership))) derived (derived-attributes objects ownership) + ;; a layout that sizes the group or bool around the shape places it too + group-sized (let [parent (get objects (:parent-id ownership))] + (and (#{:group :bool} (:type parent)) + (some #{:width :height} (derived-attributes objects parent)))) width-owned (contains? derived :width) height-owned (contains? derived :height) ;; Both flags and a half turn decompose the transform neither does. @@ -571,7 +579,7 @@ (and (not layout-child) auto-height (not (gsh/close-attrs? :points [(first (:points shape))] [(first (:points expected))] 0.01))) (conj :position) - (and (not layout-child) (not auto-width) (not auto-height) + (and (not layout-child) (not auto-width) (not auto-height) (not group-sized) ;; a bool computes its corners from its segments, in their order (not (if (or (= :bool (:type shape)) in-group?) (gsh/close-attrs? :points (geom/ordered-corners (:points shape)) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 11521f0545..c5379ae727 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2624,6 +2624,12 @@ :layout-children false :grid-empty false :layout-copies true :text true}] :ops [[:rotate 7 0 0 0] [:update-main 0 0 0 0] [:make-variant 19 0 0 0] [:style 0 29 4 0]]})))) +(t/deftest the-shapes-of-a-copy-bool-a-grid-fills-are-sized-with-it + (t/is (map? (cg/run {:world [1 1 {:variants true :rich-variants true :text false :layout :grid + :layout-copies false :layout-children true}] + :ops [[:add-child] [:structure] [:swap 5] [:add-child] [:add-child] [:structure 6 4 5] + [:style 0 29 1]]})))) + (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}] @@ -4189,3 +4195,17 @@ :ops [[:detach 1 0 0 0] [:resize 0 0 0 0] [:nest 0 0 0 0] [:duplicate 0 0 0 0] [:duplicate 0 0 0 0] [:detach 2 0 0 0] [:style 3 9 1] [:rotate 6 0 0 0] [:detach 12 0 0 0]]})))) + +(t/deftest generated-undo-compares-the-corners-of-a-bool-masked-group-in-any-order + ;; a masked group takes the corners of its mask, which a bool computes + ;; again from its children in any order when a sync refits it + (t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants true :text false :layout :flex + :layout-copies false :layout-children false}] + :ops [[:transform 0 4 0 3] [:structure] [:add-child 1] [:structure] [:structure 4 4] + [:add-child] [:structure 4 1] [:delete] [:structure 2 7 5]]})))) + +(t/deftest generated-resizing-a-copy-path-a-layout-places-authors-its-size + ;; a path stores no width or height, so its size is read from its bounds + (t/is (map? (cg/run {:world [1 1 {:variants true :rich-variants true :text false :layout :flex + :layout-copies false :layout-children true}] + :ops [[:add-child] [:add-child] [:structure 7 8] [:transform 10 20 0 17]]}))))