     (match [last-type dir]
            [:h :level] (extend-h plots' dest-end-x)
            [_ :level] (conj plots' (h-to dest-end-x))
-           :else (plot-duration (into plots' (arcs-and-tangent pair-map))
+           :else (plot-duration (into plots' (arcs-and-tangent segment))
                                 dest-start-x dest-end-x))))
 
 

  (let [class-graphs (FlatGraph->ClassGraphs flat-graph)
        narrowest (apply min-key #(width % node-sep char-sep) class-graphs)
        narrow-min-y (min-y narrowest node-sep char-sep)
        narrow-max-y (max-y narrowest node-sep char-sep)]
    (->> class-graphs
         (map #(let [delta (if (:aligned-down (meta %))
                             (- narrow-max-y (max-y % node-sep char-sep))
                             (- narrow-min-y (min-y % node-sep char-sep)))]
                 (ys % node-sep char-sep delta)))
         (apply merge-with #(if (vector? %1) (conj %1 %2) [%1 %2]))
         (map (fn [[node ys]]
                (let [sort-ys (sort ys)]
                  [node (/ (+ (nth sort-ys 1) (nth sort-ys 2)) 2)])))
         (into {}))))


(defn arc-distance

    (+ arcs-x-dist tangent-x-dist)))


(defn arc-radius
  "Given node info map (must have :order) a min-arc-radius and the number of
  pixels characters should be separated by, and returns the radius of the arc
  for that node for that character"
  [{:keys [order]} min-arc-radius char-sep]
  {:pre [(integer? order) (every? number? [min-arc-radius char-sep])]}
  (+ min-arc-radius (* order char-sep)))


(defn arc-y-info
  "Returns the y values of the arc centers, as well as the radii for each arc
  for a character segment with endpoints on adjacent layers"
  [src dest dir min-arc-radius char-sep]
  {:pre [(contains? #{:up :down} dir)]}
  (let [src-arc-r (arc-radius src min-arc-radius char-sep)
        dest-arc-r (arc-radius dest min-arc-radius char-sep)
        [src-op dest-op] ({:up [- +] :down [+ -]} dir)]
    {:src-arc-radius src-arc-r
     :dest-arc-radius dest-arc-r
     :src-arc-y (src-op (:y src) src-arc-r)
     :dest-arc-y (dest-op (:y dest) dest-arc-r)}))


(defn add-y-info
  "Adds :arc-y and :arc-radius information to character segments, plus
  :total-arc-radius, for convenience"
  [char-segs min-arc-radius char-sep]
  (map (fn [{:keys [dir src dest], :as seg}]
         (if (= dir :level)
           seg
           (let [{:keys [src-arc-y dest-arc-y
                         src-arc-radius dest-arc-radius]}
                 (arc-y-info src dest dir min-arc-radius char-sep)]
             (-> seg
                 (assoc :total-arc-radius (+ src-arc-radius dest-arc-radius))
                 (assoc-in [:src :arc-y] src-arc-y)
                 (assoc-in [:src :arc-radius] src-arc-radius)
                 (assoc-in [:dest :arc-y] dest-arc-y)
                 (assoc-in [:dest :arc-radius] dest-arc-radius)))))
       char-segs))


(defn add-x-info
  "Adds :xs to character segments, and if the segment is not :level, also
  adds :arc-x for each segment"
  [char-segs layer-xs]
  (map (fn [{:keys [dir src dest], :as seg}]
         (let [src-xs (-> src :node :layer-id layer-xs)
               dest-xs (-> dest :node :layer-id layer-xs)
               seg' (-> seg
                        (assoc-in [:src :xs] src-xs)
                        (assoc-in [:dest :xs] dest-xs))]
           (if (= dir :level)
             seg'
             (-> seg'
                 (assoc-in [:src :arc-x] (src-xs 1))
                 (assoc-in [:dest :arc-x] (dest-xs 0))))))
       char-segs))


(defn pair-up
  "Given a list of character positions, pairs each with the one following for a
  representation of transistions between layers. Also adds information about
  the direction this segment goes."
  [infos]
  (->> (map vector infos (drop 1 infos))
       (reduce (fn [segments [src dest]]
                 (let [src-y (:y src)
                       dest-y (:y dest)]
                   (conj segments
                         {:dir (if (= src-y dest-y)
                                 :level
                                 (if (> src-y dest-y)
                                   :up
                                   :down))
                          :src src
                          :dest dest
                          :character (:character src)})))
               [])))


(defn relative-layer-xs
  "Generates a map of layers to the pixel distance to the preceding layer"
  [path-info layers max-slope layer-sep]
  (->> (vals path-info)
       (mapcat #(remove (fn [{:keys [dir]}] (= dir :level)) %))
       (reduce (fn [min-seps {:keys [dir total-arc-radius src dest]}]
                 (let [layer (get layers (-> dest
                                             :node
                                             :layer-id))
