🐛 Keep the layout's place and sizes out of a detach's kept geometry

A detach advances the references of nested copies, and marks the
geometry of one authored when its new main would place it elsewhere. For
a nested copy a layout places, that compared the place and the sizes
the layout gives it: a grid that starts its tracks at 0.01 px, or a copy
that fills its grid, made its geometry an override, while the contract
keeps the place of a layout child and the sizes it fills or hugs the
layout's. Such a copy now keeps as authored only an orientation or a
size of its own, leaving out the dimensions its layout gives it, and the
model checks the same.

Tests: detaching-after-a-main-adds-a-row-leaves-the-copy-boards-unauthored
(the grid gate program of seed 673701779) and
detaching-keeps-unauthored-a-nested-copy-a-grid-fills (a random grid
program of the common suite).
Common suite: 2466 tests; only the open red tests and a new random shape
structure case (F488 family) fail.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile), measured
with the next commit's change in the tree as well:
|                             :world | :baseline |    :now |   :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |   22.04 |   22.52 |   0.63 |
| edit-through-a-chain-of-dependents |    68.931 |  43.463 |   44.28 |   0.63 |
|         library-update-into-copies |    83.083 |  48.024 |  50.138 |   0.58 |
|        main-edit-among-many-shapes |     4.837 |   2.247 |   2.418 |   0.46 |
|           main-edit-into-10-copies |      1.79 |    1.06 |   1.078 |   0.59 |
|          main-edit-into-100-copies |    15.415 |  10.242 |  11.303 |   0.66 |
|         main-edit-into-1000-copies |   153.086 | 110.068 | 112.273 |   0.72 |
|         variant-switch-into-copies |    32.052 |  22.921 |  23.391 |   0.72 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-12 05:33:21 +01:00
parent a64ea2121c
commit 9e2a50da3c
2 changed files with 50 additions and 17 deletions

View File

@ -2036,26 +2036,43 @@
(defn- turned-like-parent?
"Whether `shape` has the size of `main` and the orientation `main` takes
when turned from `main-parent` to `parent`, wherever each one is. A
main at the root of its page has an unturned parent."
[shape main main-parent parent]
(let [main-parent (when-not (cfh/root? main-parent) main-parent)
flip? (fn [key] (odd? (count (filter key [main main-parent parent]))))]
(and (mth/close? (-> shape :selrect :width) (-> main :selrect :width))
(mth/close? (-> shape :selrect :height) (-> main :selrect :height))
(gmt/close? (axes-matrix shape)
(gmt/multiply (axes-matrix parent)
(gmt/inverse (axes-matrix main-parent))
(axes-matrix main)))
(= (boolean (:flip-x shape)) (flip? :flip-x))
(= (boolean (:flip-y shape)) (flip? :flip-y)))))
main at the root of its page has an unturned parent. The dimensions in
`sized`, which a layout gives the shape, are left out."
([shape main main-parent parent] (turned-like-parent? shape main main-parent parent #{}))
([shape main main-parent parent sized]
(let [main-parent (when-not (cfh/root? main-parent) main-parent)
flip? (fn [key] (odd? (count (filter key [main main-parent parent]))))]
(and (or (contains? sized :width) (mth/close? (-> shape :selrect :width) (-> main :selrect :width)))
(or (contains? sized :height) (mth/close? (-> shape :selrect :height) (-> main :selrect :height)))
(gmt/close? (axes-matrix shape)
(gmt/multiply (axes-matrix parent)
(gmt/inverse (axes-matrix main-parent))
(axes-matrix main)))
(= (boolean (:flip-x shape)) (flip? :flip-x))
(= (boolean (:flip-y shape)) (flip? :flip-y))))))
(defn- layout-sized
"The dimensions a layout gives `shape`: those it fills in its layout
parent or hugs as a layout itself, and both once it is turned in a
layout parent, which resizes it along its own axes."
[objects shape]
(let [child? (and (ctsl/any-layout-immediate-child? objects shape)
(not (ctsl/position-absolute? shape)))
owned? #(and (or child? (ctsl/any-layout? shape)) (#{:fill :auto} %))
sized (cond-> #{}
(owned? (:layout-item-h-sizing shape)) (conj :width)
(owned? (:layout-item-v-sizing shape)) (conj :height))]
(if (and child? (seq sized) (not (mth/close? (mod (or (:rotation shape) 0) 360) 0)))
#{:width :height}
sized)))
(defn generate-keep-advanced-placement
"Make authored the geometry of the copy shapes `ids`, whose references
advanced, when their next sync would place them elsewhere: their copy
parent keeps overrides that the new main lacks. Under a plain parent a
copy is placed freely, and only its orientation and size follow its
main, turned like that parent. Parents come before their children, so each child is checked in
its parent's settled frame."
main, turned like that parent, as does one a layout places. Parents come before their children,
so each child is checked in its parent's settled frame."
[changes container libraries ids]
(reduce
(fn [changes id]
@ -2066,15 +2083,19 @@
main (ctf/find-ref-shape nil container libraries shape
:include-deleted? true :with-context? true)
main-objects (:objects (:container (meta main)))
main-parent (get main-objects (:parent-id main))]
main-parent (get main-objects (:parent-id main))
;; a layout places the shape, so only its size and orientation can be its own
layout-placed? (and (ctsl/any-layout-immediate-child? objects shape)
(not (ctsl/position-absolute? shape)))]
(if (and (some? main)
(not (ctk/touched-group? shape :geometry-group))
(if (some? (:shape-ref parent))
(if (and (some? (:shape-ref parent)) (not layout-placed?))
(and (some? main-parent)
(not (close-geometry? shape (get (placed-like main-objects main-parent parent
(authored-constraints objects [id]))
(:id main)))))
(not (turned-like-parent? shape main main-parent parent))))
(not (turned-like-parent? shape main main-parent parent
(if layout-placed? (layout-sized objects shape) #{})))))
(pcb/update-shapes changes [id] #(update % :touched ctk/set-touched-group :geometry-group)
{:ignore-touched true})
changes)))

View File

@ -2369,6 +2369,18 @@
:layout-copies true :layout-children false}]
:ops [[:delete 0] [:restore 0] [:add-child 0] [:structure 0 4 0] [:rotate 0 0 0 0]]}))))
(t/deftest detaching-after-a-main-adds-a-row-leaves-the-copy-boards-unauthored
(t/is (map? (cg/run {:world [1 1 {:variants true :layout :grid :layout-item-margins false :grid-square false
:rich-variants true :layout-children false :grid-empty false
:layout-copies true :text true}]
:ops [[:nest 7] [:swap 7] [:grid-cell] [:grid-track 7] [:detach 1]]}))))
(t/deftest detaching-keeps-unauthored-a-nested-copy-a-grid-fills
(t/is (map? (cg/run {:world [3 2 {:variants true :layout :grid :layout-item-margins false :grid-square false
:rich-variants true :layout-children false :grid-empty false
:layout-copies true :text true}]
:ops [[:nest 6 0 0 0] [:nest 9 0 0 0] [:style 2 29 1] [:detach 5 0 0 0]]}))))
(t/deftest random-shape-structure-compositions
(let [coverage (atom {})
failure (atom nil)]