🐛 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
This commit is contained in:
alonso.torres 2026-11-06 10:46:13 +01:00
parent 9c539b173f
commit 469d97812d
2 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -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]]}))))