📎 Size the shapes of a group a layout sizes in the harness oracle

A copy bool set to fill in a grid cell is sized by the grid, and its
shapes scale with it. The oracle expected them at their main's size and
place. The shapes of a group or bool whose size a layout owns are now
sized and placed by that layout too.

Test: the-shapes-of-a-copy-bool-a-grid-fills-are-sized-with-it; shape
structure programs pass (seed 9008, 300).

Harness only; the benchmark is not run.

Also in this commit:

- Compare the corners of a masked group in any order on undo. A masked group
  takes the corners of its mask. When the mask is a bool, a sync that refits it
  computes them again from its children in any order, and the undo of that sync
  refits it the same way. The undo check already compares the corners of a bool
  in any order; a masked group now follows its mask.
- Read the size of a copy path from its bounds in the harness model. A path
  stores no width or height, so the model saw no change when a copy path that a
  layout places was resized: its place is the layout's and its size values stay
  nil. The model now reads a size change of a shape with no width from its
  bounds, and expects the resize to mark it.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-13 17:35:08 +01:00
parent 07384e599e
commit 6eff483b22
4 changed files with 45 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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