         (.map (constantly :scroll-end)))))
 
 (defn dampen [v]
-  (let [length (dist v)]
+  (let [length (vec-length v)]
     (vec-with-length v (- length swipe-damping-factor))))
 
 (defn swipe-displacements-observable [manager svg]

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


;; Vector math

(defn math-vec [x y] {:x x :y y})

(def sqrt (.-sqrt js/Math))

(defn dist-sq [v]
  (let [{:keys [x y]} v]
    (+ (* x x) (* y y))))

(def dist (comp sqrt dist-sq))

(defn add-vec [v1 v2]
  (merge-with + v1 v2))

  (scalar-multiply v -1))

(defn vec-with-length [v l]
  (scalar-multiply v (/ l (vec-length v))))

(def vec-distance (comp vec-length subtract-vec))

;; D3 magic

(defn scaled-distance-from-camera
  "Returns the distance of the given point from the camera, scaled so that
  points which would be at the corner of the screen are at distance 1"
  [state pos]
  (let [{:keys [camera-pos view-size]} state
        corner-distance (/ (vec-length view-size) 2)]
    (/ (vec-distance (:camera-pos state) pos) corner-distance)))

(defn elliptic-distance-from-camera [state pos]
  (let [{:keys [view-size camera-pos]} state
        rx (/ (:x view-size) 2)
        ry (/ (:y view-size) 2)
        sq (fn [x] (* x x))
        {:keys [x y]} (subtract-vec pos camera-pos)]
    (sqrt (+ (/ (sq x) (sq rx)) (/ (sq y) (sq ry))))))

(defn project-displacement [t]
  (cond
    (<= t 0.5) t
    (<= 0.5 t 1) (+ 0.5 (/ (- t 0.5) 2))
    (<= 1 t 1.5) (+ 0.75 (/ (- t 1) 4))
    (<= 1.5 t 2.5) (+ 0.875 (/ (- t 1.5) 8))
    (<= 2.5 t) 1))

(defn view-position [state pos]
  (let [{:keys [view-size camera-pos]} state
        view-center (scalar-multiply view-size 0.5)
        corner-distance (vec-length view-center)
        displacement (subtract-vec pos camera-pos)
        r (scaled-distance-from-camera state pos)
        projected-r (project-displacement r)]
    (add-vec view-center (scalar-multiply displacement
                                        (/ projected-r r)))))

(defn project-radius [t]
    (+ min-radius (* (- max-radius min-radius)
                     (min 1 (/ 1 (.pow js/Math 2 (* 2 (- t 0.25))))))))

(defn view-radius [state pos]
  (let [r (scaled-distance-from-camera state pos)]
    (project-radius r)))

(defn sync-graph! [state]
  (let [{:keys [svg nodes]} state
