From e595ac8b0b3de4187afe4a27673ff346a99f11af Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 12 Nov 2026 12:16:29 +0100 Subject: [PATCH] :bug: Keep an empty bool at its place when its geometry updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- common/src/app/common/types/path.cljc | 7 +++++-- .../common_tests/logic/composable_gen_test.cljc | 6 ++++++ .../test/common_tests/types/path_data_test.cljc | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/types/path.cljc b/common/src/app/common/types/path.cljc index 66996ddd3b..4581e481ef 100644 --- a/common/src/app/common/types/path.cljc +++ b/common/src/app/common/types/path.cljc @@ -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)) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 2ea6a87338..5f8f6b0f12 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -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)] diff --git a/common/test/common_tests/types/path_data_test.cljc b/common/test/common_tests/types/path_data_test.cljc index 6c1b957691..42a40d3abc 100644 --- a/common/test/common_tests/types/path_data_test.cljc +++ b/common/test/common_tests/types/path_data_test.cljc @@ -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))))