001  (ns walkmap.utils
002    "Miscellaneous utility functions."
003    (:require [walkmap.path :as p]
004              [walkmap.polygon :as q]
005              [walkmap.vertex :as v]))
006  
007  (defn deep-merge
008    "Recursively merges maps. If vals are not maps, the last value wins."
009    ;; TODO: not my implementation, not sure I entirely trust it.
010    [& vals]
011    (if (every? map? vals)
012      (apply merge-with deep-merge vals)
013      (last vals)))
014  
015  (defn vertices
016    "If `o` is an object with vertices, return those vertices, else nil."
017    ;; TODO: it's possibly a design mistake that I'm currently distinguishing
018    ;; between polygons and paths on the basis that one has `:vertices` and
019    ;; the other has `:nodes`. Possibly it would be better to have a key
020    ;; `:closed` which was `true` for polygons, `false` (or missing) for
021    ;; paths.
022    [o]
023    (cond
024      (v/vertex? o) (list o)
025      (q/polygon? o) (:vertices o)
026      (p/path? o) (:nodes o)))