001  (ns walkmap.utils
002    "Miscellaneous utility functions."
003    (:require [clojure.math.numeric-tower :as m]
004              [walkmap.path :as p]
005              [walkmap.polygon :as q]
006              [walkmap.vertex :as v]))
007  
008  (defn deep-merge
009    "Recursively merges maps. If vals are not maps, the last value wins."
010    ;; TODO: not my implementation, not sure I entirely trust it.
011    [& vals]
012    (if (every? map? vals)
013      (apply merge-with deep-merge vals)
014      (last vals)))
015  
016  (defn vertices
017    "If `o` is an object with vertices, return those vertices, else nil."
018    [o]
019    (cond
020      (v/vertex? o) (list o)
021      (q/polygon? o) (:vertices o)
022      (p/path? o) (:vertices o)))
023