mirror of
https://github.com/penpot/penpot.git
synced 2025-06-05 19:11:41 +02:00
✨ Reuse transducers on points->rect transformation.
This commit is contained in:
parent
be24e1fb71
commit
6c07cfcd25
2 changed files with 15 additions and 9 deletions
|
@ -30,11 +30,16 @@
|
||||||
[selrect]
|
[selrect]
|
||||||
(center-rect selrect))
|
(center-rect selrect))
|
||||||
|
|
||||||
|
(def map-x-xf (comp (map :x) (remove nil?)))
|
||||||
|
(def map-y-xf (comp (map :y) (remove nil?)))
|
||||||
|
|
||||||
(defn center-points [points]
|
(defn center-points [points]
|
||||||
(let [minx (transduce (map :x) min ##Inf points)
|
(let [ptx (into [] map-x-xf points)
|
||||||
miny (transduce (map :y) min ##Inf points)
|
pty (into [] map-y-xf points)
|
||||||
maxx (transduce (map :x) max ##-Inf points)
|
minx (reduce min ##Inf ptx)
|
||||||
maxy (transduce (map :y) max ##-Inf points)]
|
miny (reduce min ##Inf pty)
|
||||||
|
maxx (reduce max ##-Inf ptx)
|
||||||
|
maxy (reduce max ##-Inf pty)]
|
||||||
(gpt/point (/ (+ minx maxx) 2)
|
(gpt/point (/ (+ minx maxx) 2)
|
||||||
(/ (+ miny maxy) 2))))
|
(/ (+ miny maxy) 2))))
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,12 @@
|
||||||
(gpt/point (+ x width) (+ y height))
|
(gpt/point (+ x width) (+ y height))
|
||||||
(gpt/point x (+ y height))])
|
(gpt/point x (+ y height))])
|
||||||
|
|
||||||
(defn points->rect [points]
|
(defn points->rect
|
||||||
(let [minx (transduce (comp (map :x) (remove nil?)) min ##Inf points)
|
[points]
|
||||||
miny (transduce (comp (map :y) (remove nil?)) min ##Inf points)
|
(let [minx (transduce gco/map-x-xf min ##Inf points)
|
||||||
maxx (transduce (comp (map :x) (remove nil?)) max ##-Inf points)
|
miny (transduce gco/map-y-xf min ##Inf points)
|
||||||
maxy (transduce (comp (map :y) (remove nil?)) max ##-Inf points)]
|
maxx (transduce gco/map-x-xf max ##-Inf points)
|
||||||
|
maxy (transduce gco/map-y-xf max ##-Inf points)]
|
||||||
{:x minx
|
{:x minx
|
||||||
:y miny
|
:y miny
|
||||||
:width (- maxx minx)
|
:width (- maxx minx)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue