   (swap-state! current-state #(-> %
                                   (update :camera-x + dx)
                                   (update :camera-y + dy))))
-
-;; Math
-
-(def sqrt (.-sqrt js/Math))
-
-(defn dist-sq [x y]
-  (+ (* x x) (* y y)))
-
-(def dist (comp sqrt dist-sq))
-
-(defn vector-with-length [l x y]
-  (let [factor (/ l (dist x y))]
-    [(* factor x) (* factor y)]))
 
 ;; Layout
 

    (add-background! svg width height)
    svg))

;; D3 magic

(defn view-position
  "Given the actual position of a node (in world coordinates), return the

  [state x y]
  (let [{:keys [view-width view-height camera-x camera-y]} state
        view-center-x (/ view-width 2)
        view-center-y (/ view-height 2)
        safe-distance-x (* safe-zone-size view-center-x)
        safe-distance-y (* safe-zone-size view-center-y)
        max-distance-x (- view-center-x edge-buffer)
        max-distance-y (- view-center-y edge-buffer)
        true-x-displacement (- x camera-x)
        true-y-displacement (- y camera-y)
        projected-x-displacement (project-displacement true-x-displacement
                                                       safe-distance-x
                                                       max-distance-x)
        projected-y-displacement (project-displacement true-y-displacement
                                                       safe-distance-y
                                                       max-distance-y)]
    {:x (+ view-center-x projected-x-displacement)
     :y (+ view-center-y projected-y-displacement)}))

(defn view-radius [state x y] 32)

