Move some functions from data.workspace to shapes ns.

This commit is contained in:
Andrey Antukh 2016-01-22 19:35:13 +02:00
parent 8284f0141c
commit a2da98f7ab
2 changed files with 31 additions and 21 deletions

View file

@ -106,27 +106,6 @@
(update-in state [:workspace :selected] disj id)
(update-in state [:workspace :selected] conj id))))))
(defn contained-in-selrect?
[shape selrect]
(let [sx1 (:x selrect)
sx2 (+ sx1 (:width selrect))
sy1 (:y selrect)
sy2 (+ sy1 (:height selrect))
rx1 (:x shape)
rx2 (+ rx1 (:width shape))
ry1 (:y shape)
ry2 (+ ry1 (:height shape))]
(and (neg? (- (:y selrect) (:y shape)))
(neg? (- (:x selrect) (:x shape)))
(pos? (- (+ (:y selrect)
(:height selrect))
(+ (:y shape)
(:height shape))))
(pos? (- (+ (:x selrect)
(:width selrect))
(+ (:x shape)
(:width shape)))))))
(defn select-shapes
"Select shapes that matches the select rect."
[selrect]

View file

@ -164,3 +164,34 @@
:y (:y result)))
shape))
(defn resolve-parent
"Recursively resolve the real shape parent."
[{:keys [group] :as shape}]
(if group
(resolve-parent (get-in @st/state [:shapes-by-id group]))
shape))
(defn contained-in?
"Check if a shape is contained in the
provided selection rect."
[shape selrect]
(let [sx1 (:x selrect)
sx2 (+ sx1 (:width selrect))
sy1 (:y selrect)
sy2 (+ sy1 (:height selrect))
rx1 (:x shape)
rx2 (+ rx1 (:width shape))
ry1 (:y shape)
ry2 (+ ry1 (:height shape))]
(and (neg? (- (:y selrect) (:y shape)))
(neg? (- (:x selrect) (:x shape)))
(pos? (- (+ (:y selrect)
(:height selrect))
(+ (:y shape)
(:height shape))))
(pos? (- (+ (:x selrect)
(:width selrect))
(+ (:x shape)
(:width shape)))))))