🐛 Orient children of a fitted bool by its turn before its flips

A bool keeps its turn and flips when fitting it resets its transform, so
sync orients its children from them, choosing between the turn before
the flips and the flips before the turn by which is nearer the bool's
axes. A fitted bool's axes are the identity, which tells neither apart,
and the choice fell to the flips first: a flipped, turned copy bool gave
its child a half-turned orientation, which a sync of the settled state
did not. The turn now goes first on a tie, as a flip of a turned shape
stores it.

Benchmark (lower quantile, ms):

| world                              | baseline |     now |    mean | ratio |
|------------------------------------+----------+---------+---------+-------|
| deepest-edit-through-three-levels  |   35.215 |  22.783 |  25.354 |  0.65 |
| edit-through-a-chain-of-dependents |   68.931 |  51.070 |  52.568 |  0.74 |
| library-update-into-copies         |   83.083 |  54.684 |  63.220 |  0.66 |
| main-edit-among-many-shapes        |    4.837 |   2.978 |   3.782 |  0.62 |
| main-edit-into-10-copies           |    1.79  |   1.212 |   1.281 |  0.68 |
| main-edit-into-100-copies          |   15.415 |  12.907 |  13.628 |  0.84 |
| main-edit-into-1000-copies         |  153.086 | 107.916 | 123.169 |  0.70 |
| variant-switch-into-copies         |   32.052 |  25.136 |  29.877 |  0.78 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-14 12:39:28 +01:00
parent 5b725b68a6
commit c86e7b2f3a
2 changed files with 15 additions and 1 deletions

View File

@ -727,7 +727,11 @@
;; how close the axes of `m` are to those of the shape
closeness (fn [m] (+ (* (:a m) (:a axes)) (* (:b m) (:b axes))
(* (:c m) (:c axes)) (* (:d m) (:d axes))))
transform (max-key closeness (gmt/multiply turn flips) (gmt/multiply flips turn))]
turned (gmt/multiply turn flips)
flipped (gmt/multiply flips turn)
;; axes that tell neither apart, as those of a bool fitting resets,
;; take the turn before the flips, as a flip of a turned shape stores
transform (if (>= (closeness turned) (closeness flipped)) turned flipped)]
(assoc shape :transform transform :transform-inverse (gmt/inverse transform))))
(defn- layout-skewed?

View File

@ -4328,3 +4328,13 @@
:layout-children false :grid-empty false :layout-copies false :text false}]
:ops [[:delete 5] [:restore] [:add-variant] [:switch] [:add-variant] [:variant-property 0 1]
[:switch 13] [:style 5 8 7] [:add-variant]]}))))
(t/deftest generated-a-flipped-turned-bool-gives-its-children-its-orientation
;; a bool that a sync fits keeps its turn and flips; its children take
;; the turn before the flips, as the flip of a turned shape stores them
(t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text true :layout :grid
:layout-copies false :layout-children true}]
:ops [[:add-child 12] [:structure 23 5 7] [:rotate] [:switch] [:transform 2 22 0 27]]})))
(t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text true :layout :grid
:layout-copies false :layout-children false}]
:ops [[:duplicate] [:structure 0 4] [:swap 7] [:rotate 11] [:transform 1 11 0 12]]}))))