mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Read whether a group mirrors from its transform when syncing
A group takes its bounds from its children and resets its flip flags while its transform keeps the mirror. Sync turns and flips the children of a copy shape like the shape, composing the flips of the copy and of its main through their flags, so a flipped group in a copy gave its children a mirroring transform stored as a half turn without flips. Sync reads whether a group or bool mirrors from its transform. Test: syncing-the-shapes-of-a-flipped-copy-group-keeps-them-flipped. The full common suite passes. Benchmark (alone, shared with the next commit): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 24.408 | 25.288 | 0.69 | | edit-through-a-chain-of-dependents | 68.931 | 49.305 | 51.709 | 0.72 | | library-update-into-copies | 83.083 | 57.405 | 59.433 | 0.69 | | main-edit-among-many-shapes | 4.837 | 2.779 | 2.943 | 0.57 | | main-edit-into-10-copies | 1.79 | 1.176 | 1.221 | 0.66 | | main-edit-into-100-copies | 15.415 | 11.968 | 13.13 | 0.78 | | main-edit-into-1000-copies | 153.086 | 121.213 | 125.656 | 0.79 | | variant-switch-into-copies | 32.052 | 24.938 | 26.57 | 0.78 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
310dac9e42
commit
2abe61e181
@ -2452,13 +2452,25 @@
|
||||
:else
|
||||
plus)))
|
||||
|
||||
(defn- flips
|
||||
"The flips of `shape`: its flags, or for a group or bool, which takes its
|
||||
bounds from its children and keeps no flags, whether its transform
|
||||
mirrors, as a horizontal flip."
|
||||
[shape]
|
||||
(if (#{:group :bool} (:type shape))
|
||||
(let [{:keys [a b c d]} (axes-matrix shape)]
|
||||
{:flip-x (neg? (- (* a d) (* b c))) :flip-y false})
|
||||
{:flip-x (boolean (:flip-x shape)) :flip-y (boolean (:flip-y shape))}))
|
||||
|
||||
(defn orient-like
|
||||
"Turn the subtree of `head` around `center` so its axes point like
|
||||
`target`'s; the lengths of the axes are left to constraints. Compose flip
|
||||
flags with the roots, independent of rotation step size."
|
||||
[head target center]
|
||||
(let [flip-x? (not= (boolean (:flip-x head)) (boolean (:flip-x target)))
|
||||
flip-y? (not= (boolean (:flip-y head)) (boolean (:flip-y target)))]
|
||||
(let [head-flips (flips head)
|
||||
target-flips (flips target)
|
||||
flip-x? (not= (:flip-x head-flips) (:flip-x target-flips))
|
||||
flip-y? (not= (:flip-y head-flips) (:flip-y target-flips))]
|
||||
(when-not (and (= (:transform head) (:transform target))
|
||||
(mth/close? (or (:rotation head) 0) (or (:rotation target) 0) 0.01)
|
||||
(not flip-x?) (not flip-y?))
|
||||
|
||||
@ -2472,6 +2472,11 @@
|
||||
:ops [[:remove-child 1] [:delete] [:apply-token 0 1] [:style 0 3 0 1] [:apply-token 1]
|
||||
[:token-value 0 1] [:switch]]}))))
|
||||
|
||||
(t/deftest syncing-the-shapes-of-a-flipped-copy-group-keeps-them-flipped
|
||||
(t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants true :text true :layout :flex
|
||||
:layout-copies false :layout-children true}]
|
||||
:ops [[:add-child 5] [:structure 12] [:transform 12 10 0 12]]}))))
|
||||
|
||||
(t/deftest settling-a-bool-in-a-grid-copy-twice-keeps-its-shapes-in-place
|
||||
(t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout :grid
|
||||
:layout-copies true :layout-children true}]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user