📎 Compare groups and bools and their shapes by corners in the harness

A bool's stored flip flags and transform drift apart, so neither sync
nor the model can read its orientation. The model and the oracle now
compare a group or bool, and the shapes it holds, by their corners in
any order, without their turn and flips, whether or not the authored
values record corners. Their corners are ordered by angle around their
centre: an order by position to the hundredth of a pixel swapped the
corners of an empty bool, 0.01 px wide, with float noise.

Resizing a copy bool after its main was flipped leaves settled and
fully synced files apart (F518, deferred until a bool keeps a reliable
orientation); the generator skips resizes of copy bools until then.

Tests: a-copy-bool-and-its-shapes-are-compared-by-their-corners,
an-empty-bool-in-a-copy-keeps-its-corners-in-one-order.

Harness only; the benchmark is not run.

Also in this commit:

- Leave a group's flip flags out of the harness undo check. Undoing a text style
  edit fits the group around the text again, and fitting a group clears its flip
  flags by design, though its corners and transform still show the flip. The
  undo check now leaves the flip flags of groups and bools out and compares
  their corners.
- Round corner angles before they wrap in the harness corner order. The harness
  orders the corners of groups, bools and their shapes by angle around their
  centre. A corner level with the centre, as in a square turned 45 degrees, fell
  at 0 or just under a full turn as noise fell, and its order flipped. Angles
  are now rounded before they wrap.
- Read the size of a bool from its selrect in the update main check. The harness
  check of an update main compared the sizes of the parent of a pushed shape by
  their width and height, and crashed when that parent was a bool, which has no
  width or height of its own. Sizes are read from the selrect.
- Order the corners of groups in the harness design snapshot. The settled and
  fully synced files of a bool made in a variant main whose copies are turned
  differed only by noise: up to 5e-6 px in the bool, which computes its geometry
  in single precision. But the design snapshot ordered only a bool's corners,
  not a group's, and the angle order, to the millionth of a radian, flipped a
  corner level with the bool's centre under that noise.
- Author no size for a swapped head a layout places in the harness. Switching a
  nested head in a filling grid copy to a wider variant grows the grid. The
  model took the grown copy for a sync resize and made the untouched swapped
  head author the size the resize gives it, though the layout sizes it, not its
  constraints. Heads a layout places are left out.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-13 05:04:03 +01:00
parent 8ed42aadac
commit e22ca8b7ce
6 changed files with 103 additions and 29 deletions

View File

@ -38,6 +38,7 @@
[app.common.geom.point :as gpt]
[app.common.math :as mth]
[app.common.test-helpers.composable.core :as tm]
[app.common.test-helpers.composable.geometry :as geom]
[app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.normalize :as thn]
[clojure.test :as t]
@ -170,10 +171,10 @@
#{} (constantly nil)))))))
(defn- corner-order
"The corners of a bool by their rounded position: a bool computes them
again from its children, in any order."
"The corners of a bool, which it computes again from its children in any
order (`geom/ordered-corners`)."
[points]
(sort-by (juxt #(Math/round (* 100.0 (:x %))) #(Math/round (* 100.0 (:y %)))) points))
(geom/ordered-corners points))
(defn same-state?
"Compare exact data with an absolute tolerance only in shape geometry.
@ -198,6 +199,10 @@
;; a bool computes its segments from its children, in an order
;; that depends on how it computed them; its children are compared
(and (= :content key) (= :bool (:type expected)) (contains? expected :parent-id))
;; fitting a group or bool to its children clears its flip flags,
;; which its transform and corners still show
(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))
corner-order)

View File

@ -814,13 +814,18 @@
(n/edit-grid target :cell (assoc (select-keys cell [:row :column]) :props props)))
(:transform :library-transform) (let [action (nth [:move :width :height :rotate :flip-x :flip-y]
(mod (or (nth tuple 2 nil) 0) 6))
value (or (nth tuple 3 nil) 0)]
(n/transform-shape target action
value (or (nth tuple 3 nil) 0)
shape (:shape selected)]
;; resizing a copy bool stays out until its
;; stored orientation is reliable (F518)
(when-not (and (#{:width :height} action)
(= :bool (:type shape)) (:shape-ref shape))
(n/transform-shape target action
(case action
:move [(* 5 (inc (mod value 4))) (* -3 (inc (mod value 3)))]
(:width :height) (+ 80 (* 20 (mod value 6)))
:rotate (* 45 (inc (mod value 4)))
nil)))
nil))))
:library-edit (n/change-property target property value)
:library-add-child (n/add-child target (keyword (str "library-generated-" (count (:applied situation))))
:width 20 :height 20 :x 10 :y 10)

