📎 Compare the corners of a bool in any order when checking undo

A bool computes its corners again from its shapes, so the same bounds can
come back in another order: undoing an edit left two flipped copy bools
with their corners listed the other way round, and the undo check took it
for a change. The undo check now compares a bool's corners in any order,
as the oracle already does.

Test: undoing-an-edit-compares-the-corners-of-a-copy-bool-in-any-order
(a shape structure program of seed 489).
Harness only; the benchmark is not run.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-12 12:29:47 +01:00
parent 17539d9f0e
commit a1339154cb
2 changed files with 18 additions and 1 deletions

View File

@ -169,6 +169,12 @@
(into (entities-signature :component (:components ed) (:components ad)
#{} (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."
[points]
(sort-by (juxt #(Math/round (* 100.0 (:x %))) #(Math/round (* 100.0 (:y %)))) points))
(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."
@ -188,7 +194,12 @@
(and (map? expected) (map? actual) (= (set (keys expected)) (set (keys actual))))
(every? (fn [key]
(same-state? (get expected key) (get actual key)
(same-state? (cond-> (get expected key)
(and (= :points key) (= :bool (:type expected)) (contains? expected :parent-id))
corner-order)
(cond-> (get actual key)
(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)))

View File

@ -2360,6 +2360,12 @@
:grid-empty false :layout-copies false :text false}]
:ops [[:nest 4] [:resize 1] [:style 15 9 3]]}))))
(t/deftest undoing-an-edit-compares-the-corners-of-a-copy-bool-in-any-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 [[:detach 0 0 0 0] [:detach 14 0 0 0] [:add-child 0] [:structure 9 4 0]
[:transform 7 16 0 4] [:edit 21 0 1 1] [:update-main 21]]}))))
(t/deftest unmasking-in-a-flex-main-leaves-its-layout-as-the-unmask-event-does
(t/is (map? (cg/run {:world [2 0 {:variants false :rich-variants false :text true :layout :flex
:layout-copies false :layout-children true}]