From ed24eaa1b6ce9dba61f187d71c6b967a88e7298b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 11 Nov 2026 09:49:36 +0100 Subject: [PATCH] :bug: Move a child that sits on the start of its squeezed parent A flex layout can squeeze a fill frame to almost no width and move it onto its child at the frame's right edge. The left constraint keeps the vector from the child to its parent's left side, but after the move the child sits on that side, so the vector has no length and no direction. The displacement scaled a zero unit vector and the child did not move. The displacement now takes the direction from the parent's side, pointing as the vector did before. Tests: start-constraint-moves-a-child-onto-the-start-of-its-squeezed- parent and nesting-a-copy-that-squeezes-a-fill-frame-moves-the-child-at- its-end (the variant gate program of round 11, seed 212451915). Common suite: 2435 tests, 0 failures. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+--------+--------| | deepest-edit-through-three-levels | 35.215 | 20.995 | 22.097 | 0.6 | | edit-through-a-chain-of-dependents | 68.931 | 46.757 | 48.547 | 0.68 | | library-update-into-copies | 83.083 | 47.501 | 55.402 | 0.57 | | main-edit-among-many-shapes | 4.837 | 2.493 | 2.793 | 0.52 | | main-edit-into-10-copies | 1.79 | 1.051 | 1.177 | 0.59 | | main-edit-into-100-copies | 15.415 | 10.322 | 11.091 | 0.67 | | main-edit-into-1000-copies | 153.086 | 91.123 | 97.288 | 0.6 | | variant-switch-into-copies | 32.052 | 20.829 | 21.942 | 0.65 | AI-assisted-by: claude-opus-5-5 --- .../app/common/geom/shapes/constraints.cljc | 14 +++++++++- .../geom_shapes_constraints_test.cljc | 28 +++++++++++++++++++ .../logic/composable_gen_test.cljc | 10 +++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/geom/shapes/constraints.cljc b/common/src/app/common/geom/shapes/constraints.cljc index b3c8b05971..173e6378a0 100644 --- a/common/src/app/common/geom/shapes/constraints.cljc +++ b/common/src/app/common/geom/shapes/constraints.cljc @@ -148,6 +148,9 @@ ((if (= :x axis) center-horizontal-vector center-vertical-vector) child-points parent-points)) (defn displacement + "The move that gives a child the vector `before-v` to its parent's side + again, where it now has `after-v`. A child on the side has no direction + to it, so the parent's side gives the one `before-v` had." [before-v after-v before-parent-side-v after-parent-side-v] (let [before-angl (gpt/angle-with-other before-v before-parent-side-v) @@ -155,8 +158,17 @@ sign (if (mth/close? before-angl after-angl) 1 -1) length (* sign (gpt/length before-v))] - (if (mth/almost-zero? length) + (cond + (mth/almost-zero? length) after-v + + (mth/almost-zero? (gpt/length after-v)) + (let [;; the parent's side, pointing as `before-v` did along it + direction (cond-> (gpt/unit after-parent-side-v) + (not (mth/close? before-angl 0)) (gpt/negate))] + (gpt/subtract after-v (gpt/scale direction (gpt/length before-v)))) + + :else (gpt/subtract after-v (gpt/scale (gpt/unit after-v) length))))) (defn side-vector diff --git a/common/test/common_tests/geom_shapes_constraints_test.cljc b/common/test/common_tests/geom_shapes_constraints_test.cljc index 0dd38b5f33..28efacfa2a 100644 --- a/common/test/common_tests/geom_shapes_constraints_test.cljc +++ b/common/test/common_tests/geom_shapes_constraints_test.cljc @@ -6,6 +6,7 @@ (ns common-tests.geom-shapes-constraints-test (:require + [app.common.geom.point :as gpt] [app.common.geom.shapes.constraints :as gsc] [app.common.types.modifiers :as ctm] [clojure.test :as t])) @@ -23,3 +24,30 @@ (t/testing ":default method can be added to modifiers" (let [result (gsc/constraint-modifier :scale :y nil nil nil nil)] (t/is (ctm/empty? (ctm/add-modifiers (ctm/empty) result)))))) + +;; ---- constraint-modifier :start ---- + +(defn- rect-points + [x y w h] + [(gpt/point x y) (gpt/point (+ x w) y) (gpt/point (+ x w) (+ y h)) (gpt/point x (+ y h))]) + +(defn- move-vector + [modifiers] + (reduce gpt/add (gpt/point 0 0) + (keep #(when (= :move (:type %)) (:vector %)) (:geometry-child modifiers)))) + +(t/deftest start-constraint-moves-a-child-onto-the-start-of-its-squeezed-parent + (t/testing "a child at the end of its parent keeps its start offset when the + parent is squeezed to zero and moved onto it" + (let [child (rect-points 100 0 100 100) + before (rect-points 0 0 100 100) + after (rect-points 100 0 0.01 100) + result (gsc/constraint-modifier :start :x child before child after)] + (t/is (gpt/close? (gpt/point 100 0) (move-vector result))))) + + (t/testing "a child the moved parent passes over keeps its start offset" + (let [child (rect-points 50 0 100 100) + before (rect-points 0 0 100 100) + after (rect-points 100 0 0.01 100) + result (gsc/constraint-modifier :start :x child before child after)] + (t/is (gpt/close? (gpt/point 100 0) (move-vector result)))))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index d5f32d48ba..158383a160 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2209,6 +2209,16 @@ [:combine 18] [:make-variant] [:switch 18] [:combine] [:rotate 8] [:update-main]]})))) +(t/deftest nesting-a-copy-that-squeezes-a-fill-frame-moves-the-child-at-its-end + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :flex :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:add-variant] [:delete 10] [:restore] [:delete 10] [:restore] [:combine 12] + [:combine 9] [:combine] [:style 0 29 1] [:add-variant] [:add-variant] + [:make-variant] [:combine] [:add-variant] [:add-variant] [:add-variant] + [:add-variant] [:combine] [:add-variant] [:combine] [:update-main] + [:nest 13]]})))) + (t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false :layout-item-margins false :grid-square true :rich-variants false