                                        edges))
     (take 5 edges)))
 
+(defn find-junction-rooms [edges]
+  "Return 2 junction room centers. Candidate junction rooms have atleast 3 edges connected to them."
+  (let [counts (reduce (fn [m [from to]]
+                         (-> m
+                         (update from (fn [v] (inc (or v 0))))
+                         (update from (fn [v] (inc (or v 0))))))
+                       {}
+                       edges)
+       junctions (keys (into {} (filter (fn [[_ connections]] (> connections 2))
+                                        counts)))]
+    (println "junctions" junctions)
+    (set (take 2 junctions))))
+
 (defn vertical-or-horizontally-aligned?
   [& xys]
   (some (partial apply =) (apply map vector xys)))

    (= y max-y)
      :horizontal
    :else
      (assert false (format "Unknown wall type %d %d %d %d %d %d" min-x min-y max-x max-y x y))))

(defn multi-part-segment
  [from from-type to to-type]

        g            (graph-to-minimum-spanning-tree fcg)
        more-edges   (additional-edges min-width min-height room-centers g)
        g            (concat g more-edges)
        ;; set of room centers that are junction rooms
        junction-rooms (find-junction-rooms g)
        ;; merge room cells to canvas, skipping junction rooms
        cells        (reduce (fn [cells room-bound]
                               (println "room-bound" room-bound)
                               (if (contains? junction-rooms (room-bounds-to-center room-bound))
                                 cells
                                 (let [room-cellsxy (apply room-to-cellsxy room-bound)]
                                   (println "room-cellsxy" room-cellsxy)
                                   (apply merge-with-canvas cells room-cellsxy))))
                             (canvas width height)
                             room-bounds)
        ;; reduce over g, merging corridor cells to canvas
        cells        (reduce (fn [cells [start goal]]
                               (let [points (make-corridor-points cells room-centers-to-room-bounds junction-rooms start goal)]
                                 (println "corridor points" points)
                                 (apply merge-with-canvas cells (points-to-corridor points))))
                             cells
                             g)
        upstairs     (conj [(first room-centers)] {:type :up-stairs})
        downstairs   (conj [(last room-centers)] {:type :down-stairs})]
