mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Store the turn a transform decomposes into when a turn flips it
Turning a subtree to match another orientation stores, for each shape, its old rotation plus the turn, or minus it when only that one fits its flips. A turn that also drops or adds a flip leaves neither fitting: a switch from an unflipped variant to a flipped one kept the copy's unflipped turn in the transform but stored the flipped main's rotation. When neither fits, the shape stores the rotation its transform decomposes into with its flips. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.641 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 38.794 | 0.56 | | library-update-into-copies | 83.083 | 46.743 | 0.56 | | main-edit-among-many-shapes | 4.837 | 2.355 | 0.49 | | main-edit-into-10-copies | 1.79 | 0.997 | 0.56 | | main-edit-into-100-copies | 15.415 | 9.669 | 0.63 | | main-edit-into-1000-copies | 153.086 | 97.248 | 0.64 | | variant-switch-into-copies | 32.052 | 21.73 | 0.68 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
e410278c91
commit
189be55a15
@ -2031,7 +2031,8 @@
|
||||
"The rotation that `shape`, just turned by `angle` with its subtree, stores:
|
||||
`rotation` plus `angle`, or minus it when only that one decomposes its
|
||||
transform with its flips. A mirror that flips after its turn turns the
|
||||
other way."
|
||||
other way. When neither does, as when the turn changes its flips, the
|
||||
rotation its transform decomposes into."
|
||||
[shape rotation angle]
|
||||
(let [{:keys [a b c d]} (or (:transform shape) (gmt/matrix))
|
||||
mirrored (not= (boolean (:flip-x shape)) (boolean (:flip-y shape)))
|
||||
@ -2044,9 +2045,16 @@
|
||||
(and (:flip-x shape) (:flip-y shape) (same? value (+ turn 180)))))
|
||||
plus (mod (+ rotation angle) 360)
|
||||
minus (mod (- rotation angle) 360)]
|
||||
(if (and (= mirrored (neg? (- (* a d) (* b c))))
|
||||
(not (stores? plus)) (stores? minus))
|
||||
(cond
|
||||
(and (= mirrored (neg? (- (* a d) (* b c))))
|
||||
(not (stores? plus)) (stores? minus))
|
||||
minus
|
||||
|
||||
;; a turn that drops or adds a flip leaves neither; the transform decides
|
||||
(and (not (stores? plus)) (not (stores? minus)))
|
||||
(mod turn 360)
|
||||
|
||||
:else
|
||||
plus)))
|
||||
|
||||
(defn orient-like
|
||||
|
||||
@ -1230,3 +1230,13 @@
|
||||
[:swap 2 0 0 0] [:duplicate 4 0 0 0] [:delete 8] [:restore 8] [:undo 0 0 0 0]
|
||||
[:text-style 4 0 1] [:delete 0 0 0 0] [:nest 21 0 0 0] [:duplicate 0 0 0 0]
|
||||
[:swap 16 0 0 0] [:switch 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest generated-switch-to-a-flipped-variant-stores-the-turn-its-transform-has
|
||||
;; a switch to a variant whose main is flipped keeps the copy's unflipped
|
||||
;; turn; the new head stores the rotation its transform decomposes into
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true
|
||||
:layout nil :layout-item-margins false :grid-square false :library-depth 2
|
||||
:library true :rich-variants true :layout-children false :library-text true
|
||||
:grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:library-transform 9 3 4 0] [:delete 5] [:restore 5] [:library-transform 9 4 0 0]
|
||||
[:library-transform 4 3 0 0] [:library-sync 0 0 0 0] [:switch 13 0 0 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user