🐛 Keep an empty bool at its place when its geometry updates

A bool whose shapes do not intersect has no content. Its geometry took
the bounds of empty content, a rect at the page origin, and turned it
about its old center with the bool's transform: a bool turned 180° moved
to twice its center at each update, so in a grid copy turned that way it
ran away and the layout moved its shapes after it. A shape with no
content now keeps its center.

Tests: an-empty-turned-shape-keeps-its-place-when-its-geometry-updates;
settling-a-bool-in-a-grid-copy-twice-keeps-its-shapes-in-place (the
shape structure program that found it).

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 | 21.443 |  22.755 |   0.61 |
| edit-through-a-chain-of-dependents |    68.931 | 40.138 |  42.216 |   0.58 |
|         library-update-into-copies |    83.083 | 51.127 |  55.671 |   0.62 |
|        main-edit-among-many-shapes |     4.837 |  2.516 |   3.029 |   0.52 |
|           main-edit-into-10-copies |      1.79 |   1.11 |   1.148 |   0.62 |
|          main-edit-into-100-copies |    15.415 |  9.991 |  10.514 |   0.65 |
|         main-edit-into-1000-copies |   153.086 | 97.388 | 114.808 |   0.64 |
|         variant-switch-into-copies |    32.052 | 21.907 |  23.988 |   0.68 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-12 12:16:29 +01:00
parent 3b8a2ce11a
commit e595ac8b0b
3 changed files with 26 additions and 2 deletions

View File

@ -178,9 +178,12 @@
base-content
(segment/transform-content content (gmt/transform-in center transform-inverse))
;; Calculates the new selrect with points given the old center
;; Calculates the new selrect with points given the old center; an
;; empty content keeps the shape at that center
points
(-> (segment/content->selrect base-content)
(-> (if (pos? (count base-content))
(segment/content->selrect base-content)
(grc/center->rect center 0.01))
(grc/rect->points)
(gco/transform-points center transform))

View File

@ -2430,6 +2430,12 @@
:grid-empty false :layout-copies false :text false}]
:ops [[:transform 0 2 0 7] [:delete] [:switch] [:transform 1 1]]}))))
(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}]
:ops [[:rotate 16 0 7 0] [:grid-direction 0 0 0 1] [:grid-cell 0 10 0 1] [:add-child 0]
[:structure 3 6 15] [:grid-direction 0 0 0 1] [:grid-cell 0 4 2 1]]}))))
(t/deftest random-shape-structure-compositions
(let [coverage (atom {})
failure (atom nil)]

View File

@ -2864,3 +2864,18 @@
result (path/splice-content content sub)]
(t/is (path.impl/path-data? result))
(t/is (= (into (vec content) sub) (vec result)))))
(t/deftest an-empty-turned-shape-keeps-its-place-when-its-geometry-updates
(let [center (gpt/point 135 197)
transform (gmt/rotate-matrix 180)
shape {:type :bool
:content []
:selrect (grc/center->rect center 0.01)
:transform transform
:transform-inverse (gmt/inverse transform)}
updated (path/update-geometry shape)
twice (path/update-geometry updated)]
(t/is (mth/close? 135 (:x (grc/rect->center (:selrect updated))) 0.01))
(t/is (mth/close? 197 (:y (grc/rect->center (:selrect updated))) 0.01))
(t/is (mth/close? 135 (:x (grc/rect->center (:selrect twice))) 0.01))
(t/is (mth/close? 197 (:y (grc/rect->center (:selrect twice))) 0.01))))