🐛 Keep the geometry a shape in a copy group authors through sync

When a shape in a group of a copy authors a move or a resize, the
untouched group's bounds follow it. Sync moved or resized the group
back to its main's bounds and carried its whole subtree with it, so the
shape lost the geometry it authored.

A group or bool takes its bounds from its children, which sync places
one by one: a move or resize of its bounds now carries nothing, and the
group fits its children again. A turn or flip still carries the subtree.

Tests: syncing-a-copy-group-keeps-the-place-its-shape-authors,
syncing-a-copy-group-keeps-the-size-its-shape-authors,
undoing-a-turn-of-a-copy-group-gives-the-groups-of-its-copies-their-bounds-back.
The full common suite passes.

The benchmark of the previous commit covers this one.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-12 23:07:27 +01:00
parent 2abe61e181
commit 6a5aa99f79
2 changed files with 30 additions and 1 deletions

View File

@ -673,7 +673,19 @@
(not= (boolean (:flip-x before)) (boolean (:flip-x after)))
(not= (boolean (:flip-y before)) (boolean (:flip-y after)))))
ids (when changed? (cfh/get-children-ids (:objects container) (:id before)))]
(if (seq ids)
(cond
;; a group or bool takes its bounds from its children, which sync places
;; one by one: a move or resize of its bounds carries nothing, and it
;; fits them again
(and (seq ids) (or moved? resized?)
(mth/close? (or (:rotation before) 0) (or (:rotation after) 0) 1e-10)
(= (boolean (:flip-x before)) (boolean (:flip-x after)))
(= (boolean (:flip-y before)) (boolean (:flip-y after)))
(#{:group :bool} (:type before)))
(let [refit {:type :reg-objects :shapes [(:id before)]}]
(pcb/add-changes changes container [refit] [refit]))
(seq ids)
(let [orientation (fn [shape]
(let [matrix (axes-matrix shape)]
(assoc shape :transform matrix :transform-inverse (gmt/inverse matrix))))
@ -704,6 +716,8 @@
(update :touched ctk/set-touched-group :geometry-group))
#(cond-> % (some? turn) turn :always (gsh/move delta)))
{:ignore-touched true}))
:else
changes)))
(defn- constraint-sized-main

View File

@ -2477,6 +2477,21 @@
:layout-copies false :layout-children true}]
:ops [[:add-child 5] [:structure 12] [:transform 12 10 0 12]]}))))
(t/deftest syncing-a-copy-group-keeps-the-place-its-shape-authors
(t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants false :text false :layout :grid
:layout-copies false :layout-children false}]
:ops [[:add-child 1] [:structure 2] [:transform 2 0 0 2]]}))))
(t/deftest syncing-a-copy-group-keeps-the-size-its-shape-authors
(t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants false :text false :layout :grid
:layout-copies false :layout-children false}]
:ops [[:add-child 1] [:structure 2] [:transform 2 2 0 2]]}))))
(t/deftest undoing-a-turn-of-a-copy-group-gives-the-groups-of-its-copies-their-bounds-back
(t/is (map? (cg/run {:world [2 2 {:variants true :rich-variants true :text true :layout nil
:layout-copies false :layout-children false}]
:ops [[:add-child 7] [:add-child 7] [:structure 13] [:transform 10 15 0 12]]}))))
(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}]