001  (ns walkmap.path
002    "Essentially the specification for things we shall consider to be path."
003    (:require [walkmap.polygon :refer [polygon?]]
004              [walkmap.vertex :refer [vertex?]]))
005  
006  (defn path?
007    "True if `o` satisfies the conditions for a path. A path shall be a map
008    having the key `:nodes`, whose value shall be a sequence of vertices as
009    defined in `walkmap.vertex`."
010    [o]
011    (let
012      [v (:nodes o)]
013      (and
014        (seq? v)
015        (> (count v) 2)
016        (every? vertex? v))))
017  
018  (defn polygon->path
019    "If `o` is a polygon, return an equivalent path. What's different about
020    a path is that in polygons there is an implicit edge between the first
021    vertex and the last. In paths, there isn't, so we need to add that
022    edge explicitly.
023  
024    If `o` is not a polygon, will throw an exception."
025    [o]
026    (if
027      (polygon? o)
028      (assoc (dissoc o :vertices) :nodes (concat (:vertices o) (list (first (:vertices o)))))
029      (throw (Exception. "Not a polygon!"))))
030