diff --git a/common/app/common/geom/shapes/common.cljc b/common/app/common/geom/shapes/common.cljc index ba3b83527..75ea7df5a 100644 --- a/common/app/common/geom/shapes/common.cljc +++ b/common/app/common/geom/shapes/common.cljc @@ -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)))) diff --git a/common/app/common/geom/shapes/rect.cljc b/common/app/common/geom/shapes/rect.cljc index bca71f3ad..330a54a8b 100644 --- a/common/app/common/geom/shapes/rect.cljc +++ b/common/app/common/geom/shapes/rect.cljc @@ -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)