🐛 Give the groups around a new bool the bounds of its result

A group takes its bounds from its children. Creating a bool inside a
group left the group with its old bounds, though the bool's result can
be smaller: a difference of a 12 px shape and a 20 px one inside a 30 px
group kept the group at 30 px in the main, while sync gave the copies'
groups the bool's 12 px. Creating a bool now refreshes the groups around
it, as masking does.

Tests: a-bool-made-in-a-group-gives-the-group-its-bounds;
a-bool-made-in-a-main-group-gives-the-copy-groups-its-bounds (the shape
structure program of gate seed 660536824).

Benchmark (scripts/bench-components, ms, lower 2.5% quantile), with a
3 GB heap, alone:
|                             :world | :baseline |    :now |   :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |  21.558 |  23.752 |   0.61 |
| edit-through-a-chain-of-dependents |    68.931 |  43.004 |  48.489 |   0.62 |
|         library-update-into-copies |    83.083 |  50.926 |  53.941 |   0.61 |
|        main-edit-among-many-shapes |     4.837 |   2.427 |   2.862 |    0.5 |
|           main-edit-into-10-copies |      1.79 |   1.121 |   1.214 |   0.63 |
|          main-edit-into-100-copies |    15.415 |  10.652 |  11.179 |   0.69 |
|         main-edit-into-1000-copies |   153.086 | 105.051 | 119.813 |   0.69 |
|         variant-switch-into-copies |    32.052 |  23.083 |  25.483 |   0.72 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-12 14:42:17 +01:00
parent bc5eb3f15c
commit dc485e2e08
3 changed files with 20 additions and 1 deletions

View File

@ -131,4 +131,6 @@
[parent-id]
(fn [parent]
(assoc-in parent [:layout-grid-cells (:id target-cell) :shapes] [shape-id]))))
(pcb/update-shapes grid-parents ctl/assign-cells {:with-objects? true}))]))))
(pcb/update-shapes grid-parents ctl/assign-cells {:with-objects? true})
;; the groups around the bool take the bounds of its result
(pcb/resize-parents [shape-id]))]))))

View File

@ -2467,6 +2467,11 @@
[:add-child 0 0 0 0] [:add-child 0] [:structure 14 1 0] [:rotate 15 0 0 0]
[:add-child 0] [:structure 0 3 0]]}))))
(t/deftest a-bool-made-in-a-main-group-gives-the-copy-groups-its-bounds
(t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants true :text false :layout :flex
:layout-copies false :layout-children false}]
:ops [[:delete] [:swap] [:add-child 1] [:structure] [:structure 4 0 1] [:structure 2 5 3]]}))))
(t/deftest random-shape-structure-compositions
(let [coverage (atom {})
failure (atom nil)]

View File

@ -144,3 +144,15 @@
tree (gm/set-objects-modifiers {(:id bool) {:modifiers (ctm/change-size bool 80 nil)}} objects)
rect (gsh/transform-shape (get objects (thi/id :rect)) (get-in tree [(thi/id :rect) :modifiers]))]
(t/is (mth/close? 80 (-> rect :selrect :width)))))
(t/deftest a-bool-made-in-a-group-gives-the-group-its-bounds
(let [file (-> (thf/sample-file :file1)
(ths/add-sample-shape :badge :width 12 :height 12)
(ths/add-sample-shape :rect :x 10 :y 10 :width 20 :height 20))
[id file] (group file [:badge :rect])
page (thf/current-page file)
[shape changes] (clb/generate-create-bool nil (:id page) (:objects page)
[(thi/id :badge) (thi/id :rect)] :difference nil)
objects (objects (thf/apply-changes file changes))]
(t/is (= (-> (get objects (:id shape)) :selrect ((juxt :x :y :width :height)))
(-> (get objects id) :selrect ((juxt :x :y :width :height)))))))