         (if (< max-error fit-error)
           [(adjust-bezier bezier coords params tan1 tan2
                           adjust-error max-adjust-iter)]
-          (let [center-tan (v2-center-tangent
-                             (nth coords (dec split-point))
-                             (nth coords split-point)
-                             (nth coords (inc split-point)))]
+          (let [[left-tan right-tan] (v2-center-tangents
+                                       (nth coords (dec split-point))
+                                       (nth coords split-point)
+                                       (nth coords (inc split-point)))]
             (vec (concat
                    (fit-cubic
-                     (subvec coords 0 (inc split-point)) tan1
-                     (v2-reverse center-tan))
+                     (subvec coords 0 (inc split-point)) tan1 left-tan)
                    (fit-cubic
-                      (subvec coords split-point) center-tan tan2)))))))))
+                      (subvec coords split-point) right-tan tan2)))))))))
 
 (defn path-length [coords]
   (first (reduce

(defn v2-tangent [a b]
  (v2-normalize (v2-sub a b)))

; computes the tangent of the center point b
; the direction is in the "rightwards" direction
(defn v2-center-tangent [a b c]
  (let [left-tan (v2-sub b a)
        right-tan (v2-sub c b)
        avg-tan (v2-add left-tan right-tan)]
    (v2-normalize avg-tan)))

(defn v2-dist [a b]
  (v2-mag (v2-sub a b)))


              newbezier (gen-bezier coords newparams tan1 tan2)]
          (recur newbezier newparams (inc i)))))))

; having duplicate adjacent points screws up the distance
; calculations, so we need to remove them before doing the fitting
(defn dedup-points [coords]
  (reduce (fn [result c]
            (if (= 0 (v2-dist (last result) c))
              result
              (conj result c)))
          [] coords))

(defn fit-cubic
  ([coords]
    (fit-cubic coords
