0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

Reuse transducers on points->rect transformation.

This commit is contained in:
Andrey Antukh 2020-11-25 15:40:33 +01:00 committed by Hirunatan
parent be24e1fb71
commit 6c07cfcd25
2 changed files with 15 additions and 9 deletions

View file

@ -30,11 +30,16 @@
[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]
(let [minx (transduce (map :x) min ##Inf points)
miny (transduce (map :y) min ##Inf points)
maxx (transduce (map :x) max ##-Inf points)
maxy (transduce (map :y) max ##-Inf points)]
(let [ptx (into [] map-x-xf points)
pty (into [] map-y-xf points)
minx (reduce min ##Inf ptx)
miny (reduce min ##Inf pty)
maxx (reduce max ##-Inf ptx)
maxy (reduce max ##-Inf pty)]
(gpt/point (/ (+ minx maxx) 2)
(/ (+ miny maxy) 2))))

View file

@ -23,11 +23,12 @@
(gpt/point (+ x width) (+ y height))
(gpt/point x (+ y height))])
(defn points->rect [points]
(let [minx (transduce (comp (map :x) (remove nil?)) min ##Inf points)
miny (transduce (comp (map :y) (remove nil?)) min ##Inf points)
maxx (transduce (comp (map :x) (remove nil?)) max ##-Inf points)
maxy (transduce (comp (map :y) (remove nil?)) max ##-Inf points)]
(defn points->rect
[points]
(let [minx (transduce gco/map-x-xf min ##Inf points)
miny (transduce gco/map-y-xf min ##Inf points)
maxx (transduce gco/map-x-xf max ##-Inf points)
maxy (transduce gco/map-y-xf max ##-Inf points)]
{:x minx
:y miny
:width (- maxx minx)