🐛 Keep a switched head's authored turn against its parent's turn too

A switch that carries an authored orientation marks a geometry override
when the head's turn differs from its new main's placement. Inside a copy
the placement left out the turn of the head's parent: a head whose near
main's half turn cancelled its turned copy parent's showed the main's own
turn, looked unchanged and lost its override.

The placement includes the parent's turn and flips inside a copy too.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):

| world                              | baseline |     now | ratio |
|------------------------------------+----------+---------+-------|
| deepest-edit-through-three-levels  |   35.215 |  19.589 |  0.56 |
| edit-through-a-chain-of-dependents |   68.931 |  39.264 |  0.57 |
| library-update-into-copies         |   83.083 |  48.997 |  0.59 |
| main-edit-among-many-shapes        |    4.837 |   2.377 |  0.49 |
| main-edit-into-10-copies           |     1.79 |   1.031 |  0.58 |
| main-edit-into-100-copies          |   15.415 |   9.145 |  0.59 |
| main-edit-into-1000-copies         |  153.086 |  97.525 |  0.64 |
| variant-switch-into-copies         |   32.052 |  21.316 |  0.67 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-06 01:11:35 +01:00
parent da44e9ee50
commit dfa7e63147
2 changed files with 13 additions and 6 deletions

View File

@ -391,14 +391,12 @@
main-parent (if position
(get-in (meta position) [:container :objects (:parent-id position)])
main-parent)
parent-delta (if (and (:shape-ref parent) (nil? position)) 0
rotation (mod (+ (or (:rotation baseline) 0)
(- (or (:rotation parent) 0) (or (:rotation main-parent) 0)))
rotation (mod (+ (or (:rotation baseline) 0) parent-delta) 360)
360)
flip (fn [key]
(if (and (:shape-ref parent) (nil? position))
(boolean (get baseline key))
(odd? (count (filter identity [(get baseline key) (get parent key)
(get main-parent key)])))))
(odd? (count (filter identity [(get baseline key) (get parent key)
(get main-parent key)]))))
changed? (or (not (mth/close? (mod (or (:rotation shape) 0) 360) rotation 0.01))
(not= (boolean (:flip-x shape)) (flip :flip-x))
(not= (boolean (:flip-y shape)) (flip :flip-y)))]

View File

@ -1210,3 +1210,12 @@
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies true :text true}]
:ops [[:rotate 0 0 0 0] [:update-main 0 0 0 0] [:resize 0 0 0 0] [:switch 4 0 0 0]]}))))
(t/deftest generated-switch-in-a-copy-keeps-a-turn-that-cancels-its-parents
;; a copy child shows no turn: its near main's half turn cancels its turned
;; copy parent's; a switch keeps that authored turn as an override
(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
:layout-children false :grid-empty false :layout-copies true :text true}]
:ops [[:duplicate 0 0 0 0] [:rotate 16 0 7 0] [:duplicate 0 0 0 0] [:rotate 16 0 7 0]
[:switch 12 0 0 0]]}))))