                              (nth coords (inc split-point)))]
             (vec (concat
                    (fit-cubic
-                     (subvec coords 0 split-point) tan1
+                     (subvec coords 0 (inc split-point)) tan1
                      (v2-reverse center-tan))
                    (fit-cubic
                       (subvec coords split-point) center-tan tan2)))))))))

         coords params (range (count coords)))
    ; collect max and split-point
    (reduce (fn [[max-dist split-point :as res-pair] [i dist]]
              (if [>= dist max-dist] [dist i] res-pair))
            [0.0 (/ (count coords) 2)])))

(defn fit-cubic


; returns the unit vector corresponding to vector a
(defn v2-normalize [a]
  (when (and (= 0 (:x a)) (= 0 (:y a)))
    (.log js/console "Warning! Can't normalize zero vector"))
  (let [mag (v2-mag a)]
    (Coord. (/ (:x a) mag)
            (/ (:y a) mag))))
