Work on routing.
This commit is contained in:
		
							parent
							
								
									f616992191
								
							
						
					
					
						commit
						f4ca49f11b
					
				|  | @ -104,16 +104,16 @@ | |||
| </tr> | ||||
| <tr> | ||||
|  <td><a href="walkmap/stl.clj.html">walkmap.stl</a></td><td class="with-bar"><div class="covered" | ||||
|                                 style="width:55.989583333333336%; | ||||
|                                         float:left;"> 215 </div><div class="not-covered" | ||||
|                                 style="width:44.010416666666664%; | ||||
|                                         float:left;"> 169 </div></td> | ||||
| <td class="with-number">55.99 %</td> | ||||
|                                 style="width:54.716981132075475%; | ||||
|                                         float:left;"> 203 </div><div class="not-covered" | ||||
|                                 style="width:45.283018867924525%; | ||||
|                                         float:left;"> 168 </div></td> | ||||
| <td class="with-number">54.72 %</td> | ||||
| <td class="with-bar"><div class="covered" | ||||
|                                 style="width:38.1578947368421%; | ||||
|                                         float:left;"> 29 </div><div class="partial" | ||||
|                                 style="width:13.157894736842104%; | ||||
|                                         float:left;"> 10 </div><div class="not-covered" | ||||
|                                 style="width:39.473684210526315%; | ||||
|                                         float:left;"> 30 </div><div class="partial" | ||||
|                                 style="width:11.842105263157896%; | ||||
|                                         float:left;"> 9 </div><div class="not-covered" | ||||
|                                 style="width:48.68421052631579%; | ||||
|                                         float:left;"> 37 </div></td> | ||||
| <td class="with-number">51.32 %</td> | ||||
|  | @ -170,26 +170,26 @@ | |||
| </tr> | ||||
| <tr> | ||||
|  <td><a href="walkmap/vertex.clj.html">walkmap.vertex</a></td><td class="with-bar"><div class="covered" | ||||
|                                 style="width:83.91959798994975%; | ||||
|                                         float:left;"> 167 </div><div class="not-covered" | ||||
|                                 style="width:16.08040201005025%; | ||||
|                                         float:left;"> 32 </div></td> | ||||
| <td class="with-number">83.92 %</td> | ||||
|                                 style="width:84.52380952380952%; | ||||
|                                         float:left;"> 213 </div><div class="not-covered" | ||||
|                                 style="width:15.476190476190476%; | ||||
|                                         float:left;"> 39 </div></td> | ||||
| <td class="with-number">84.52 %</td> | ||||
| <td class="with-bar"><div class="covered" | ||||
|                                 style="width:60.60606060606061%; | ||||
|                                         float:left;"> 20 </div><div class="partial" | ||||
|                                 style="width:21.21212121212121%; | ||||
|                                         float:left;"> 7 </div><div class="not-covered" | ||||
|                                 style="width:18.181818181818183%; | ||||
|                                         float:left;"> 6 </div></td> | ||||
| <td class="with-number">81.82 %</td> | ||||
| <td class="with-number">66</td><td class="with-number">7</td><td class="with-number">33</td> | ||||
|                                 style="width:64.28571428571429%; | ||||
|                                         float:left;"> 27 </div><div class="partial" | ||||
|                                 style="width:19.047619047619047%; | ||||
|                                         float:left;"> 8 </div><div class="not-covered" | ||||
|                                 style="width:16.666666666666668%; | ||||
|                                         float:left;"> 7 </div></td> | ||||
| <td class="with-number">83.33 %</td> | ||||
| <td class="with-number">79</td><td class="with-number">8</td><td class="with-number">42</td> | ||||
| </tr> | ||||
| <tr><td>Totals:</td> | ||||
| <td class="with-bar"></td> | ||||
| <td class="with-number">46.27 %</td> | ||||
| <td class="with-number">47.23 %</td> | ||||
| <td class="with-bar"></td> | ||||
| <td class="with-number">51.59 %</td> | ||||
| <td class="with-number">52.63 %</td> | ||||
|    </tr> | ||||
|   </table> | ||||
|  </body> | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ | |||
|                 008              [walkmap.polygon :refer [polygon?]] | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 009              [walkmap.vertex :refer [vertex-key]]) | ||||
|                 009              [walkmap.vertex :refer [canonicalise-vertex]]) | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 010    (:import org.clojars.smee.binary.core.BinaryIO | ||||
|  | @ -211,8 +211,8 @@ | |||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 069      ;; if it has a value for :x it's a vertex, but it doesn't yet conform to `vertex?` | ||||
|                 </span><br/> | ||||
| <span class="partial" title="18 out of 19 forms covered"> | ||||
|                 070      (:x o) (assoc o :kind :vertex :id (or (:id o) (vertex-key o))) | ||||
| <span class="covered" title="6 out of 6 forms covered"> | ||||
|                 070      (:x o) (canonicalise-vertex o) | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 071      ;; shouldn't happen | ||||
|  |  | |||
|  | @ -95,10 +95,10 @@ | |||
|                 030            (assoc vi (:id v) (assoc current (:id o) (:id v)))) | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 4 forms covered"> | ||||
|                 031          (throw (Exception. "Not a vertex: " v))) | ||||
|                 031          (throw (IllegalArgumentException. "Not a vertex: " v))) | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 10 forms covered"> | ||||
|                 032        (throw (Exception. (subs (str "No `:id` value: " o) 0 80)))) | ||||
|                 032        (throw (IllegalArgumentException. (subs (str "No `:id` value: " o) 0 80)))) | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 033      ;; it shouldn't actually be an error to try to index a vertex, but it | ||||
|  | @ -221,7 +221,7 @@ | |||
|                 072      :else | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 13 forms covered"> | ||||
|                 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"))))))) | ||||
|                 </span><br/> | ||||
| <span class="blank" title="0 out of 0 forms covered"> | ||||
|                 074   | ||||
|  |  | |||
|  | @ -38,7 +38,7 @@ | |||
|                 011      (and (:x o) (:y o)) (keyword (str "vert{" (:x o) "|" (:y o) "}")) | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 3 forms covered"> | ||||
|                 012      :else (throw (Exception. "Not a vertex.")))) | ||||
|                 012      :else (throw (IllegalArgumentException. "Not a vertex.")))) | ||||
|                 </span><br/> | ||||
| <span class="blank" title="0 out of 0 forms covered"> | ||||
|                 013   | ||||
|  | @ -131,76 +131,115 @@ | |||
|                 042   | ||||
|                 </span><br/> | ||||
| <span class="covered" title="1 out of 1 forms covered"> | ||||
|                 043  (def ensure3d | ||||
|                 043  (defn canonicalise-vertex | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 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`, | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 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." | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 046    `:z` key, or zero as the value of its `:z` key if `dflt` is not specified. | ||||
|                 </span><br/> | ||||
| <span class="blank" title="0 out of 0 forms covered"> | ||||
|                 047   | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 048    If `o` is not a vertex, throws an exception." | ||||
|                 </span><br/> | ||||
| <span class="covered" title="2 out of 2 forms covered"> | ||||
|                 049    (memoize | ||||
|                 046    [o] | ||||
|                 </span><br/> | ||||
| <span class="covered" title="1 out of 1 forms covered"> | ||||
|                 050      (fn | ||||
|                 047    (if | ||||
|                 </span><br/> | ||||
| <span class="partial" title="13 out of 17 forms covered"> | ||||
|                 048      (and | ||||
|                 </span><br/> | ||||
| <span class="covered" title="3 out of 3 forms covered"> | ||||
|                 049        (map? o) | ||||
|                 </span><br/> | ||||
| <span class="covered" title="5 out of 5 forms covered"> | ||||
|                 050        (number? (:x o)) | ||||
|                 </span><br/> | ||||
| <span class="covered" title="5 out of 5 forms covered"> | ||||
|                 051        (number? (:y o)) | ||||
|                 </span><br/> | ||||
| <span class="covered" title="9 out of 9 forms covered"> | ||||
|                 052        (or (nil? (:z o)) (number? (:z o)))) | ||||
|                 </span><br/> | ||||
| <span class="covered" title="9 out of 9 forms covered"> | ||||
|                 053      (assoc o :kind :vertex :id (vertex-key o)) | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 3 forms covered"> | ||||
|                 054      (throw (IllegalArgumentException. "Not a vertex.")))) | ||||
|                 </span><br/> | ||||
| <span class="blank" title="0 out of 0 forms covered"> | ||||
|                 055   | ||||
|                 </span><br/> | ||||
| <span class="covered" title="1 out of 1 forms covered"> | ||||
|                 056  (def ensure3d | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 051        ([o] | ||||
|                 057    "Given a vertex `o`, if `o` has a `:z` value, just return `o`; otherwise | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 058    return a vertex like `o` but having thie `dflt` value as the value of its | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 059    `:z` key, or zero as the value of its `:z` key if `dflt` is not specified. | ||||
|                 </span><br/> | ||||
| <span class="blank" title="0 out of 0 forms covered"> | ||||
|                 060   | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 061    If `o` is not a vertex, throws an exception." | ||||
|                 </span><br/> | ||||
| <span class="covered" title="2 out of 2 forms covered"> | ||||
|                 062    (memoize | ||||
|                 </span><br/> | ||||
| <span class="covered" title="1 out of 1 forms covered"> | ||||
|                 063      (fn | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 064        ([o] | ||||
|                 </span><br/> | ||||
| <span class="covered" title="4 out of 4 forms covered"> | ||||
|                 052         (ensure3d o 0.0)) | ||||
|                 065         (ensure3d o 0.0)) | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 053        ([o dflt] | ||||
|                 066        ([o dflt] | ||||
|                 </span><br/> | ||||
| <span class="partial" title="2 out of 3 forms covered"> | ||||
|                 054         (cond | ||||
|                 067         (cond | ||||
|                 </span><br/> | ||||
| <span class="partial" title="5 out of 8 forms covered"> | ||||
|                 055           (not (vertex? o)) (throw (Exception. "Not a vertex!")) | ||||
|                 068           (not (vertex? o)) (throw (IllegalArgumentException. "Not a vertex!")) | ||||
|                 </span><br/> | ||||
| <span class="covered" title="4 out of 4 forms covered"> | ||||
|                 056           (:z o) o | ||||
|                 069           (:z o) o | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 5 forms covered"> | ||||
|                 057           :else (assoc o :z dflt)))))) | ||||
|                 070           :else (assoc o :z dflt)))))) | ||||
|                 </span><br/> | ||||
| <span class="blank" title="0 out of 0 forms covered"> | ||||
|                 058   | ||||
|                 071   | ||||
|                 </span><br/> | ||||
| <span class="covered" title="1 out of 1 forms covered"> | ||||
|                 059  (def ensure2d | ||||
|                 072  (def ensure2d | ||||
|                 </span><br/> | ||||
| <span class="not-tracked" title="0 out of 0 forms covered"> | ||||
|                 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." | ||||
|                 </span><br/> | ||||
| <span class="covered" title="2 out of 2 forms covered"> | ||||
|                 061    (memoize | ||||
|                 074    (memoize | ||||
|                 </span><br/> | ||||
| <span class="covered" title="1 out of 1 forms covered"> | ||||
|                 062      (fn [o] | ||||
|                 075      (fn [o] | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 1 forms covered"> | ||||
|                 063        (if | ||||
|                 076        (if | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 3 forms covered"> | ||||
|                 064          (vertex? o) | ||||
|                 077          (vertex? o) | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 5 forms covered"> | ||||
|                 065          (assoc o :z 0.0) | ||||
|                 078          (assoc o :z 0.0) | ||||
|                 </span><br/> | ||||
| <span class="not-covered" title="0 out of 3 forms covered"> | ||||
|                 066          (throw (Exception. "Not a vertex!")))))) | ||||
|                 079          (throw (IllegalArgumentException. "Not a vertex!")))))) | ||||
|                 </span><br/> | ||||
|  </body> | ||||
| </html> | ||||
|  |  | |||
|  | @ -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…
	
		Reference in a new issue