diff --git a/.gitignore b/.gitignore index f747809..97b570a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,9 @@ resources/small_hill.svg s.edn .eastwood + +settlement_1.edn + +small_hill.edn + +small_hill.html diff --git a/docs/cloverage/index.html b/docs/cloverage/index.html index 93248aa..1c568a3 100644 --- a/docs/cloverage/index.html +++ b/docs/cloverage/index.html @@ -68,11 +68,11 @@ walkmap.path
249
17
-93.61 % + style="width:93.98496240601504%; + float:left;"> 250
16
+93.98 %
35
walkmap.polygon
328
338
131
-71.46 % +72.07 %
43
45
6
7
-87.50 % -1141356 +87.93 % +1181358 walkmap.read-svg
walkmap.stl
238
247
-49.07 % + style="width:49.361702127659576%; + float:left;"> 232
+50.64 %
43
walkmap.superstructure
272
257
107
-71.77 % +70.60 %
62
walkmap.svg
11
282
-3.75 % + style="width:95.78544061302682%; + float:left;"> 250
+4.21 %
8
walkmap.tag
178
+ float:left;"> 159
100.00 %
walkmap.utils
425
331
-56.22 % + style="width:99.86772486772487%; + float:left;"> 755
1
+99.87 %
25
4
7
-80.56 % + style="width:97.22222222222223%; + float:left;"> 35
1
+100.00 % 101936 walkmap.vertex
475
74
-86.52 % + style="width:89.45454545454545%; + float:left;"> 492
58
+89.45 %
60
11
62
10
2
-97.26 % -1501573 +97.30 % +1511574 Totals: -64.52 % +72.81 % -67.67 % +68.80 % diff --git a/docs/cloverage/walkmap/path.clj.html b/docs/cloverage/walkmap/path.clj.html index 907a2e7..4df3664 100644 --- a/docs/cloverage/walkmap/path.clj.html +++ b/docs/cloverage/walkmap/path.clj.html @@ -58,7 +58,7 @@ 018      [v (:vertices o)]
- + 019      (and
diff --git a/docs/cloverage/walkmap/polygon.clj.html b/docs/cloverage/walkmap/polygon.clj.html index c3b5f51..a7c5f47 100644 --- a/docs/cloverage/walkmap/polygon.clj.html +++ b/docs/cloverage/walkmap/polygon.clj.html @@ -166,185 +166,197 @@ 054    [& vertices]
- - 055    {:vertices (check-vertices vertices) + + 055    (if
- - 056     :walkmap.id/id (keyword (gensym "poly")) + + 056      (> (count vertices) 2) +
+ + 057      {:vertices (check-vertices vertices) +
+ + 058       :walkmap.id/id (keyword (gensym "poly"))
- 057     :kind :polygon}) + 059       :kind :polygon}
- - 058   + + 060      (throw (IllegalArgumentException. +
+ + 061               "A polygon must have at least 3 vertices.")))) +
+ + 062  
- 059  (defn rectangle + 063  (defn rectangle
- 060    "Return a rectangle, with edges aligned east-west and north-south, whose + 064    "Return a rectangle, with edges aligned east-west and north-south, whose
- 061    south-west corner is the vertex `vsw` and whose north-east corner is the + 065    south-west corner is the vertex `vsw` and whose north-east corner is the
- 062    vertex `vne`." + 066    vertex `vne`."
- 063    [vsw vne] + 067    [vsw vne]
- 064    ;; we can actually create any rectangle in the xy plane based on two opposite + 068    ;; we can actually create any rectangle in the xy plane based on two opposite
- 065    ;; corners, but the maths are a bit to advanced for me today. TODO: do it! + 069    ;; corners, but the maths are a bit to advanced for me today. TODO: do it!
- - 066    (let [vnw (vertex (:x (check-vertex vsw)) + + 070    (let [vnw (vertex (:x (check-vertex vsw))
- 067                      (:y (check-vertex vne)) + 071                      (:y (check-vertex vne))
- 068                      (/ (reduce + (map #(or (:z %) 0) [vsw vne])) 2)) + 072                      (/ (reduce + (map #(or (:z %) 0) [vsw vne])) 2))
- 069          vse (vertex (:x vne) + 073          vse (vertex (:x vne)
- - 070                      (:y vsw) + + 074                      (:y vsw)
- 071                      (/ (reduce + (map #(or (:z %) 0) [vsw vne])) 2))] + 075                      (/ (reduce + (map #(or (:z %) 0) [vsw vne])) 2))]
- 072      (t/tag (polygon vsw vnw vne vse) :rectangle))) + 076      (t/tag (polygon vsw vnw vne vse) :rectangle)))
- 073   + 077  
- 074  ;; (rectangle (vertex 1 2 3) (vertex 7 9 4)) + 078  ;; (rectangle (vertex 1 2 3) (vertex 7 9 4))
- 075   + 079  
- 076  (defn gradient + 080  (defn gradient
- 077    "Return a polygon like `triangle` but with a key `:gradient` whose value is a + 081    "Return a polygon like `triangle` but with a key `:gradient` whose value is a
- 078    unit vector representing the gradient across `triangle`." + 082    unit vector representing the gradient across `triangle`."
- 079    [triangle] + 083    [triangle]
- 080    (let [order (sort #(max (:z %1) (:z %2)) + 084    (let [order (sort #(max (:z %1) (:z %2))
- 081                      (:vertices (check-triangle triangle))) + 085                      (:vertices (check-triangle triangle)))
- 082          highest (first order) + 086          highest (first order)
- 083          lowest (last order)] + 087          lowest (last order)]
- 084       (assoc triangle :gradient (e/unit-vector (e/edge lowest highest))))) + 088       (assoc triangle :gradient (e/unit-vector (e/edge lowest highest)))))
- 085   + 089  
- 086  (defn triangle-centre + 090  (defn triangle-centre
- 087    "Return a canonicalised `facet` (i.e. a triangular polygon) with an added + 091    "Return a canonicalised `facet` (i.e. a triangular polygon) with an added
- 088    key `:centre` whose value represents the centre of this facet in 3 + 092    key `:centre` whose value represents the centre of this facet in 3
- 089    dimensions. This only works for triangles, so is here not in + 093    dimensions. This only works for triangles, so is here not in
- 090    `walkmap.polygon`. It is an error (although no exception is currently + 094    `walkmap.polygon`. It is an error (although no exception is currently
- 091    thrown) if the object past is not a triangular polygon." + 095    thrown) if the object past is not a triangular polygon."
- 092    [facet] + 096    [facet]
- 093    (let [vs (:vertices (check-triangle facet)) + 097    (let [vs (:vertices (check-triangle facet))
- 094          v1 (first vs) + 098          v1 (first vs)
- 095          opposite (e/edge (nth vs 1) (nth vs 2)) + 099          opposite (e/edge (nth vs 1) (nth vs 2))
- 096          oc (e/centre opposite)] + 100          oc (e/centre opposite)]
- 097        (assoc + 101        (assoc
- 098        facet + 102        facet
- 099        :centre + 103        :centre
- 100        (vertex + 104        (vertex
- 101          (+ (:x v1) (* (- (:x oc) (:x v1)) 2/3)) + 105          (+ (:x v1) (* (- (:x oc) (:x v1)) 2/3))
- 102          (+ (:y v1) (* (- (:y oc) (:y v1)) 2/3)) + 106          (+ (:y v1) (* (- (:y oc) (:y v1)) 2/3))
- 103          (+ (:z v1) (* (- (:z oc) (:z v1)) 2/3)))))) + 107          (+ (:z v1) (* (- (:z oc) (:z v1)) 2/3))))))
- 104   + 108  
- 105  (defn centre + 109  (defn centre
- 106    [poly] + 110    [poly]
- 107    (case (count (:vertices (check-polygon poly))) + 111    (case (count (:vertices (check-polygon poly)))
- 108      3 (triangle-centre poly) + 112      3 (triangle-centre poly)
- 109      ;; else + 113      ;; else
- 110      (throw + 114      (throw
- 111        (UnsupportedOperationException. + 115        (UnsupportedOperationException.
- 112          "The general case of centre for polygons is not yet implemented.")))) + 116          "The general case of centre for polygons is not yet implemented."))))
- 113   + 117  
- 114   + 118  
diff --git a/docs/cloverage/walkmap/stl.clj.html b/docs/cloverage/walkmap/stl.clj.html index 5240aa8..ff71dd2 100644 --- a/docs/cloverage/walkmap/stl.clj.html +++ b/docs/cloverage/walkmap/stl.clj.html @@ -550,7 +550,7 @@ 182    ([filename stl solidname]
- + 183     (l/debug "Solid name is " solidname)
diff --git a/docs/cloverage/walkmap/superstructure.clj.html b/docs/cloverage/walkmap/superstructure.clj.html index a83ad6d..229b2b9 100644 --- a/docs/cloverage/walkmap/superstructure.clj.html +++ b/docs/cloverage/walkmap/superstructure.clj.html @@ -355,7 +355,7 @@ 117    ([o s]
- + 118     (l/debug "Finding objects in:" o)
diff --git a/docs/cloverage/walkmap/svg.clj.html b/docs/cloverage/walkmap/svg.clj.html index c04a8b4..29fe91d 100644 --- a/docs/cloverage/walkmap/svg.clj.html +++ b/docs/cloverage/walkmap/svg.clj.html @@ -274,7 +274,7 @@ 090                   (:facets stl)))]
- + 091      (l/info "Generating SVG for " *preferred-svg-render* " renderer")
@@ -316,7 +316,7 @@ 104     (let [s (binary-stl-file->svg in-filename)]
- + 105       (l/info "Emitting SVG with " *preferred-svg-render* " renderer")
diff --git a/docs/cloverage/walkmap/tag.clj.html b/docs/cloverage/walkmap/tag.clj.html index d26ce5f..1a20e0b 100644 --- a/docs/cloverage/walkmap/tag.clj.html +++ b/docs/cloverage/walkmap/tag.clj.html @@ -118,7 +118,7 @@ 038    [object & tags]
- + 039    (l/debug "Tagging" (kind-type object) "with" tags)
diff --git a/docs/cloverage/walkmap/utils.clj.html b/docs/cloverage/walkmap/utils.clj.html index 84e02ec..1ed6104 100644 --- a/docs/cloverage/walkmap/utils.clj.html +++ b/docs/cloverage/walkmap/utils.clj.html @@ -61,7 +61,7 @@ 019    [s n]
- + 020    (if (and (string? s) (number? n) (> (count s) n))
@@ -91,7 +91,7 @@ 029    [object]
- + 030    (or (:kind object) (type object) "nil"))
@@ -104,7 +104,7 @@ 033    "True if numbers `n1`, `n2` are roughly equal; that is to say, equal to
- 034    within `tolerance` (defaults to one part in a million)." + 034    within `tolerance` (defaults to one part in one hundred thousand)."
035    ([n1 n2] @@ -116,7 +116,7 @@ 037       (let [m (m/abs (min n1 n2))
- 038             t (if (zero? m) 0.000001 (* 0.000001 m))] + 038             t (if (zero? m) 0.00001 (* 0.00001 m))]
039         (=ish n1 n2 t)) @@ -139,7 +139,7 @@ 045  
- + 046  (defmacro check-kind-type
@@ -163,7 +163,7 @@ 053    ([object expected]
- + 054     `(if-not (= (kind-type ~object) ~expected)
@@ -178,10 +178,10 @@ 058              " "
- + 059              ["Expected" ~expected "but found" (kind-type ~object)])))
- + 060        ~object))
@@ -211,7 +211,7 @@ 069  
- + 070  (defmacro check-kind-type-seq
@@ -235,7 +235,7 @@ 077    ([s expected]
- + 078    `(if-not (every? #(= (kind-type %) ~expected) ~s)
@@ -253,19 +253,19 @@ 083             ["Expected sequence of"
- + 084              ~expected
085              "but found ("
- + 086              (s/join ", " (remove #(= ~expected %) (map kind-type ~s)))
087              ")"])))
- + 088       ~s))
diff --git a/docs/cloverage/walkmap/vertex.clj.html b/docs/cloverage/walkmap/vertex.clj.html index b1ca90f..6495272 100644 --- a/docs/cloverage/walkmap/vertex.clj.html +++ b/docs/cloverage/walkmap/vertex.clj.html @@ -130,7 +130,7 @@ 042    [o]
- + 043    (and
@@ -139,7 +139,7 @@ 045      (:walkmap.id/id o)
- + 046      (number? (:x o))
@@ -205,13 +205,13 @@ 067    [v1 v2]
- + 068    (check-vertex v1)
069    (check-vertex v2)
- + 070    (every?
@@ -430,29 +430,32 @@ 142    [target minv maxv]
- - 143    (check-vertices [target minv maxv]) + + 143    (do +
+ + 144      (check-vertices [target minv maxv])
- 144    (every? + 145      (every?
- 145      true? + 146        true?
- 146      (map + 147        (map
- 147        #(if (% target) + 148          #(if (% target)
- 148           (<= (% minv) (% target) (% maxv)) + 149             (<= (% minv) (% target) (% maxv))
- 149           true) + 150             true)
- 150        [:x :y :z]))) + 151          [:x :y :z]))))
diff --git a/test/walkmap/utils_test.clj b/test/walkmap/utils_test.clj index 3a09b01..d2ce375 100644 --- a/test/walkmap/utils_test.clj +++ b/test/walkmap/utils_test.clj @@ -1,6 +1,7 @@ (ns walkmap.utils-test (:require [clojure.test :refer :all] - [walkmap.utils :refer :all])) + [walkmap.utils :refer :all] + [walkmap.vertex :refer [vertex vertex?]])) (deftest =ish-tests (testing "Rough equality" @@ -12,3 +13,88 @@ (is (=ish :foo :foo) "Fails over to plain old equals for non-numbers.") (is (=ish 6 5 10000) "If tolerance is wide enough, anything can be equal.") (is (not (=ish "hello" "goodbye" 10000)) "Well, except non-numbers, of course."))) + +(deftest truncate-tests + (testing "String truncation" + (is (= (truncate "The quick brown fox jumped over the lazy dog" 19) + "The quick brown fox") + "If it's a sting, and longer than the desired length, it should be + truncated.") + (is (= (truncate "The quick brown fox jumped over the lazy dog" 100) + "The quick brown fox jumped over the lazy dog") + "If it's a sting, and shorter than the desired length, it should not be + truncated.") + (is (= (truncate :the-quick-brown-fox 10) :the-quick-brown-fox) + "If it's not a string, it should not be truncated, regardless."))) + + +(deftest kind-type-tests + (testing "Type identification." + (is (= (kind-type {:kind :test}) :test) + "Maps with a value for `:kind` return that as their kind.") + (is (= (kind-type {:dnik :test}) clojure.lang.PersistentArrayMap) + "Maps with no value for `:kind` are just maps.") + (is (= (kind-type nil) "nil") + "As a special case, the kind of `nil` is the string \"nil\".") + (is (= (kind-type "Fred") java.lang.String) + "The kind-type of anything else is just its Java class."))) + +(deftest check-kind-type-tests + (testing "Exception thrown if kind not as expected." + (let [v {:kind :test}] + (is (= (check-kind-type v :test) v) + "If the check passes, the object is returned.")) + (let [v "test"] + (is (= (check-kind-type v java.lang.String) v) + "If the check passes, the object is returned.")) + (let [v "test"] + (is (= (check-kind-type v string? java.lang.String) v) + "If the check passes, the object is returned.")) + (let [v (vertex 1 1 1)] + (is (= (check-kind-type v :vertex) v) + "If the check passes, the object is returned.")) + (let [v (vertex 1 1 1)] + (is (= (check-kind-type v vertex? :vertex) v) + "If the check passes, the object is returned.")) + (let [v "test"] + (is (thrown? IllegalArgumentException + (check-kind-type v :test)) + "If the check doesn't pass, an exception is thrown.")) + (let [v {:kind :test}] + (is (thrown? IllegalArgumentException + (check-kind-type v vertex? :vertex)) + "If the check doesn't pass, an exception is thrown.")))) + +(deftest check-kind-type-seq-tests + (testing "Exception thrown if kind not as expected: sequence variant." + (let [v [{:kind :test} {:kind :test}]] + (is (= (check-kind-type-seq v :test) v) + "If the check passes, the object is returned.")) + (let [v (list "another" "test")] + (is (= (check-kind-type-seq v java.lang.String) v) + "If the check passes, the object is returned.")) + (let [v ["more" "test" "strings"]] + (is (= (check-kind-type-seq v string? java.lang.String) v) + "If the check passes, the object is returned.")) + (let [v (list (vertex 1 1 1) (vertex 2 2 2) (vertex 3 3 3))] + (is (= (check-kind-type-seq v :vertex) v) + "If the check passes, the object is returned.")) + (let [v (list (vertex 1 1 1))] + (is (= (check-kind-type-seq v vertex? :vertex) v) + "If the check passes, the object is returned.")) + (let [v :test] + (is (thrown? IllegalArgumentException + (check-kind-type-seq v :test)) + "If the arg isn't a sequence, an exception is thrown.")) + (let [v (list (vertex 1 1 1) "test" (vertex 3 3 3))] + (is (thrown? IllegalArgumentException + (check-kind-type-seq v :test)) + "If the check doesn't pass for any item, an exception is thrown.")) + (let [v (list (vertex 1 1 1) (vertex 2 2 2) "test")] + (is (thrown? IllegalArgumentException + (check-kind-type-seq v vertex? :vertex)) + "If the check doesn't pass, an exception is thrown.")))) + + + +