🐛 Carry a mirrored child's turn with its transform on a switch

A mirror stores its turn either way, so two variants can hold a flipped
child with one transform and the rotations 315 and 45. A switch compared
the attributes one by one: it carried the copy's transform and corners,
whose values both variants share, but not its rotation, leaving a shape
whose rotation its transform does not hold. The turns of two mirrors now
also agree where they point their axes alike, so the turn carries with
the transform.

Test (the variant gate program of round 12, seed 164135730):
switching-a-copy-carries-the-turn-of-a-mirrored-child-with-its-transform
Composable generated, swap group and variant tests: 533 tests, 0 failures.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):
|                             :world | :baseline |    :now |   :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |  21.684 |  22.254 |   0.62 |
| edit-through-a-chain-of-dependents |    68.931 |  40.146 |  43.327 |   0.58 |
|         library-update-into-copies |    83.083 |  50.403 |  52.479 |   0.61 |
|        main-edit-among-many-shapes |     4.837 |   2.045 |    2.23 |   0.42 |
|           main-edit-into-10-copies |      1.79 |   1.098 |   1.131 |   0.61 |
|          main-edit-into-100-copies |    15.415 |  10.462 |  10.578 |   0.68 |
|         main-edit-into-1000-copies |   153.086 | 103.929 | 107.681 |   0.68 |
|         variant-switch-into-copies |    32.052 |  21.622 |  22.386 |   0.67 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 04:07:12 +01:00
parent 5ed9771864
commit 83156ea5f7
3 changed files with 30 additions and 2 deletions

View File

@ -613,7 +613,7 @@
(grc/rect->center (:selrect (get objects (:id shape-main)))))]
(reduce #(update %1 %2 gsh/move delta) objects ids)))
(defn- axes-matrix
(defn axes-matrix
"The directions of the axes of the transform of `shape`, without their
lengths: the transform of a tiny shape scales them by its rounding."
[shape]

View File

@ -170,6 +170,11 @@
(contains? carried :text-content-typography)
(into (filter agreed) txt/typography-units))))
(defn- mirrored?
"Whether `shape` has exactly one flip."
[shape]
(not= (boolean (:flip-x shape)) (boolean (:flip-y shape))))
(defn- switch-attr-operations
"The `[attr value]` pairs that carry `attr` over a variant switch, from
`previous-shape`, the copy shape before the switch placed like
@ -217,10 +222,17 @@
;; 3. We set Copy’s bg to green (so it it has an override on the bg).
;; 4. We switch Copy to use C2 as base.
;; 5. The bg of Copy now is blue (we ignore the override)
;; A mirror stores its turn either way, so the turns of two
;; mirrors also agree where both point their axes alike.
(and
(not (contains? #{:points :selrect :content} attr))
(not (if (= sync-group :geometry-group)
(gsh/close-attrs? attr (get origin-ref-shape attr) (get current-shape attr))
(or (gsh/close-attrs? attr (get origin-ref-shape attr) (get current-shape attr))
(and (= attr :rotation)
(mirrored? origin-ref-shape)
(mirrored? current-shape)
(gmt/close? (cll/axes-matrix origin-ref-shape)
(cll/axes-matrix current-shape))))
(= (get origin-ref-shape attr) (get current-shape attr)))))
;; The :content attr cant't be copied to elements of different type

View File

@ -20,6 +20,7 @@
[app.common.test-helpers.composable.comp.setups :as setup]
[app.common.test-helpers.composable.core :as tm]
[app.common.test-helpers.composable.gen :as cg]
[app.common.test-helpers.composable.geometry :as geom]
[app.common.test-helpers.composable.grid :as grid]
[app.common.test-helpers.composable.oracle :as oracle]
[app.common.test-helpers.composable.shadow :as shadow]
@ -2166,6 +2167,21 @@
:ops [[:swap] [:make-variant 12] [:rotate] [:delete] [:transform 6 5]
[:transform 3 9 0 13] [:switch]]}))))
(t/deftest switching-a-copy-carries-the-turn-of-a-mirrored-child-with-its-transform
(let [situation (:situation
(cg/run {:world [2 2 {:variants true :text-styles false :layout :grid :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies false :text true}]
:ops [[:swap] [:make-variant 12] [:rotate] [:delete] [:transform 6 5]
[:transform 3 9 0 13] [:switch]]}))
turned (for [file (vals (cf/all-files situation))
objects (cf/object-trees file)
shape (vals objects)
:when (and (ctk/touched-group? shape :geometry-group) (:flip-y shape))]
shape)]
(t/is (seq turned))
(t/is (every? geom/decomposes? turned))))
(t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry
(t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true