mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Rebuild a switched child's transform from the turn and flips it carries
A variant switch carries a copy child's rotation, with the old copy's transform, and each of its flips as separate attributes, each only where both variants agree on it. When the variants agreed on a flip but not on the turn, the flip flag carried while the transform and the corners stayed the new copy's; when they agreed on the turn but not on a flip, the old transform replaced the new variant's flip. Either way the stored rotation and flips no longer described the transform. When the switch carries a turn or a flip, it now gives the child the transform and the corners that the resulting turn and flips compose, the turn before or after the flips as is nearer the old copy's axes. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 22.732 | 23.882 | 0.65 | | edit-through-a-chain-of-dependents | 68.931 | 46.7 | 49.116 | 0.68 | | library-update-into-copies | 83.083 | 53.926 | 57.074 | 0.65 | | main-edit-among-many-shapes | 4.837 | 3.051 | 3.358 | 0.63 | | main-edit-into-10-copies | 1.79 | 1.147 | 1.188 | 0.64 | | main-edit-into-100-copies | 15.415 | 11.482 | 12.261 | 0.74 | | main-edit-into-1000-copies | 153.086 | 114.523 | 124.586 | 0.75 | | variant-switch-into-copies | 32.052 | 24.252 | 25.701 | 0.76 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
24e389b763
commit
8e53d5f782
@ -610,7 +610,7 @@
|
||||
(let [{:keys [a b c d]} (axes-matrix shape)]
|
||||
(not (mth/close? (+ (* a c) (* b d)) 0 0.0001))))
|
||||
|
||||
(defn- unskewed
|
||||
(defn unskewed
|
||||
"`shape` with the transform that its rotation and flips give it, without
|
||||
the skew a layout gives a turned child that it resizes along its parent's
|
||||
axes. Of a turn before or after the flips, the one nearer its axes."
|
||||
|
||||
@ -307,6 +307,26 @@
|
||||
:always
|
||||
(conj [attr attr-val])))))
|
||||
|
||||
(defn- reoriented-operations
|
||||
"The switch operations `[roperations uoperations]` into `current-shape`
|
||||
with, when they carry a turn or a flip, the transform and the corners
|
||||
the resulting turn and flips give it, so they describe one orientation.
|
||||
Of a turn before or after the flips, the one nearer the axes of
|
||||
`previous-shape`."
|
||||
[[roperations uoperations] current-shape previous-shape]
|
||||
(if-not (some (comp #{:rotation :flip-x :flip-y} :attr) roperations)
|
||||
[roperations uoperations]
|
||||
(let [carried (reduce (fn [shape {:keys [attr val]}] (assoc shape attr val))
|
||||
current-shape roperations)
|
||||
oriented (cll/unskewed (assoc carried :transform (:transform previous-shape)))
|
||||
values {:transform (:transform oriented)
|
||||
:transform-inverse (:transform-inverse oriented)
|
||||
:points (sized-geometry-value oriented (:width carried) (:height carried) :points)}
|
||||
kept? #(not (contains? values (:attr %)))
|
||||
[rops uops] (cll/attr-operations current-shape (fn [attr] [[attr (get values attr)]]) (keys values))]
|
||||
[(into (filterv kept? roperations) rops)
|
||||
(into (apply list (filter kept? uoperations)) uops)])))
|
||||
|
||||
(defn update-attrs-on-switch
|
||||
"Copy attributes that have changed in the shape previous to the switch
|
||||
to the current shape (post switch). Used only on variants switch"
|
||||
@ -333,10 +353,11 @@
|
||||
(concat (disj ctk/swap-keep-attrs :interactions)))
|
||||
|
||||
[roperations uoperations]
|
||||
(cll/attr-operations current-shape
|
||||
#(switch-attr-operations current-shape previous-shape origin-ref-shape
|
||||
touched text-auto? %)
|
||||
attrs)
|
||||
(-> (cll/attr-operations current-shape
|
||||
#(switch-attr-operations current-shape previous-shape origin-ref-shape
|
||||
touched text-auto? %)
|
||||
attrs)
|
||||
(reoriented-operations current-shape previous-shape))
|
||||
|
||||
updated-attrs (into #{} (map :attr) roperations)
|
||||
updated-sync-groups (into #{}
|
||||
|
||||
@ -2058,6 +2058,20 @@
|
||||
:layout-children false :grid-empty false :layout-copies false :text false}]
|
||||
:ops [[:combine 2] [:switch] [:swap 3]]}))))
|
||||
|
||||
(t/deftest switching-flips-a-child-transform-with-the-flip-both-variants-share
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout nil :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 [[:make-variant 15] [:make-variant] [:make-variant 20] [:swap 8]
|
||||
[:transform 0 10 0 18] [:rotate 21] [:switch]]}))))
|
||||
|
||||
(t/deftest switching-turns-a-child-keeping-the-flip-of-its-new-variant
|
||||
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :flex :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 [[:combine 8] [:transform 13 4 0 6] [:nest 8] [:make-variant] [:make-variant 7]
|
||||
[:make-variant] [:transform 0 9 0 2] [:combine 9] [:switch 6]]}))))
|
||||
|
||||
(t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn
|
||||
(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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user