📎 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
This commit is contained in:
alonso.torres 2026-11-12 13:58:54 +01:00
parent 3d1ea0b599
commit bc5eb3f15c
4 changed files with 44 additions and 6 deletions

View File

@ -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?

View File

@ -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)

View File

@ -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

View File

@ -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)]