diff --git a/docs/cloverage/index.html b/docs/cloverage/index.html index f066158..fcfdf92 100644 --- a/docs/cloverage/index.html +++ b/docs/cloverage/index.html @@ -104,16 +104,16 @@ walkmap.stl
215
169
-55.99 % + style="width:54.716981132075475%; + float:left;"> 203
168
+54.72 %
29
10
30
9
37
51.32 % @@ -170,26 +170,26 @@ walkmap.vertex
167
32
-83.92 % + style="width:84.52380952380952%; + float:left;"> 213
39
+84.52 %
20
7
6
-81.82 % -66733 + style="width:64.28571428571429%; + float:left;"> 27
8
7
+83.33 % +79842 Totals: -46.27 % +47.23 % -51.59 % +52.63 % diff --git a/docs/cloverage/walkmap/stl.clj.html b/docs/cloverage/walkmap/stl.clj.html index 2c577c0..e6cd3a5 100644 --- a/docs/cloverage/walkmap/stl.clj.html +++ b/docs/cloverage/walkmap/stl.clj.html @@ -29,7 +29,7 @@ 008              [walkmap.polygon :refer [polygon?]]
- 009              [walkmap.vertex :refer [vertex-key]]) + 009              [walkmap.vertex :refer [canonicalise-vertex]])
010    (:import org.clojars.smee.binary.core.BinaryIO @@ -211,8 +211,8 @@ 069      ;; if it has a value for :x it's a vertex, but it doesn't yet conform to `vertex?`
- - 070      (:x o) (assoc o :kind :vertex :id (or (:id o) (vertex-key o))) + + 070      (:x o) (canonicalise-vertex o)
071      ;; shouldn't happen diff --git a/docs/cloverage/walkmap/superstructure.clj.html b/docs/cloverage/walkmap/superstructure.clj.html index 27266ac..fe56429 100644 --- a/docs/cloverage/walkmap/superstructure.clj.html +++ b/docs/cloverage/walkmap/superstructure.clj.html @@ -95,10 +95,10 @@ 030            (assoc vi (:id v) (assoc current (:id o) (:id v))))
- 031          (throw (Exception. "Not a vertex: " v))) + 031          (throw (IllegalArgumentException. "Not a vertex: " v)))
- 032        (throw (Exception. (subs (str "No `:id` value: " o) 0 80)))) + 032        (throw (IllegalArgumentException. (subs (str "No `:id` value: " o) 0 80))))
033      ;; it shouldn't actually be an error to try to index a vertex, but it @@ -221,7 +221,7 @@ 072      :else
- 073      (throw (Exception. (str "Don't know how to index " (or (type o) "nil"))))))) + 073      (throw (IllegalArgumentException. (str "Don't know how to index " (or (type o) "nil")))))))
074   diff --git a/docs/cloverage/walkmap/vertex.clj.html b/docs/cloverage/walkmap/vertex.clj.html index 538fa98..3ba073f 100644 --- a/docs/cloverage/walkmap/vertex.clj.html +++ b/docs/cloverage/walkmap/vertex.clj.html @@ -38,7 +38,7 @@ 011      (and (:x o) (:y o)) (keyword (str "vert{" (:x o) "|" (:y o) "}"))
- 012      :else (throw (Exception. "Not a vertex.")))) + 012      :else (throw (IllegalArgumentException. "Not a vertex."))))
013   @@ -131,76 +131,115 @@ 042  
- 043  (def ensure3d + 043  (defn canonicalise-vertex
- 044    "Given a vertex `o`, if `o` has a `:z` value, just return `o`; otherwise + 044    "If `o` is a map with numeric values for `:x`, `:y` and optionally `:z`,
- 045    return a vertex like `o` but having thie `dflt` value as the value of its + 045    upgrade it to something we will recognise as a vertex."
- 046    `:z` key, or zero as the value of its `:z` key if `dflt` is not specified. -
- - 047   -
- - 048    If `o` is not a vertex, throws an exception." -
- - 049    (memoize + 046    [o]
- 050      (fn + 047    (if +
+ + 048      (and +
+ + 049        (map? o) +
+ + 050        (number? (:x o)) +
+ + 051        (number? (:y o)) +
+ + 052        (or (nil? (:z o)) (number? (:z o)))) +
+ + 053      (assoc o :kind :vertex :id (vertex-key o)) +
+ + 054      (throw (IllegalArgumentException. "Not a vertex.")))) +
+ + 055   +
+ + 056  (def ensure3d
- 051        ([o] + 057    "Given a vertex `o`, if `o` has a `:z` value, just return `o`; otherwise +
+ + 058    return a vertex like `o` but having thie `dflt` value as the value of its +
+ + 059    `:z` key, or zero as the value of its `:z` key if `dflt` is not specified. +
+ + 060   +
+ + 061    If `o` is not a vertex, throws an exception." +
+ + 062    (memoize +
+ + 063      (fn +
+ + 064        ([o]
- 052         (ensure3d o 0.0)) + 065         (ensure3d o 0.0))
- 053        ([o dflt] + 066        ([o dflt]
- 054         (cond + 067         (cond
- 055           (not (vertex? o)) (throw (Exception. "Not a vertex!")) + 068           (not (vertex? o)) (throw (IllegalArgumentException. "Not a vertex!"))
- 056           (:z o) o + 069           (:z o) o
- 057           :else (assoc o :z dflt)))))) + 070           :else (assoc o :z dflt))))))
- 058   + 071  
- 059  (def ensure2d + 072  (def ensure2d
- 060    "If `o` is a vertex, set its `:z` value to zero; else throw an exception." + 073    "If `o` is a vertex, set its `:z` value to zero; else throw an exception."
- 061    (memoize + 074    (memoize
- 062      (fn [o] + 075      (fn [o]
- 063        (if + 076        (if
- 064          (vertex? o) + 077          (vertex? o)
- 065          (assoc o :z 0.0) + 078          (assoc o :z 0.0)
- 066          (throw (Exception. "Not a vertex!")))))) + 079          (throw (IllegalArgumentException. "Not a vertex!"))))))
diff --git a/src/walkmap/edge.clj b/src/walkmap/edge.clj index 9f50281..356414b 100644 --- a/src/walkmap/edge.clj +++ b/src/walkmap/edge.clj @@ -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`." diff --git a/src/walkmap/stl.clj b/src/walkmap/stl.clj index fee15e3..accbb09 100644 --- a/src/walkmap/stl.clj +++ b/src/walkmap/stl.clj @@ -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)) diff --git a/src/walkmap/superstructure.clj b/src/walkmap/superstructure.clj index 80a514a..b41c459 100644 --- a/src/walkmap/superstructure.clj +++ b/src/walkmap/superstructure.clj @@ -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") diff --git a/src/walkmap/vertex.clj b/src/walkmap/vertex.clj index 4c60945..6a01de2 100644 --- a/src/walkmap/vertex.clj +++ b/src/walkmap/vertex.clj @@ -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!"))))))