From 469d97812d56ee3c2709475b8aa444211442156c Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 6 Nov 2026 10:46:13 +0100 Subject: [PATCH] :bug: Turn a swapped head's content by its axes, not its raw transform Sync places the content main of a swapped head in the head's orientation by turning the main's subtree with the head's transform against the main's. A head shrunk to a fraction of a pixel stores a transform that carries its rounding, not a pure turn: a child nested into its content main came out of a full sync slightly scaled and skewed, unlike the settled copy. The turn uses only the directions of both transforms' axes. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 22.709 | 0.64 | | edit-through-a-chain-of-dependents | 68.931 | 43.034 | 0.62 | | library-update-into-copies | 83.083 | 53.487 | 0.64 | | main-edit-among-many-shapes | 4.837 | 2.794 | 0.58 | | main-edit-into-10-copies | 1.79 | 1.068 | 0.60 | | main-edit-into-100-copies | 15.415 | 10.244 | 0.66 | | main-edit-into-1000-copies | 153.086 | 105.368 | 0.69 | | variant-switch-into-copies | 32.052 | 23.65 | 0.74 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 5 +++-- .../common_tests/logic/composable_gen_test.cljc | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index a0b24bef3c..31b25ef3ff 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -104,6 +104,7 @@ (declare reorder-copy-children) (declare add-shape-to-instance) (declare add-shape-to-main) +(declare axes-matrix) (declare remove-shape) (declare move-shape) (declare reorder-main-children) @@ -345,8 +346,8 @@ swapped? (and (not reset?) (ctk/swapped? shape-inst)) origin (if swapped? shape-main main-parent) target (if swapped? shape-inst parent) - relative (gmt/multiply (or (:transform target) (gmt/matrix)) - (or (:transform-inverse origin) (gmt/matrix)))] + ;; the axes only: a tiny shape's transform carries its rounding + relative (gmt/multiply (axes-matrix target) (gmt/inverse (axes-matrix origin)))] (if (or (nil? target) (and (:shape-ref parent) (not reset?) (not swapped?)) (gmt/unit? relative)) main-container diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 014c9e9658..a0061baaa9 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1255,3 +1255,16 @@ [:grid-cell 0 0 0 1] [:restore 0 0 0 0] [:delete 0 0 0 0] [:grid-direction 5 0 3 0] [:add-child 1 0 0 0] [:update-main 0 0 0 0] [:grid-direction 0 0 0 0] [:grid-direction 0 0 3 0]]})))) + +(t/deftest generated-tiny-swapped-head-turns-its-content-rigidly + ;; a swapped head shrunk to 0.01 px and turned has a transform carrying its + ;; rounding; a nest into its content main turns the new child by the head's + ;; axes alone, without scaling it + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :layout :flex :layout-item-margins true + :grid-square false :library true :rich-variants true :layout-children false + :grid-empty true :layout-copies true :text true}] + :ops [[:rotate 3 0 0 0] [:delete 16] [:restore 16] [:delete 16 0 0 0] + [:style 1 10 1] [:delete 1 0 0 0] [:restore 0 0 0 0] [:edit 10 0 1 1] + [:update-main 10] [:undo 0 0 0 0] [:nest 19 0 0 0] [:detach 1 0 0 0] + [:detach 2 0 0 0] [:delete 23 0 0 0] [:restore 3 0 0 0] [:swap 13 0 0 0] + [:nest 21 0 0 0]]}))))