From f795f76545ed5db3fc4339214570baba5dc833cc Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 9 Nov 2026 19:02:52 +0100 Subject: [PATCH] :bug: Keep a constrained child's size when a turned parent shrinks it to 0.01 A child of a turned parent first scales with the parent's resize, and its constraints then scale it back. The scale back divided by the child's scaled width with a 0.01 minimum, so a child that the resize scaled below 0.01 came back too narrow: a 70px text with a left constraint in a board turned 45 degrees and narrowed to 0.01 kept 40.83px. An axis-aligned parent skips this path, so the layout of an unturned copy kept 70px while the sync of that copy, which resizes its turned main, gave 40.83px. The scale back now divides by the child's real edge lengths, and only a collapsed child takes no scale. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 21.281 | 21.79 | 0.6 | | edit-through-a-chain-of-dependents | 68.931 | 41.715 | 42.166 | 0.61 | | library-update-into-copies | 83.083 | 50.352 | 52.632 | 0.61 | | main-edit-among-many-shapes | 4.837 | 2.29 | 2.413 | 0.47 | | main-edit-into-10-copies | 1.79 | 0.932 | 0.983 | 0.52 | | main-edit-into-100-copies | 15.415 | 8.968 | 9.361 | 0.58 | | main-edit-into-1000-copies | 153.086 | 99.524 | 107.384 | 0.65 | | variant-switch-into-copies | 32.052 | 21.503 | 21.923 | 0.67 | AI-assisted-by: claude-opus-5-5 --- .../app/common/geom/shapes/constraints.cljc | 14 ++++++++------ .../common_tests/geom_modifiers_test.cljc | 19 +++++++++++++++++++ .../logic/composable_gen_test.cljc | 7 +++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/geom/shapes/constraints.cljc b/common/src/app/common/geom/shapes/constraints.cljc index 325a6d3069..b3c8b05971 100644 --- a/common/src/app/common/geom/shapes/constraints.cljc +++ b/common/src/app/common/geom/shapes/constraints.cljc @@ -271,13 +271,15 @@ (let [child-bb-before (gpo/parent-coords-bounds child-bounds parent-bounds) child-bb-after (gpo/parent-coords-bounds transformed-child-bounds transformed-parent-bounds) - scale-x (if (= :scale constraints-h) - 1 - (/ (gpo/width-points child-bb-before) (max 0.01 (gpo/width-points child-bb-after)))) + ;; the length of the edge from the first point to the point at `index` + edge (fn [points index] (gpt/length (gpt/to-vec (nth points 0) (nth points index)))) + ;; the length `before` over the length `after`, or no scale for a collapsed child + restore (fn [index] + (let [after (edge child-bb-after index)] + (if (pos? after) (/ (edge child-bb-before index) after) 1))) - scale-y (if (= :scale constraints-v) - 1 - (/ (gpo/height-points child-bb-before) (max 0.01 (gpo/height-points child-bb-after)))) + scale-x (if (= :scale constraints-h) 1 (restore 1)) + scale-y (if (= :scale constraints-v) 1 (restore 3)) resize-vector (gpt/point scale-x scale-y) resize-origin (gpo/origin child-bb-after) diff --git a/common/test/common_tests/geom_modifiers_test.cljc b/common/test/common_tests/geom_modifiers_test.cljc index af3232cd89..77b13d5802 100644 --- a/common/test/common_tests/geom_modifiers_test.cljc +++ b/common/test/common_tests/geom_modifiers_test.cljc @@ -264,3 +264,22 @@ e2 (gpt/to-vec p1 p4) area (abs (- (* (:x e1) (:y e2)) (* (:y e1) (:x e2))))] (t/is (>= (/ area (max (gpt/length e1) (gpt/length e2))) 0.999)))) + +(t/deftest a-turned-board-narrowed-to-its-minimum-keeps-a-left-child-width + (let [file (-> (thf/sample-file :file1) + (tho/add-frame :board :width 120 :height 140) + (add-rect-child :child :board :width 70 :height 25 :constraints-h :left :constraints-v :top)) + objects (:objects (thf/current-page file)) + board (get objects (thi/id :board)) + objects (->> objects + (gm/set-objects-modifiers + {(:id board) {:modifiers (ctm/rotation-modifiers board (gsh/shape->center board) 45)}}) + (gtr/apply-objects-modifiers objects)) + board (get objects (thi/id :board)) + objects (->> objects + (gm/set-objects-modifiers + {(:id board) {:modifiers (ctm/change-size board 0.01 140)}}) + (gtr/apply-objects-modifiers objects)) + child (get objects (thi/id :child))] + (t/is (< (abs (- 70 (:width child))) 0.001)) + (t/is (< (abs (- 25 (:height child))) 0.001)))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 7fe97f46b0..5da08dfa4e 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1964,6 +1964,13 @@ [:nest 19 0 0 0] [:grid-direction 9 0 3 0] [:nest 8 0 0 0] [:add-variant 0] [:switch 12] [:make-variant 2] [:switch 14]]})))) +(t/deftest filling-an-unturned-copy-of-a-turned-main-keeps-its-left-text-width + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library-variants true :stale-libraries true + :layout :flex :layout-item-margins false :grid-square false :library-depth 1 + :library true :rich-variants true :layout-children false :library-text true + :grid-empty false :layout-copies true :text true}] + :ops [[:nest 7 0 0 0] [:transform 3 3 0 0] [:switch 1 0 0 0] [:style 3 29 1]]})))) + (t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false :layout-item-margins false :grid-square false :rich-variants true