Work on routing.
This commit is contained in:
parent
f616992191
commit
f4ca49f11b
8 changed files with 130 additions and 74 deletions
|
|
@ -8,7 +8,7 @@
|
|||
[walkmap.vertex :refer [ensure3d vertex?]]))
|
||||
|
||||
(defn edge?
|
||||
"True if `o` satisfies the conditions for a path. A path shall be a map
|
||||
"True if `o` satisfies the conditions for a edge. An edge shall be a map
|
||||
having the keys `:start` and `:end`, such that the values of each of those
|
||||
keys shall be a vertex."
|
||||
[o]
|
||||
|
|
@ -19,7 +19,10 @@
|
|||
|
||||
(defn path->edges
|
||||
"if `o` is a path, a polygon, or a sequence of vertices, return a sequence of
|
||||
edges representing that path, polygon or sequence."
|
||||
edges representing that path, polygon or sequence.
|
||||
|
||||
Throws `IllegalArgumentException` if `o` is not a path, a polygon, or
|
||||
sequence of vertices."
|
||||
[o]
|
||||
(cond
|
||||
(seq? o)
|
||||
|
|
@ -34,7 +37,10 @@
|
|||
(path? o)
|
||||
(path->edges (:nodes o))
|
||||
(polygon? o)
|
||||
(path->edges (polygon->path o))))
|
||||
(path->edges (polygon->path o))
|
||||
:else
|
||||
(throw (IllegalArgumentException.
|
||||
"Not a path, polygon, or sequence of vertices!"))))
|
||||
|
||||
(defn length
|
||||
"Return the length of the edge `e`."
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
[org.clojars.smee.binary.core :as b]
|
||||
[taoensso.timbre :as l :refer [info error spy]]
|
||||
[walkmap.polygon :refer [polygon?]]
|
||||
[walkmap.vertex :refer [vertex-key]])
|
||||
[walkmap.vertex :refer [canonicalise-vertex]])
|
||||
(:import org.clojars.smee.binary.core.BinaryIO
|
||||
java.io.DataInput))
|
||||
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
:kind :polygon
|
||||
:vertices (canonicalise (:vertices o)))
|
||||
;; if it has a value for :x it's a vertex, but it doesn't yet conform to `vertex?`
|
||||
(:x o) (assoc o :kind :vertex :id (or (:id o) (vertex-key o)))
|
||||
(:x o) (canonicalise-vertex o)
|
||||
;; shouldn't happen
|
||||
:else o))
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
;; deep-merge doesn't merge sets, only maps; so at this
|
||||
;; stage we need to build a map.
|
||||
(assoc vi (:id v) (assoc current (:id o) (:id v))))
|
||||
(throw (Exception. "Not a vertex: " v)))
|
||||
(throw (Exception. (subs (str "No `:id` value: " o) 0 80))))
|
||||
(throw (IllegalArgumentException. "Not a vertex: " v)))
|
||||
(throw (IllegalArgumentException. (subs (str "No `:id` value: " o) 0 80))))
|
||||
;; it shouldn't actually be an error to try to index a vertex, but it
|
||||
;; also isn't useful to do so, so I'd be inclined to ignore it.
|
||||
(:vertex-index s)))
|
||||
|
|
@ -70,7 +70,5 @@
|
|||
(coll? o) (reduce u/deep-merge (map #(add-to-superstructure s %) o))
|
||||
(nil? o) o
|
||||
:else
|
||||
(throw (Exception. (str "Don't know how to index " (or (type o) "nil")))))))
|
||||
(throw (IllegalArgumentException. (str "Don't know how to index " (or (type o) "nil")))))))
|
||||
|
||||
(:vertex-index (add-to-superstructure (:facets (s/decode-binary-stl "resources/isle_of_man.stl"))))
|
||||
(s/decode-binary-stl "resources/isle_of_man.stl")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
(cond
|
||||
(and (:x o) (:y o) (:z o)) (keyword (str "vert{" (:x o) "|" (:y o) "|" (:z o) "}"))
|
||||
(and (:x o) (:y o)) (keyword (str "vert{" (:x o) "|" (:y o) "}"))
|
||||
:else (throw (Exception. "Not a vertex."))))
|
||||
:else (throw (IllegalArgumentException. "Not a vertex."))))
|
||||
|
||||
(defn vertex?
|
||||
"True if `o` satisfies the conditions for a vertex. That is, essentially,
|
||||
|
|
@ -40,6 +40,19 @@
|
|||
([x y z]
|
||||
(assoc (make-vertex x y) :z z)))
|
||||
|
||||
(defn canonicalise-vertex
|
||||
"If `o` is a map with numeric values for `:x`, `:y` and optionally `:z`,
|
||||
upgrade it to something we will recognise as a vertex."
|
||||
[o]
|
||||
(if
|
||||
(and
|
||||
(map? o)
|
||||
(number? (:x o))
|
||||
(number? (:y o))
|
||||
(or (nil? (:z o)) (number? (:z o))))
|
||||
(assoc o :kind :vertex :id (vertex-key o))
|
||||
(throw (IllegalArgumentException. "Not a vertex."))))
|
||||
|
||||
(def ensure3d
|
||||
"Given a vertex `o`, if `o` has a `:z` value, just return `o`; otherwise
|
||||
return a vertex like `o` but having thie `dflt` value as the value of its
|
||||
|
|
@ -52,7 +65,7 @@
|
|||
(ensure3d o 0.0))
|
||||
([o dflt]
|
||||
(cond
|
||||
(not (vertex? o)) (throw (Exception. "Not a vertex!"))
|
||||
(not (vertex? o)) (throw (IllegalArgumentException. "Not a vertex!"))
|
||||
(:z o) o
|
||||
:else (assoc o :z dflt))))))
|
||||
|
||||
|
|
@ -63,4 +76,4 @@
|
|||
(if
|
||||
(vertex? o)
|
||||
(assoc o :z 0.0)
|
||||
(throw (Exception. "Not a vertex!"))))))
|
||||
(throw (IllegalArgumentException. "Not a vertex!"))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue