                                  (contains? qs (:dest %)))
                           (:dest %)
                           %)))
-        with-qs (loop [f flat
+        plus-qs (loop [f flat
                        seg-c (first segment-containers)
                        layer []]
                   (if (empty? f)

                        (if (empty? (:segments seg-c))
                          (recur (rest f) seg-c (conj layer item))
                          (recur (rest f) (first segment-containers) (conj layer seg-c item)))))))]
    (assoc next-layer :with-qs with-qs)))


(defn ensure-alternating

  and then a separate algorithm that counts the crossings that result from the
  orderings on those two layers (step 5)."
  [next-layer]
  (->> (:plus-qs next-layer)
       (partition-by #(instance? SegmentContainer %))
       (mapcat (fn [items]
                 (if (instance? SegmentContainer (first items))
