🐛 Keep the geometry of a swapped shape a pushed swap carries

An update main that pushes a copy's swap into a copy inside the main
places the pushed shapes like the shape the head takes the place of.
That placement holds every shape of the main's page, and a pushed shape
followed any entry its reference names: a swapped board inside the
pushed swap took the size of the board it replaced, and its children
the place of their own component's main children, at the page origin.
The subtree of a swapped shape now keeps its pushed geometry, as the
subtree of a shape that authors its geometry does.

Test: updating-a-main-pushes-a-swapped-shape-nested-in-a-swap-with-its-children
(the scale gate program of seed 660536824).

Benchmark (scripts/bench-components, ms, lower 2.5% quantile), measured
with the previous commit's change in the tree as well:
|                             :world | :baseline |    :now |   :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |  21.827 |  22.409 |   0.62 |
| edit-through-a-chain-of-dependents |    68.931 |  45.406 |  46.777 |   0.66 |
|         library-update-into-copies |    83.083 |  56.396 |   58.29 |   0.68 |
|        main-edit-among-many-shapes |     4.837 |   2.456 |   2.809 |   0.51 |
|           main-edit-into-10-copies |      1.79 |   1.143 |   1.177 |   0.64 |
|          main-edit-into-100-copies |    15.415 |   11.12 |  11.591 |   0.72 |
|         main-edit-into-1000-copies |   153.086 | 111.472 | 118.427 |   0.73 |
|         variant-switch-into-copies |    32.052 |  22.527 |  23.487 |    0.7 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-12 10:13:54 +01:00
parent 1374a897b7
commit 8bf641ee81
2 changed files with 9 additions and 2 deletions

View File

@ -1422,9 +1422,9 @@
placed (when (and position (not (ctk/swapped? head)))
(placed-like position-objects position head
(authored-constraints by-id (cfh/get-children-ids by-id (:id head)))))
;; the shapes that keep their pushed geometry: the head and the subtrees of those that author theirs
;; the shapes that keep their pushed geometry: the head and the subtrees of those that author theirs or are swapped
kept-ids (into #{(:id head)}
(comp (filter #(ctk/touched-group? % :geometry-group))
(comp (filter #(or (ctk/touched-group? % :geometry-group) (ctk/swapped? %)))
(mapcat #(cfh/get-children-ids-with-self by-id (:id %))))
positioned)
follow-position (fn [shape]

View File

@ -2387,6 +2387,13 @@
:layout-copies false :text false}]
:ops [[:grid-track 10 5 0 11] [:grid-track 0 1] [:grid-cell 0 0 0 1]]}))))
(t/deftest updating-a-main-pushes-a-swapped-shape-nested-in-a-swap-with-its-children
(t/is (map? (cg/run {:world [3 3 {:variants true :text-styles true :scale true :layout :flex :variant-diff true
:grid-square false :copies 5 :rich-variants true :layout-children true
:grid-empty false :layout-copies false :text true}]
:ops [[:delete] [:restore] [:combine 21] [:swap 24] [:switch 27] [:rotate 14] [:switch 11]
[:combine 11] [:switch 6] [:switch 5] [:edit 16] [:edit 0 0 0 1] [:update-main 24]]}))))
(t/deftest random-shape-structure-compositions
(let [coverage (atom {})
failure (atom nil)]