🐛 Author the size a sync resize gives a swapped head

When sync resizes a copy parent, sync-descendant-orientation places its
subtree through constraints, which scales an untouched swapped head with
a scale constraint. Update-swapped-placement then only moves the head, so
a later sync of every component gave it back the size of its own main:
the result depended on the order of the syncs. Sync cannot tell a main
change from a reset of a copy sized apart from its main, which must scale
the head back (#12716), as it never sees the main's earlier size. The
resize now marks the geometry group of an untouched swapped head it gives
another size, so later syncs keep that size. The composable model records
the same: a swapped head without authored geometry whose copy parent and
own size both change in a step authors its new geometry in that parent.

Test: syncing-a-resized-copy-parent-authors-the-size-it-gives-a-swapped-
head (the variant gate program of round 16, seed 212451915).
Common suite: 2441 tests, 0 failures.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):
|                             :world | :baseline |    :now |   :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |  21.568 |   22.51 |   0.61 |
| edit-through-a-chain-of-dependents |    68.931 |  42.762 |  46.833 |   0.62 |
|         library-update-into-copies |    83.083 |  52.439 |  55.324 |   0.63 |
|        main-edit-among-many-shapes |     4.837 |   2.443 |   2.762 |   0.51 |
|           main-edit-into-10-copies |      1.79 |   1.124 |   1.217 |   0.63 |
|          main-edit-into-100-copies |    15.415 |  10.254 |  11.046 |   0.67 |
|         main-edit-into-1000-copies |   153.086 | 103.629 | 107.266 |   0.68 |
|         variant-switch-into-copies |    32.052 |  22.861 |  23.944 |   0.71 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 16:12:27 +01:00
parent 67484aff60
commit 230dc0b4c2
2 changed files with 24 additions and 3 deletions

View File

@ -657,7 +657,8 @@
"A parent turned or moved by sync carries its whole subtree, including
geometry overrides. Resize remains the job of constraints, not matrix
scale: a parent turned and resized at once resizes its subtree through
their constraints first, then turns and moves it as one piece."
their constraints first, then turns and moves it as one piece. A swapped
head the resize gives another size authors that size."
[changes container before]
(let [after (get (pcb/get-objects changes) (:id before))
resized? (and after
@ -684,10 +685,23 @@
(let [objects (pcb/get-objects changes)
parent (cond-> (merge after (select-keys before placement-geometry-attrs))
(ctsl/grid-layout? after) (ctsl/assign-cells objects))]
(placed-like (assoc objects (:id before) parent) before after {})))]
(placed-like (assoc objects (:id before) parent) before after {})))
;; untouched swapped heads the resize gives another size
scaled (when resized?
(into #{}
(filter #(let [shape (get (:objects container) %)
moved (get placed %)]
(and (ctk/swapped? shape)
(not (ctk/touched-group? shape :geometry-group))
(some? moved)
(not (and (mth/close? (:width shape) (:width moved))
(mth/close? (:height shape) (:height moved)))))))
ids))]
(pcb/update-shapes changes ids
(if resized?
#(get placed (:id %) %)
#(cond-> (get placed (:id %) %)
(contains? scaled (:id %))
(update :touched ctk/set-touched-group :geometry-group))
#(cond-> % (some? turn) turn :always (gsh/move delta)))
{:ignore-touched true}))
changes)))

View File

@ -2282,6 +2282,13 @@
[:transform 3 9 7 13] [:switch] [:undo] [:update-main 1] [:duplicate 2]
[:update-main 15] [:switch]]}))))
(t/deftest syncing-a-resized-copy-parent-authors-the-size-it-gives-a-swapped-head
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout :grid :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies false :text false}]
:ops [[:add-variant 15] [:duplicate 10] [:make-variant 8] [:switch 15] [:style 21 9 1]
[:update-main] [:duplicate 16] [:resize 16]]}))))
(t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false
:layout-item-margins false :grid-square true :rich-variants false