From 8061841b1be86411c649ab88bb5b0efefba56001 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 14 Nov 2026 12:39:28 +0100 Subject: [PATCH] :bug: Orient children of a fitted bool by its turn before its flips A bool keeps its turn and flips when fitting it resets its transform, so sync orients its children from them, choosing between the turn before the flips and the flips before the turn by which is nearer the bool's axes. A fitted bool's axes are the identity, which tells neither apart, and the choice fell to the flips first: a flipped, turned copy bool gave its child a half-turned orientation, which a sync of the settled state did not. The turn now goes first on a tie, as a flip of a turned shape stores it. Benchmark (lower quantile, ms): | world | baseline | now | mean | ratio | |------------------------------------+----------+---------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 22.783 | 25.354 | 0.65 | | edit-through-a-chain-of-dependents | 68.931 | 51.070 | 52.568 | 0.74 | | library-update-into-copies | 83.083 | 54.684 | 63.220 | 0.66 | | main-edit-among-many-shapes | 4.837 | 2.978 | 3.782 | 0.62 | | main-edit-into-10-copies | 1.79 | 1.212 | 1.281 | 0.68 | | main-edit-into-100-copies | 15.415 | 12.907 | 13.628 | 0.84 | | main-edit-into-1000-copies | 153.086 | 107.916 | 123.169 | 0.70 | | variant-switch-into-copies | 32.052 | 25.136 | 29.877 | 0.78 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 6 +++++- .../test/common_tests/logic/composable_gen_test.cljc | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index ecb8536964..2624f67f95 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -766,7 +766,11 @@ ;; how close the axes of `m` are to those of the shape closeness (fn [m] (+ (* (:a m) (:a axes)) (* (:b m) (:b axes)) (* (:c m) (:c axes)) (* (:d m) (:d axes)))) - transform (max-key closeness (gmt/multiply turn flips) (gmt/multiply flips turn))] + turned (gmt/multiply turn flips) + flipped (gmt/multiply flips turn) + ;; axes that tell neither apart, as those of a bool fitting resets, + ;; take the turn before the flips, as a flip of a turned shape stores + transform (if (>= (closeness turned) (closeness flipped)) turned flipped)] (assoc shape :transform transform :transform-inverse (gmt/inverse transform)))) (defn- layout-skewed? diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 1ab6b782c8..27995cf474 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4328,3 +4328,13 @@ :layout-children false :grid-empty false :layout-copies false :text false}] :ops [[:delete 5] [:restore] [:add-variant] [:switch] [:add-variant] [:variant-property 0 1] [:switch 13] [:style 5 8 7] [:add-variant]]})))) + +(t/deftest generated-a-flipped-turned-bool-gives-its-children-its-orientation + ;; a bool that a sync fits keeps its turn and flips; its children take + ;; the turn before the flips, as the flip of a turned shape stores them + (t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text true :layout :grid + :layout-copies false :layout-children true}] + :ops [[:add-child 12] [:structure 23 5 7] [:rotate] [:switch] [:transform 2 22 0 27]]}))) + (t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text true :layout :grid + :layout-copies false :layout-children false}] + :ops [[:duplicate] [:structure 0 4] [:swap 7] [:rotate 11] [:transform 1 11 0 12]]}))))