 (defn rect [tl dims]
   {:pre [(p>= dims [0 0])]}
   (->Rect tl dims))
+
+(defn p-inside? [p b]
+  (let [tl (-top-left b)
+        br (-bottom-right b)]
+    (and (p<= tl p)
+         (p>= br p))))
+
+(defn b-inside? [b1 b2]
+  (let [tl (-top-left b1)
+        br (-bottom-right b1)]
+    (and (p-inside? b2 tl)
+         (p-inside? b2 br))))
+
+(defn inside? [x b]
+  (cond
+   (point? x) (p-inside? x b)
+   (box? x) (b-inside? x b)
+   :else false))
+
+(defn corners [b]
+  [(-top-left b)
+   (-top-right b)
+   (-bottom-right b)
+   (-bottom-left b)])
+
+(defn intersects? [b1 b2]
+  (->> b2
+       corners
+       (some #(inside? % b1))
+       some?))

(ns clj.brutha.geo
  (:require [brutha.math :refer [sqrt]]))

(defprotocol IPos
  (-x [p])
  (-y [p])
  (-vec [p]))

(defrecord Point [x y]
  IPos
  (-x [_]
    x)
  (-y [_]


(defprotocol IBox
  (-top-left [b])
  (-top-right [b])
  (-bottom-left [b])
  (-bottom-right [b])
  (-dims [b])
  (-center [b]))

(defn box? [b]
  (satisfies? IBox b))

(defrecord Box [tl br]
  IBox
