📎 Place a group's shapes from its board when the harness orients them

Flipping the mask of a mask group in a copy makes the group follow it.
The model applied the mask's change twice, as the modifier tree passes
a mask's change to its group and back, and when the group's orientation
changed it placed the mask's authored geometry in the group, whose
bounds come from that mask, halving it.

The requested geometry of a group's mask applies its change once, and
authored geometry under a group or bool follows the board around it
when its parent's orientation changes, as elsewhere in the model.

Test: flipping-the-mask-of-a-copy-group-flips-the-group-for-good;
shape structure programs pass (seed 9002, 300).

Harness only; the benchmark is not run.

Also in this commit:

- Compare a bool by its children, not its segments, when checking undo. Undoing
  an update main that pushed a flip into a main holding a bool gives the bool
  back the same rectangle with its segments drawn the other way round. A bool
  computes its segments from its children, in an order that depends on how it
  computed them.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-13 02:25:58 +01:00
parent 8c2ef98bb2
commit fa1edc78bd
4 changed files with 27 additions and 6 deletions

View File

@ -194,7 +194,11 @@
(and (map? expected) (map? actual) (= (set (keys expected)) (set (keys actual))))
(every? (fn [key]
(same-state? (cond-> (get expected key)
(or
;; 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))
(same-state? (cond-> (get expected key)
(and (= :points key) (= :bool (:type expected)) (contains? expected :parent-id))
corner-order)
(cond-> (get actual key)
@ -210,7 +214,7 @@
(or (contains? #{:x :y :width :height :rotation :points
:selrect :transform :transform-inverse} key)
;; the segments of a bool or path are its geometry
(and (= :content key) (#{:bool :path} (:type expected))))))))
(and (= :content key) (#{:bool :path} (:type expected)))))))))
(keys expected))
(and (sequential? expected) (sequential? actual) (= (count expected) (count actual)))

View File

@ -1030,8 +1030,12 @@
:resize (ctm/change-size shape nil (:value op))
:rotate (n/geometry-modifiers shape :rotate (:angle op))
(:transform :library-transform) (n/geometry-modifiers shape (:action op) (:value op)))
tree (gm/set-objects-modifiers {(:id shape) {:modifiers modifiers}} objects)]
(gsh/transform-shape shape (get-in tree [(:id shape) :modifiers]))))
parent (get objects (:parent-id shape))
;; the mask of a group passes its change to the group and back, so
;; the tree would apply it twice; only its group places it
mask? (and (:masked-group parent) (= (:id shape) (first (:shapes parent))))
tree (when-not mask? (gm/set-objects-modifiers {(:id shape) {:modifiers modifiers}} objects))]
(gsh/transform-shape shape (if mask? modifiers (get-in tree [(:id shape) :modifiers])))))
(defn- kind-file
"The file an operation edits: the library `library-id`, or the current one."

View File

@ -628,8 +628,16 @@
(fn [result id groups]
(let [old (get before id)
shape (get after id)
parent (get before (:parent-id old))
new-parent (get after (:parent-id shape))]
;; a group or bool takes its bounds and turn from its children,
;; so they take their place from the board around it
board (fn [objects shape]
(let [parent (get objects (:parent-id shape))
frame (get objects (:frame-id shape))]
(if (and (#{:group :bool} (:type parent)) (not (ctl/any-layout? frame)))
frame
parent)))
parent (when old (board before old))
new-parent (when shape (board after shape))]
(if (and (:geometry-group groups) old shape
(= (:parent-id old) (:parent-id shape)) parent new-parent)
(if-let [expected (authored-placement (:geometry-group groups) new-parent)]

View File

@ -2530,6 +2530,11 @@
:ops [[:remove-child 9] [:add-child 7] [:delete 7] [:add-child] [:undo]
[:structure 10 1] [:transform 10 5 0 2]]}))))
(t/deftest undoing-an-update-main-compares-a-bool-by-its-children-not-its-segments
(t/is (map? (cg/run {:world [1 1 {:variants false :rich-variants false :text false :layout nil
:layout-copies false :layout-children false}]
:ops [[:transform 0 5 0 3] [:structure 0 5] [:update-main]]}))))
(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}]