#3: Massive changes, superstructure now kind-of works
More unit tests now, and they all pass. More work needed, but this is very promising.
This commit is contained in:
parent
f49a7495db
commit
f616992191
33 changed files with 1768 additions and 672 deletions
|
|
@ -1,46 +1,53 @@
|
|||
(ns walkmap.edge-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[walkmap.edge :refer :all]))
|
||||
[walkmap.edge :refer :all]
|
||||
[walkmap.vertex :refer [make-vertex]]))
|
||||
|
||||
(deftest edge-test
|
||||
(testing "identification of edges."
|
||||
(is (edge? {:start {:x 0.0 :y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}}) "It is.")
|
||||
(is (not (edge? {:start {:y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}})) "Start lacks :x key")
|
||||
(is (not (edge? {:start {:x nil :y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}})) "Start lacks :x value")
|
||||
(is (not (edge? {:begin {:x nil :y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}})) "Lacks start key")
|
||||
(is (not (edge? {:start {:x nil :y 0.0 :z 0.0} :finish {:x 3 :y 4 :z 0.0}})) "Lacks end key")
|
||||
(is (not (edge? {:start {:x "zero" :y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}})) "Value of x in start is not a number")
|
||||
(is (edge? {:start (make-vertex 0.0 0.0 0.0)
|
||||
:end (make-vertex 3 4 0.0)}) "It is.")
|
||||
(is (not (edge? {:start {:y 0.0 :z 0.0 :id 'foo}
|
||||
:end {:x 3 :y 4 :z 0.0 :id 'bar}})) "Start lacks :x key")
|
||||
(is (not (edge? {:start {:x nil :y 0.0 :z 0.0 :id 'foo}
|
||||
:end {:x 3 :y 4 :z 0.0 :id 'bar}})) "Start lacks :x value")
|
||||
(is (not (edge? {:begin {:x nil :y 0.0 :z 0.0 :id 'foo}
|
||||
:end {:x 3 :y 4 :z 0.0 :id 'bar}})) "Lacks start key")
|
||||
(is (not (edge? {:start {:x nil :y 0.0 :z 0.0 :id 'foo}
|
||||
:finish {:x 3 :y 4 :z 0.0 :id 'bar}})) "Lacks end key")
|
||||
(is (not (edge? {:start {:x "zero" :y 0.0 :z 0.0 :id 'foo}
|
||||
:end {:x 3 :y 4 :z 0.0 :id 'bar}})) "Value of x in start is not a number")
|
||||
))
|
||||
|
||||
(deftest length-test
|
||||
(testing "length of an edge"
|
||||
(is (= (length {:start {:x 0.0 :y 0.0 :z 0.0} :end {:x 3.0 :y 4.0 :z 0.0}}) 5.0))))
|
||||
(is (= (length {:start {:x 0.0 :y 0.0 :z 0.0 :id 'foo} :end {:x 3.0 :y 4.0 :z 0.0 :id 'bar}}) 5.0))))
|
||||
|
||||
(deftest unit-vector-test
|
||||
(testing "deriving the unit vector"
|
||||
(is (=
|
||||
(unit-vector {:start {:x 0.0 :y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}})
|
||||
(unit-vector {:start {:x 0.0 :y 0.0 :z 0.0 :id 'foo} :end {:x 3 :y 4 :z 0.0 :id 'bar}})
|
||||
{:x 0.6, :y 0.8, :z 0.0}))
|
||||
(is (=
|
||||
(unit-vector {:start {:x 1.0 :y 2.0 :z 3.5} :end {:x 4.0 :y 6.0 :z 3.5}})
|
||||
(unit-vector {:start {:x 1.0 :y 2.0 :z 3.5 :id 'foo} :end {:x 4.0 :y 6.0 :z 3.5 :id 'bar}})
|
||||
{:x 0.6, :y 0.8, :z 0.0}))))
|
||||
|
||||
(deftest parallel-test
|
||||
(testing "parallelism"
|
||||
(is (parallel? {:start {:x 0.0 :y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}}
|
||||
{:start {:x 1.0 :y 2.0 :z 3.5} :end {:x 4.0 :y 6.0 :z 3.5}})
|
||||
(is (parallel? {:start {:x 0.0 :y 0.0 :z 0.0 :id 'foo} :end {:x 3 :y 4 :z 0.0 :id 'bar}}
|
||||
{:start {:x 1.0 :y 2.0 :z 3.5 :id 'foo} :end {:x 4.0 :y 6.0 :z 3.5 :id 'bar}})
|
||||
"Should be")
|
||||
(is (not
|
||||
(parallel? {:start {:x 0.0 :y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}}
|
||||
{:start {:x 1.0 :y 2.0 :z 3.5} :end {:x 4.0 :y 6.0 :z 3.49}}))
|
||||
(parallel? {:start {:x 0.0 :y 0.0 :z 0.0 :id 'foo} :end {:x 3 :y 4 :z 0.0 :id 'bar}}
|
||||
{:start {:x 1.0 :y 2.0 :z 3.5 :id 'foo} :end {:x 4.0 :y 6.0 :z 3.49 :id 'bar}}))
|
||||
"Should not be!")))
|
||||
|
||||
(deftest collinear-test
|
||||
(testing "collinearity"
|
||||
(is (collinear? {:start {:x 0.0 :y 0.0 :z 0.0} :end {:x 3.0 :y 4.0 :z 0.0}}
|
||||
{:start {:x 3.0 :y 4.0 :z 0.0} :end {:x 9.0 :y 12.0 :z 0.0}})
|
||||
(is (collinear? {:start {:x 0.0 :y 0.0 :z 0.0 :id 'foo} :end {:x 3.0 :y 4.0 :z 0.0 :id 'bar}}
|
||||
{:start {:x 3.0 :y 4.0 :z 0.0 :id 'foo} :end {:x 9.0 :y 12.0 :z 0.0 :id 'bar}})
|
||||
"Should be")
|
||||
(is (not
|
||||
(collinear? {:start {:x 0.0 :y 0.0 :z 0.0} :end {:x 3 :y 4 :z 0.0}}
|
||||
{:start {:x 1.0 :y 2.0 :z 3.5} :end {:x 4.0 :y 6.0 :z 3.5}}))
|
||||
(collinear? {:start {:x 0.0 :y 0.0 :z 0.0 :id 'foo} :end {:x 3 :y 4 :z 0.0 :id 'bar}}
|
||||
{:start {:x 1.0 :y 2.0 :z 3.5 :id 'foo} :end {:x 4.0 :y 6.0 :z 3.5 :id 'bar}}))
|
||||
"Should not be!")))
|
||||
|
|
|
|||
96
test/walkmap/stl_test.clj
Normal file
96
test/walkmap/stl_test.clj
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
(ns walkmap.stl-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[walkmap.stl :refer :all]
|
||||
[walkmap.polygon :refer [polygon?]]
|
||||
[walkmap.vertex :refer [vertex?]]))
|
||||
|
||||
(deftest canonicalise-test
|
||||
(testing "Canonicalisation of objects read from STL: vertices."
|
||||
(is (vertex? (canonicalise {:x 3.0, :y 1.0, :z 1.0}))
|
||||
"Vertex: should have an `:id` and `:kind` = `:vertex`.")
|
||||
(is (= (:x (canonicalise {:x 3.0, :y 1.0, :z 1.0})) 3.0)
|
||||
"`:x` value should be unchanged.")
|
||||
(is (= (:y (canonicalise {:x 3.0, :y 1.0, :z 1.0})) 1.0)
|
||||
"`:y` value should be unchanged.")
|
||||
(is (= (:z (canonicalise {:x 3.0, :y 1.0, :z 1.0})) 1.0)
|
||||
"`:z` value should be unchanged.")
|
||||
(is (every?
|
||||
vertex?
|
||||
(canonicalise [{:x 3.0, :y 1.0, :z 1.0}
|
||||
{:x 2.0, :y 3.0, :z 1.0}
|
||||
{:x 0.0, :y 0.0, :z 1.0}]))
|
||||
"Vertices: should recurse."))
|
||||
(testing "Canonicalisation of objects read from STL: facets/polygons."
|
||||
(let [p {:normal {:x -0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 3.0, :y 1.0, :z 1.0}
|
||||
{:x 2.0, :y 3.0, :z 1.0}
|
||||
{:x 0.0, :y 0.0, :z 1.0}],
|
||||
:abc 0}
|
||||
p' (canonicalise p)]
|
||||
(is (polygon? p')
|
||||
"Polygon: should have an `:id` and `:kind` = `:polygon`.")
|
||||
(is (= (count (:vertices p)) (count (:vertices p')))
|
||||
"Number of vertices should not change")
|
||||
(map
|
||||
#(is (= (map % (:vertices p))(map % (:vertices p')))
|
||||
(str "Order of vertices should not change: " %))
|
||||
[:x :y :z]))
|
||||
(is (every?
|
||||
polygon?
|
||||
(canonicalise
|
||||
[{:normal {:x -0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 3.0, :y 1.0, :z 1.0}
|
||||
{:x 2.0, :y 3.0, :z 1.0}
|
||||
{:x 0.0, :y 0.0, :z 1.0}],
|
||||
:abc 0}
|
||||
{:normal {:x 0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 10.0, :y 4.0, :z 1.0}
|
||||
{:x 22.0, :y 3.0, :z 1.0}
|
||||
{:x 13.0, :y 5.0, :z 1.0}],
|
||||
:abc 0}
|
||||
{:normal {:x 0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 26.0, :y 46.0, :z 1.0}
|
||||
{:x 29.0, :y 49.0, :z 1.0}
|
||||
{:x 31.0, :y 61.0, :z 1.0}],
|
||||
:abc 0}
|
||||
{:normal {:x -0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 16.0, :y 33.0, :z 1.0}
|
||||
{:x 15.0, :y 35.0, :z 1.0}
|
||||
{:x 13.0, :y 32.0, :z 1.0}],
|
||||
:abc 0}
|
||||
{:normal {:x 0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 81.0, :y 0.0, :z 1.0}
|
||||
{:x 54.0, :y 27.0, :z 1.0}
|
||||
{:x 51.0, :y 20.0, :z 1.0}],
|
||||
:abc 0}]))
|
||||
"Facets/polygons: should recurse."))
|
||||
(testing "Canonicalisation of entire STL structure."
|
||||
(let [stl {:header "Dummy test STL",
|
||||
:count 5,
|
||||
:facets [{:normal {:x -0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 3.0, :y 1.0, :z 1.0}
|
||||
{:x 2.0, :y 3.0, :z 1.0}
|
||||
{:x 0.0, :y 0.0, :z 1.0}],
|
||||
:abc 0}
|
||||
{:normal {:x 0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 10.0, :y 4.0, :z 1.0}
|
||||
{:x 22.0, :y 3.0, :z 1.0}
|
||||
{:x 13.0, :y 5.0, :z 1.0}],
|
||||
:abc 0}
|
||||
{:normal {:x 0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 26.0, :y 46.0, :z 1.0}
|
||||
{:x 29.0, :y 49.0, :z 1.0}
|
||||
{:x 31.0, :y 61.0, :z 1.0}],
|
||||
:abc 0}
|
||||
{:normal {:x -0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 16.0, :y 33.0, :z 1.0}
|
||||
{:x 15.0, :y 35.0, :z 1.0}
|
||||
{:x 13.0, :y 32.0, :z 1.0}],
|
||||
:abc 0}
|
||||
{:normal {:x 0.0, :y 0.0, :z 1.0},
|
||||
:vertices [{:x 81.0, :y 0.0, :z 1.0}
|
||||
{:x 54.0, :y 27.0, :z 1.0}
|
||||
{:x 51.0, :y 20.0, :z 1.0}],
|
||||
:abc 0}]}
|
||||
stl' (canonicalise stl)]
|
||||
(is (stl? stl') "Stl: should have an `:id` and `:kind` = `:stl`."))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue