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