mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 09:42:01 +00:00
🐛 Place a tiny swapped head at the first corner of its turned place
A sync places a swapped copy head where the shape it replaces would be. When both are turned alike, it lines up their first corners; otherwise it lines up the corners of their unrotated rectangles. Two transforms counted as turned alike only when their matrices were close, and the transform of a head at the 0.01 px minimum size scales its axes by its rounding (0.706 for 0.707). So a tiny head in a turned copy was placed by the unrotated corner of a 100 px board, and its selrect ended 50 px away from its own corners. The placement compares the directions of the transforms' axes, without their lengths, as the sync of a parent's descendants already does. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.375 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 39.744 | 0.58 | | library-update-into-copies | 83.083 | 49.053 | 0.59 | | main-edit-among-many-shapes | 4.837 | 2.269 | 0.47 | | main-edit-into-10-copies | 1.79 | 1.082 | 0.60 | | main-edit-into-100-copies | 15.415 | 9.911 | 0.64 | | main-edit-into-1000-copies | 153.086 | 95.772 | 0.63 | | variant-switch-into-copies | 32.052 | 21.539 | 0.67 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
5077c22ab9
commit
5da7886351
@ -585,6 +585,15 @@
|
||||
(grc/rect->center (:selrect (get objects (:id shape-main)))))]
|
||||
(reduce #(update %1 %2 gsh/move delta) objects ids)))
|
||||
|
||||
(defn- axes-matrix
|
||||
"The directions of the axes of the transform of `shape`, without their
|
||||
lengths: the transform of a tiny shape scales them by its rounding."
|
||||
[shape]
|
||||
(let [{:keys [a b c d]} (or (:transform shape) (gmt/matrix))
|
||||
horizontal (gpt/unit (gpt/point a b))
|
||||
vertical (gpt/unit (gpt/point c d))]
|
||||
(gmt/matrix (:x horizontal) (:y horizontal) (:x vertical) (:y vertical) 0 0)))
|
||||
|
||||
(defn- sync-descendant-orientation
|
||||
"A parent turned or moved by sync carries its whole subtree, including
|
||||
geometry overrides. Resize remains the job of constraints, not matrix
|
||||
@ -606,11 +615,7 @@
|
||||
ids (when changed? (cfh/get-children-ids (:objects container) (:id before)))]
|
||||
(if (seq ids)
|
||||
(let [orientation (fn [shape]
|
||||
(let [{:keys [a b c d]} (or (:transform shape) (gmt/matrix))
|
||||
horizontal (gpt/unit (gpt/point a b))
|
||||
vertical (gpt/unit (gpt/point c d))
|
||||
matrix (gmt/matrix (:x horizontal) (:y horizontal)
|
||||
(:x vertical) (:y vertical) 0 0)]
|
||||
(let [matrix (axes-matrix shape)]
|
||||
(assoc shape :transform matrix :transform-inverse (gmt/inverse matrix))))
|
||||
turn (orient-like (orientation before) (orientation after) (gsh/shape->center before))
|
||||
delta (gpt/subtract (gsh/shape->center after) (gsh/shape->center before))
|
||||
@ -1708,8 +1713,8 @@
|
||||
oriented (cond-> shape-inst (some? orient) (orient))
|
||||
;; turned alike, both take their place at their first corner
|
||||
turned? (and (some? (:transform placed))
|
||||
(not (gmt/unit? (:transform placed)))
|
||||
(gmt/close? (:transform placed) (or (:transform oriented) (gmt/matrix))))
|
||||
(not (gmt/unit? (axes-matrix placed)))
|
||||
(gmt/close? (axes-matrix placed) (axes-matrix oriented)))
|
||||
position (fn [shape]
|
||||
(or (when turned? (first (:points shape)))
|
||||
(gpt/point (dm/get-in shape [:selrect :x])
|
||||
|
||||
@ -1116,3 +1116,12 @@
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:text 14 0 0 0] [:nest 0 0 0 0] [:transform 0 0 0 18] [:swap 12 0 0 0]]}))))
|
||||
|
||||
(t/deftest a-swapped-minimum-size-head-takes-the-first-corner-of-its-turned-place
|
||||
;; a 0.01 px head swapped into a turned copy; its transform is noisy at
|
||||
;; that size, and it still takes the first corner of the place it fills
|
||||
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout nil :variant-diff false
|
||||
:layout-item-margins false :grid-square true :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:delete 5 0 0 0] [:swap 4 0 0 0] [:nest 0 0 0 0] [:duplicate 1 0 0 0]
|
||||
[:rotate 1 0 0 0] [:resize 1 0 0 0] [:rotate 4 0 2 0] [:update-main 0 0 0 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user