mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
📎 Reorient a pushed geometry by the turn its rotation stores
The model of an update main turns the pushed geometry of a copy shape out of the orientation its copy root or parent inherits. A mirrored shape can store the opposite of its transform's turn as its rotation, and the model turned that stored value as if it were the turn: a Board storing 315 with a vertical flip, inside a copy root turned 45, was expected at 270 in the main, where its transform is unturned. The pushed geometry is now reoriented with the turn sign of the copy shape, as the model already does for a parent's orientation. Harness only; the benchmark is not run. Also in this commit: - Leave shapes below an authored swap out of a switch's old copy map. The switch model matches each old copy shape with its path in the old main by its ref chain. A swapped Board whose component holds a copy of the switched copy's own component reaches the old main's root through that nested copy, so the nested copy took the root's path and its turn override replaced the root's. The shapes below an authored swap belong to the swapped component and are left out of the map. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
58ee5519d3
commit
8161f15015
@ -447,13 +447,15 @@
|
||||
main-root (get before (:shape-ref root))
|
||||
root-parent (get before (:parent-id root))
|
||||
main-parent (get before (:parent-id main-root) {})
|
||||
;; the way the rotation of `shape` stores its turn
|
||||
sign (geom/turn-sign shape)
|
||||
;; the turn the copy root inherits places it and is not pushed
|
||||
geometry (cond-> (values shape :geometry-group)
|
||||
(and (:component-root root) (not (get-in model [root-id :geometry-group])))
|
||||
(in-orientation root main-root)
|
||||
(in-orientation root main-root sign)
|
||||
|
||||
(and (not (:component-root root)) root-parent)
|
||||
(in-orientation root-parent main-parent))
|
||||
(in-orientation root-parent main-parent sign))
|
||||
replaced (when (and (contains? groups :swap-group)
|
||||
(not= (:shape-ref shape) (:shape-ref updated)))
|
||||
(get before (:shape-ref shape)))
|
||||
@ -638,9 +640,17 @@
|
||||
;; and authored overrides belong to its own component.
|
||||
(when (= root-id (:id original))
|
||||
[(get objects main-id) (get model root-id)]))))
|
||||
;; the shapes below an authored swap, which belong to the swapped component
|
||||
swapped-below (into #{}
|
||||
(comp (filter #(and (not= root-id (:id %))
|
||||
(contains? (get model (:id %)) :swap-group)))
|
||||
(mapcat #(rest (subtree-shapes before (:id %))))
|
||||
(map :id))
|
||||
(subtree-shapes before root-id))
|
||||
old-copies (into {} (keep (fn [shape]
|
||||
(when-let [[main groups] (source before old-paths old-main-id shape)]
|
||||
[(get old-paths (:id main)) [shape main groups]])))
|
||||
(when-not (contains? swapped-below (:id shape))
|
||||
(when-let [[main groups] (source before old-paths old-main-id shape)]
|
||||
[(get old-paths (:id main)) [shape main groups]]))))
|
||||
(subtree-shapes before root-id))
|
||||
;; the rotation a clean copy of the new main takes in the root's parent
|
||||
placed-rotation (let [main (get after new-main-id)]
|
||||
|
||||
@ -2072,6 +2072,15 @@
|
||||
: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 updating-a-main-from-a-turned-copy-unturns-a-mirrored-swap-by-its-own-turn
|
||||
(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 false}]
|
||||
:ops [[:combine] [:make-variant] [:swap 4] [:add-variant 20] [:make-variant]
|
||||
[:text-style 6 0 1] [:make-variant] [:switch] [:update-main] [:make-variant]
|
||||
[:switch 8] [:switch 18] [:rotate 3] [:make-variant] [:resize 14]
|
||||
[:add-variant 15] [:transform 5 5 0 18] [:update-main 20] [:update-main]]}))))
|
||||
|
||||
(t/deftest switching-a-text-with-a-typography-file-but-no-typography-carries-no-override
|
||||
(t/is (map? (cg/run {:world [1 0 {:variants true :text-styles false :layout :grid :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
@ -2079,6 +2088,13 @@
|
||||
:ops [[:text-style 3 8 1] [:text-style 3 1] [:nest] [:switch] [:text-style 0 8 1]
|
||||
[:switch 1]]}))))
|
||||
|
||||
(t/deftest switching-a-copy-holding-a-turned-copy-of-itself-in-a-swap-carries-no-turn
|
||||
(t/is (map? (cg/run {:world [1 0 {: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 false}]
|
||||
:ops [[:detach 2] [:switch 8] [:text 4] [:switch] [:nest 2] [:rotate] [:switch]
|
||||
[:combine] [:switch 2]]}))))
|
||||
|
||||
(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