From bc5eb3f15c94059b0374113faf538c526ea7ab5d Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 12 Nov 2026 13:58:54 +0100 Subject: [PATCH] :paperclip: Read groups and bools in copies by their corners and their board A group or bool takes its corners from its children, so its stored turn and flips say nothing its corners do not: the oracle failed a copy group whose main turned for a flip flag at its expected corners. It no longer compares a group's or bool's turn and flips once its corners match. And the oracle placed a copy child of a bool from the bool's stored transform, which need not carry the bool's flip; it now places children of groups and bools from the board around them, as the snapshot measures them. Tests (programs of the shape structure property): a-copy-group-whose-main-turns-matches-its-corners-whatever-its-flips; a-copy-shape-in-a-bool-takes-its-place-from-its-board-when-the-main-flips. Harness only; the benchmark is not run. Also in this commit: - Allow a group's recomputed bounds the bool tolerance when checking undo. A group computes its bounds again from its children, as a bool does: undoing an unmask gave a turned mask group 0.01 high its bounds back about 1e-6 apart, beyond the undo check's 1e-10. A group now takes the 1e-4 tolerance of bools and paths. AI-assisted-by: claude-opus-5-5 --- .../composable/comp/undo_check.cljc | 4 ++-- .../test_helpers/composable/oracle.cljc | 21 +++++++++++++++---- .../test_helpers/composable/shadow.cljc | 7 +++++++ .../logic/composable_gen_test.cljc | 18 ++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) 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 1cd2e765fc..e267337d4c 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 @@ -201,8 +201,8 @@ (and (= :points key) (= :bool (:type expected)) (contains? expected :parent-id)) corner-order) ;; a bool or path stores its segments in single precision, and - ;; a bool computes them again from its children - (if (and (contains? expected :parent-id) (#{:bool :path} (:type expected))) + ;; a bool or group computes its bounds again from its children + (if (and (contains? expected :parent-id) (#{:bool :path :group} (:type expected))) (max tolerance 1e-4) tolerance) (or geometry? diff --git a/common/src/app/common/test_helpers/composable/oracle.cljc b/common/src/app/common/test_helpers/composable/oracle.cljc index 1afb2da266..530459cdd5 100644 --- a/common/src/app/common/test_helpers/composable/oracle.cljc +++ b/common/src/app/common/test_helpers/composable/oracle.cljc @@ -405,6 +405,13 @@ (update (:id main) merge (d/without-nils (select-keys shape [:constraints-h :constraints-v])))) main-parent (get main-objects (:parent-id main)) + ;; a group or bool takes its bounds and turn from its children, + ;; so they take their place from the board around it + board? (and (#{:group :bool} (:type parent)) main-parent + (#{:group :bool} (:type main-parent)) + (not (ctl/any-layout? (get objects (:frame-id shape))))) + parent (if board? (get objects (:frame-id shape)) parent) + main-parent (if board? (get main-objects (:frame-id main)) main-parent) ;; a reset refreshes its subtree from the loaded library while ;; the parent keeps the version it accepted, which may lack a turn; ;; a swapped parent holds the child in the main of its content @@ -509,20 +516,26 @@ same-corners? (gsh/close-attrs? :points (:points shape) (:points expected) 0.01) both-flipped (and (not= (boolean (:flip-x shape)) (boolean (:flip-x expected))) (not= (boolean (:flip-y shape)) (boolean (:flip-y expected))) - (geom/decomposes? shape))] + (geom/decomposes? shape)) + ;; a group or bool takes its corners from its children: at its + ;; expected corners, its turn and flips say nothing more + derived (and (#{:group :bool} (:type shape)) + (gsh/close-attrs? :points (sort-by corner-order (:points shape)) + (sort-by corner-order (:points expected)) 0.01))] (cond-> #{} ;; Parents may store equivalent decompositions, so a rotation that ;; decomposes the shape's own transform is its expected turn too, as ;; is any rotation of a shape at its expected corners. - (not (or (same-turn? rotation exp-rotation) + (not (or derived + (same-turn? rotation exp-rotation) (and mirrored (same-turn? rotation (- exp-rotation))) (geom/decomposes? shape) (gsh/close-attrs? :points (:points shape) (:points expected) 0.01))) (conj :rotation) ;; ordered corners that match fix the transform, so flags that decompose ;; it store the same transform otherwise - (and (not both-flipped) (not= (boolean (:flip-x shape)) (boolean (:flip-x expected))) + (and (not both-flipped) (not derived) (not= (boolean (:flip-x shape)) (boolean (:flip-x expected))) (not (and same-corners? (geom/decomposes? shape)))) (conj :flip-x) - (and (not both-flipped) (not= (boolean (:flip-y shape)) (boolean (:flip-y expected))) + (and (not both-flipped) (not derived) (not= (boolean (:flip-y shape)) (boolean (:flip-y expected))) (not (and same-corners? (geom/decomposes? shape)))) (conj :flip-y) (and (not width-owned) (not (mth/close? (:width shape) (:width expected) 0.01))) (conj :width) (and (not height-owned) (not (mth/close? (:height shape) (:height expected) 0.01))) (conj :height) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 7bad2dca15..8478138fcd 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -186,6 +186,12 @@ parent) placed (when (and objects (not (:sized? (::position (meta expected))))) (authored-placement expected parent shape)) + ;; a group or bool takes its corners from its children: at its + ;; expected corners, its turn and flips say nothing more + derived (and (#{:group :bool} (:type shape)) + (let [order (partial sort-by (juxt #(Math/round (* 100.0 (:x %))) + #(Math/round (* 100.0 (:y %)))))] + (gsh/close-attrs? :points (order (:points shape)) (order (:points expected)) 0.01))) ;; an unskewed transform carries the turn and the mirror: an ;; expected rotation and flips match when they decompose it, ;; whichever rotation and flips the shape stores for it @@ -215,6 +221,7 @@ (let [actual (get shape key)] (cond (contains? sized key) true + (and derived (#{:rotation :flip-x :flip-y} key)) true (and (some? oriented) (#{:rotation :flip-x :flip-y} key)) true ;; ordered corners fix the transform, whichever ;; rotation the shape stores for it diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 7eacbb786b..367f4c6f56 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2449,6 +2449,24 @@ :ops [[:rotate 16 0 7 0] [:grid-direction 0 0 0 1] [:grid-cell 0 10 0 1] [:add-child 0] [:structure 3 6 15] [:grid-direction 0 0 0 1] [:grid-cell 0 4 2 1]]})))) +(t/deftest a-copy-group-whose-main-turns-matches-its-corners-whatever-its-flips + (t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout nil + :layout-copies true :layout-children false}] + :ops [[:transform 16 4 0 0] [:add-child 0] [:structure 2 0 0] [:rotate 0 0 0 0]]})))) + +(t/deftest a-copy-shape-in-a-bool-takes-its-place-from-its-board-when-the-main-flips + (t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout nil + :layout-copies true :layout-children false}] + :ops [[:resize 5 0 0 0] [:add-child 0] [:structure 0 0 0] [:add-child 0] [:structure 8 4 0] + [:delete 8 0 0 0] [:delete 3] [:restore 3] [:transform 9 4 0 0]]})))) + +(t/deftest undoing-an-unmask-restores-a-turned-mask-within-the-bounds-tolerance + (t/is (map? (cg/run {:world [2 1 {:variants true :rich-variants true :text true :layout nil + :layout-copies true :layout-children false}] + :ops [[:add-child 0 0 0 0] [:add-child 0] [:structure 0 0 0] [:add-child 0] [:structure 0 0 0] + [:add-child 0 0 0 0] [:add-child 0] [:structure 14 1 0] [:rotate 15 0 0 0] + [:add-child 0] [:structure 0 3 0]]})))) + (t/deftest random-shape-structure-compositions (let [coverage (atom {}) failure (atom nil)]