View File

@ -173,3 +173,20 @@
(gsh/transform-shape child (gsh/calc-child-modifiers parent child modifiers false
(:points child) (:points parent)
(delay (:points resized))))))))
(defn ordered-corners
"The corners `points` of a group or bool, which keeps them in any order,
by their angle around their centre: it holds whatever the shape's size,
turn or noise, where an order by position swaps the corners of a tiny or
turned shape."
[points]
(when (seq points)
(let [cx (/ (reduce + (map :x points)) (count points))
cy (/ (reduce + (map :y points)) (count points))
;; angles to the ten-thousandth of a radian, rounded before they wrap,
;; so a corner level with the centre sorts first whichever side the
;; single precision noise of a bool puts it
turn (Math/round (* 2e4 Math/PI))]
(sort-by (fn [{:keys [x y]}]
(mod (Math/round (* 1e4 (Math/atan2 (- y cy) (- x cx)))) turn))
points))))

View File

@ -155,11 +155,6 @@
node))
content))
;; the order of a bool's corners: by position, to the hundredth of a pixel,
;; so noise in one coordinate does not swap two corners
(def ^:private corner-order
(juxt #(Math/round (* 100.0 (:x %))) #(Math/round (* 100.0 (:y %)))))
(defn- without-unreferenced-deleted
"The snapshot `files` without the deleted components no shape outside
their own objects refers to, as an undone creation: only redo brings one
@ -209,9 +204,9 @@
(and (= :path (:type value)) (some? (:content value))) (update :content #(into [] %))
;; a bool computes its segments from its children, which the design
;; holds, in an order that depends on how it was computed
(= :bool (:type value)) (-> (dissoc :content)
;; and its corners in their order
(update :points #(some->> % (sort-by corner-order) vec)))
(= :bool (:type value)) (dissoc :content)
;; a group or bool takes its corners from its children, in any order
(#{:group :bool} (:type value)) (update :points #(some-> % geom/ordered-corners vec))
;; the transform carries the turn, whichever rotation the shape
;; stores for it
:always (dissoc :rotation))
@ -550,10 +545,12 @@
(not= (boolean (:flip-y shape)) (boolean (:flip-y expected)))
(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))]
;; expected corners, its turn and flips say nothing more; nor do those
;; of its children, whose orientation it stores unreliably
in-group? (#{:group :bool} (:type (get objects (:parent-id ownership))))
derived (and (or (#{:group :bool} (:type shape)) in-group?)
(gsh/close-attrs? :points (geom/ordered-corners (:points shape))
(geom/ordered-corners (: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
@ -576,9 +573,9 @@
[(first (:points expected))] 0.01))) (conj :position)
(and (not layout-child) (not auto-width) (not auto-height)
;; a bool computes its corners from its segments, in their order
(not (if (= :bool (:type shape))
(gsh/close-attrs? :points (sort-by corner-order (:points shape))
(sort-by corner-order (:points expected)) 0.01)
(not (if (or (= :bool (:type shape)) in-group?)
(gsh/close-attrs? :points (geom/ordered-corners (:points shape))
(geom/ordered-corners (:points expected)) 0.01)
(gsh/close-attrs? :points (:points shape) (:points expected) 0.01)))) (conj :points)))))
(defn check-requested-geometry
@ -631,8 +628,9 @@
source (cond-> source
(and source-parent kept-parent
(= (:id source-parent) (:id kept-parent))
(mth/close? (:width source-parent) (:width kept-parent) 0.01)
(mth/close? (:height source-parent) (:height kept-parent) 0.01))
;; a bool has no size but its selrect's
(mth/close? (-> source-parent :selrect :width) (-> kept-parent :selrect :width) 0.01)
(mth/close? (-> source-parent :selrect :height) (-> kept-parent :selrect :height) 0.01))
(gsh/move (gpt/subtract (first (:points kept-parent))
(first (:points source-parent)))))
attrs (geometry-differences source-objects kept source source)]

View File

@ -193,13 +193,13 @@
;; 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)))
(or (nil? (:points expected))
(gsh/close-attrs? :points (geom/ordered-corners (:points shape))
(geom/ordered-corners (: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
oriented (when (and (not placed) (:transform shape) (geom/rigid? shape)
oriented (when (and (not placed) (not derived) (:transform shape) (geom/rigid? shape)
(number? (:rotation expected))
(contains? expected :flip-x) (contains? expected :flip-y))
(geom/decomposes? (merge shape (select-keys expected [:rotation :flip-x :flip-y]))))
@ -215,9 +215,17 @@
(update :rotation + 180))
expected)]
(and (if placed
;; a size the layout gives keeps the first corner
(if (seq sized)
(cond
;; a group or bool keeps its corners in any order
(#{:group :bool} (:type shape))
(gsh/close-attrs? :points (geom/ordered-corners (:points shape))
(geom/ordered-corners (:points placed)) 0.01)
;; a size the layout gives keeps the first corner
(seq sized)
(gsh/close-attrs? :points [(first (:points shape))] [(first (:points placed))] 0.01)
:else
(gsh/close-attrs? :points (:points shape) (:points placed) 0.01))
true)
(if (some? oriented) oriented true)
@ -678,6 +686,9 @@
(if (and (contains? groups :swap-group)
(not (contains? groups :geometry-group))
(resized? id)
;; a layout sizes and places its children, not their constraints
(not (and (ctl/any-layout-immediate-child? after shape)
(not (ctl/position-absolute? shape))))
(some? origin)
(:shape-ref origin)
(not (contains? (get model (:id origin)) :geometry-group)))

View File

@ -2535,6 +2535,44 @@
:layout-copies false :layout-children false}]
:ops [[:transform 0 5 0 3] [:structure 0 5] [:update-main]]}))))
(t/deftest an-empty-bool-in-a-copy-keeps-its-corners-in-one-order
(t/is (map? (cg/run {:world [3 1 {:variants true :rich-variants true :text true :layout nil
:layout-copies true :layout-children false}]
:ops [[:add-child 7] [:structure 0 0 0] [:add-child 7] [:structure 3 4 3] [:add-child 0]
[:structure 3 0 0] [:add-child 7] [:structure 7 5 7]]}))))
(t/deftest a-copy-bool-and-its-shapes-are-compared-by-their-corners
(t/is (map? (cg/run {:world [2 1 {:variants true :rich-variants true :text true :layout :flex
:layout-copies false :layout-children true}]
:ops [[:transform 6 17 0 9] [:add-child 16] [:structure] [:remove-child 11] [:structure 6 6]
[:update-main] [:transform 0 13 0 17]]}))))
(t/deftest undoing-a-text-style-refits-a-flipped-group-to-the-same-corners
(t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants true :text false :layout nil
:layout-copies false :layout-children false}]
:ops [[:delete] [:transform 0 22 0 18] [:structure 0 0 5] [:text-style 0 0 1]]}))))
(t/deftest a-turned-copy-shape-in-a-group-orders-a-corner-level-with-its-centre-once
(t/is (map? (cg/run {:world [1 1 {:variants true :rich-variants true :text true :layout :grid
:layout-copies true :layout-children true}]
:ops [[:add-child] [:structure 11 4 5] [:swap 6] [:rotate] [:style 8 11]]}))))
(t/deftest updating-a-main-from-a-shape-in-a-copy-bool-reads-the-bool-size
(t/is (map? (cg/run {:world [3 1 {:variants true :rich-variants false :text true :layout nil
:layout-copies false :layout-children false}]
:ops [[:add-child 5] [:remove-child] [:undo] [:add-child] [:structure 17] [:structure 16 7]
[:transform 18 0 0 17] [:update-main]]}))))
(t/deftest a-bool-made-in-a-variant-main-orders-the-corners-of-its-turned-copies
(t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout nil
:layout-copies false :layout-children false}]
:ops [[:rotate 12] [:swap 2] [:swap 19] [:add-child] [:structure] [:structure 3 5 21]]}))))
(t/deftest switching-a-head-a-grid-places-authors-no-size-when-the-grid-grows
(t/is (map? (cg/run {:world [1 1 {:variants true :rich-variants true :text true :layout :grid
:layout-copies true :layout-children false}]
:ops [[:style 8 29 1] [:nest 6] [:switch 9]]}))))
(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}]