🐛 Keep the inherited turn of a switched copy child without an override

A switch keeps an orientation that the copy, or a shape along its
reference chain, authored when both variants share it, and compares it
with the new copy's own orientation instead of the place its position
gives it. Any geometry override along the chain counted as authoring
it, so a copy child whose position main was only resized carried the
turn it inherits from its turned copy parent, and the switch marked that
inherited turn as a geometry override.

The orientation is carried only when it differs from its component's
orientation turned and flipped with its parent; an inherited one is
compared with the place its position gives it.

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

| world                              | baseline |     now | ratio |
|------------------------------------+----------+---------+-------|
| deepest-edit-through-three-levels  |   35.215 |  19.316 |  0.55 |
| edit-through-a-chain-of-dependents |   68.931 |  39.369 |  0.57 |
| library-update-into-copies         |   83.083 |  45.503 |  0.55 |
| main-edit-among-many-shapes        |    4.837 |   2.125 |  0.44 |
| main-edit-into-10-copies           |     1.79 |   0.933 |  0.52 |
| main-edit-into-100-copies          |   15.415 |   9.092 |  0.59 |
| main-edit-into-1000-copies         |  153.086 |  92.629 |  0.61 |
| variant-switch-into-copies         |   32.052 |  20.538 |  0.64 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-04 05:15:29 +01:00
parent 1b2c74da68
commit 0e812b1f5e
2 changed files with 22 additions and 1 deletions

View File

@ -534,10 +534,24 @@
new-ldata (or (get-in libraries [(:component-file new-shape) :data]) ldata)
new-main (ctf/get-component-root new-ldata (ctkl/get-component new-ldata (:component-id new-shape)))
;; An authored orientation carries only where both variants share it
parent (get page-objects (:parent-id original-shape))
ref-parent (get orig-ref-objects (:parent-id orig-base-ref-shape))
;; Whether the switched copy's orientation is authored along its
;; reference chain, not just its component's turned with its parent
authored-orientation? (let [flip (fn [key]
(odd? (count (filter identity [(get orig-base-ref-shape key) (get parent key)
(get ref-parent key)]))))]
(or (not (mth/close? (mod (or (:rotation original-shape) 0) 360)
(mod (+ (or (:rotation orig-base-ref-shape) 0)
(- (or (:rotation parent) 0) (or (:rotation ref-parent) 0)))
360)
0.01))
(not= (boolean (:flip-x original-shape)) (flip :flip-x))
(not= (boolean (:flip-y original-shape)) (flip :flip-y))))
carried-orientation? (and (some #(and (= (:id %) (:id original-shape))
(ctk/touched-group? % :geometry-group)) orig-touched)
authored-orientation?
(same-orientation? orig-base-ref-shape new-main))
parent (get page-objects (:parent-id original-shape))
;; A switch keeps orientation even when the old main supplied it.
;; If no orientation was carried, placement from an enclosing copy is
;; still inherited rather than authored by this switch.

View File

@ -1070,3 +1070,10 @@
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library true :rich-variants true
:layout-copies true :text true}]
:ops [[:nest 4 0 0 0] [:transform 1 0 0 3] [:switch 3 0 0 0]]}))))
(t/deftest generated-switch-keeps-the-inherited-turn-of-a-copy-child
;; a copy child of a turned copy, whose position main is resized, keeps
;; the turn it inherits through a switch without an override
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :variant-diff false :rich-variants true
:layout-copies true :text true}]
:ops [[:resize 0 0 0 0] [:rotate 1 0 0 0] [:switch 4 0 0 0]]}))))