]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Tetrahedron.hs
Even more Tetrahedron de-dupe.
[spline3.git] / src / Tests / Tetrahedron.hs
1 module Tests.Tetrahedron
2 where
3
4 import Test.Framework (Test, testGroup)
5 import Test.Framework.Providers.HUnit (testCase)
6 import Test.HUnit
7 import Test.QuickCheck (Property, (==>))
8
9 import Cardinal
10 import Comparisons
11 import FunctionValues
12 import Tests.FunctionValues()
13 import Tetrahedron
14 import ThreeDimensional
15
16 -- HUnit Tests
17
18
19 -- | Check the volume of a particular tetrahedron (computed by hand)
20 -- and whether or not it contains a specific point chosen to be
21 -- outside of it. Its vertices are in clockwise order, so the volume
22 -- should be negative.
23 tetrahedron1_geometry_tests :: Test.Framework.Test
24 tetrahedron1_geometry_tests =
25 testGroup "tetrahedron1 geometry"
26 [ testCase "volume1" volume1,
27 testCase "doesn't contain point1" doesnt_contain_point1]
28 where
29 p0 = (0, -0.5, 0)
30 p1 = (0, 0.5, 0)
31 p2 = (2, 0, 0)
32 p3 = (1, 0, 1)
33 t = Tetrahedron { v0 = p0,
34 v1 = p1,
35 v2 = p2,
36 v3 = p3,
37 fv = empty_values }
38
39 volume1 :: Assertion
40 volume1 =
41 assertEqual "volume is correct" True (vol ~= (-1/3))
42 where
43 vol = volume t
44
45 doesnt_contain_point1 :: Assertion
46 doesnt_contain_point1 =
47 assertEqual "doesn't contain an exterior point" False contained
48 where
49 exterior_point = (5, 2, -9.0212)
50 contained = contains_point t exterior_point
51
52
53 -- | Check the volume of a particular tetrahedron (computed by hand)
54 -- and whether or not it contains a specific point chosen to be
55 -- inside of it. Its vertices are in counter-clockwise order, so the
56 -- volume should be positive.
57 tetrahedron2_geometry_tests :: Test.Framework.Test
58 tetrahedron2_geometry_tests =
59 testGroup "tetrahedron2 geometry"
60 [ testCase "volume1" volume1,
61 testCase "contains point1" contains_point1]
62 where
63 p0 = (0, -0.5, 0)
64 p1 = (2, 0, 0)
65 p2 = (0, 0.5, 0)
66 p3 = (1, 0, 1)
67 t = Tetrahedron { v0 = p0,
68 v1 = p1,
69 v2 = p2,
70 v3 = p3,
71 fv = empty_values }
72
73 volume1 :: Assertion
74 volume1 = assertEqual "volume1 is correct" True (vol ~= (1/3))
75 where
76 vol = volume t
77
78 contains_point1 :: Assertion
79 contains_point1 = assertEqual "contains an inner point" True contained
80 where
81 inner_point = (1, 0, 0.5)
82 contained = contains_point t inner_point
83
84
85 -- | Ensure that tetrahedra do not contain a particular point chosen to
86 -- be outside of them.
87 containment_tests :: Test.Framework.Test
88 containment_tests =
89 testGroup "containment tests"
90 [ testCase "doesn't contain point2" doesnt_contain_point2,
91 testCase "doesn't contain point3" doesnt_contain_point3,
92 testCase "doesn't contain point4" doesnt_contain_point4,
93 testCase "doesn't contain point5" doesnt_contain_point5]
94 where
95 p2 = (0.5, 0.5, 1)
96 p3 = (0.5, 0.5, 0.5)
97 exterior_point = (0, 0, 0)
98
99 doesnt_contain_point2 :: Assertion
100 doesnt_contain_point2 =
101 assertEqual "doesn't contain an exterior point" False contained
102 where
103 p0 = (0, 1, 1)
104 p1 = (1, 1, 1)
105 t = Tetrahedron { v0 = p0,
106 v1 = p1,
107 v2 = p2,
108 v3 = p3,
109 fv = empty_values }
110 contained = contains_point t exterior_point
111
112
113 doesnt_contain_point3 :: Assertion
114 doesnt_contain_point3 =
115 assertEqual "doesn't contain an exterior point" False contained
116 where
117 p0 = (1, 1, 1)
118 p1 = (1, 0, 1)
119 t = Tetrahedron { v0 = p0,
120 v1 = p1,
121 v2 = p2,
122 v3 = p3,
123 fv = empty_values }
124 contained = contains_point t exterior_point
125
126
127 doesnt_contain_point4 :: Assertion
128 doesnt_contain_point4 =
129 assertEqual "doesn't contain an exterior point" False contained
130 where
131 p0 = (1, 0, 1)
132 p1 = (0, 0, 1)
133 t = Tetrahedron { v0 = p0,
134 v1 = p1,
135 v2 = p2,
136 v3 = p3,
137 fv = empty_values }
138 contained = contains_point t exterior_point
139
140
141 doesnt_contain_point5 :: Assertion
142 doesnt_contain_point5 =
143 assertEqual "doesn't contain an exterior point" False contained
144 where
145 p0 = (0, 0, 1)
146 p1 = (0, 1, 1)
147 t = Tetrahedron { v0 = p0,
148 v1 = p1,
149 v2 = p2,
150 v3 = p3,
151 fv = empty_values }
152 contained = contains_point t exterior_point
153
154
155 -- | The barycentric coordinate of v0 with respect to itself should
156 -- be one.
157 prop_b0_v0_always_unity :: Tetrahedron -> Property
158 prop_b0_v0_always_unity t =
159 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
160
161 -- | The barycentric coordinate of v1 with respect to v0 should
162 -- be zero.
163 prop_b0_v1_always_zero :: Tetrahedron -> Property
164 prop_b0_v1_always_zero t =
165 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
166
167 -- | The barycentric coordinate of v2 with respect to v0 should
168 -- be zero.
169 prop_b0_v2_always_zero :: Tetrahedron -> Property
170 prop_b0_v2_always_zero t =
171 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
172
173 -- | The barycentric coordinate of v3 with respect to v0 should
174 -- be zero.
175 prop_b0_v3_always_zero :: Tetrahedron -> Property
176 prop_b0_v3_always_zero t =
177 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
178
179 -- | The barycentric coordinate of v1 with respect to itself should
180 -- be one.
181 prop_b1_v1_always_unity :: Tetrahedron -> Property
182 prop_b1_v1_always_unity t =
183 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
184
185 -- | The barycentric coordinate of v0 with respect to v1 should
186 -- be zero.
187 prop_b1_v0_always_zero :: Tetrahedron -> Property
188 prop_b1_v0_always_zero t =
189 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
190
191 -- | The barycentric coordinate of v2 with respect to v1 should
192 -- be zero.
193 prop_b1_v2_always_zero :: Tetrahedron -> Property
194 prop_b1_v2_always_zero t =
195 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
196
197 -- | The barycentric coordinate of v3 with respect to v1 should
198 -- be zero.
199 prop_b1_v3_always_zero :: Tetrahedron -> Property
200 prop_b1_v3_always_zero t =
201 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
202
203 -- | The barycentric coordinate of v2 with respect to itself should
204 -- be one.
205 prop_b2_v2_always_unity :: Tetrahedron -> Property
206 prop_b2_v2_always_unity t =
207 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
208
209 -- | The barycentric coordinate of v0 with respect to v2 should
210 -- be zero.
211 prop_b2_v0_always_zero :: Tetrahedron -> Property
212 prop_b2_v0_always_zero t =
213 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
214
215 -- | The barycentric coordinate of v1 with respect to v2 should
216 -- be zero.
217 prop_b2_v1_always_zero :: Tetrahedron -> Property
218 prop_b2_v1_always_zero t =
219 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
220
221 -- | The barycentric coordinate of v3 with respect to v2 should
222 -- be zero.
223 prop_b2_v3_always_zero :: Tetrahedron -> Property
224 prop_b2_v3_always_zero t =
225 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
226
227 -- | The barycentric coordinate of v3 with respect to itself should
228 -- be one.
229 prop_b3_v3_always_unity :: Tetrahedron -> Property
230 prop_b3_v3_always_unity t =
231 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
232
233 -- | The barycentric coordinate of v0 with respect to v3 should
234 -- be zero.
235 prop_b3_v0_always_zero :: Tetrahedron -> Property
236 prop_b3_v0_always_zero t =
237 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
238
239 -- | The barycentric coordinate of v1 with respect to v3 should
240 -- be zero.
241 prop_b3_v1_always_zero :: Tetrahedron -> Property
242 prop_b3_v1_always_zero t =
243 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
244
245 -- | The barycentric coordinate of v2 with respect to v3 should
246 -- be zero.
247 prop_b3_v2_always_zero :: Tetrahedron -> Property
248 prop_b3_v2_always_zero t =
249 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
250
251
252 -- | Used for convenience in the next few tests; not a test itself.
253 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
254 p t i j k l = (polynomial t) (xi t i j k l)
255
256 -- | Given in Sorokina and Zeilfelder, p. 78.
257 prop_c3000_identity :: Tetrahedron -> Property
258 prop_c3000_identity t =
259 (volume t) > 0 ==>
260 c t 3 0 0 0 ~= p t 3 0 0 0
261
262 -- | Given in Sorokina and Zeilfelder, p. 78.
263 prop_c2100_identity :: Tetrahedron -> Property
264 prop_c2100_identity t =
265 (volume t) > 0 ==>
266 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
267 where
268 term1 = (1/3)*(p t 0 3 0 0)
269 term2 = (5/6)*(p t 3 0 0 0)
270 term3 = 3*(p t 2 1 0 0)
271 term4 = (3/2)*(p t 1 2 0 0)
272
273 -- | Given in Sorokina and Zeilfelder, p. 78.
274 prop_c1110_identity :: Tetrahedron -> Property
275 prop_c1110_identity t =
276 (volume t) > 0 ==>
277 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
278 where
279 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
280 term2 = (9/2)*(p t 1 1 1 0)
281 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
282 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
283
284 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
285 prop_x_rotation_doesnt_affect_front t =
286 expr1 == expr2
287 where
288 fv0 = Tetrahedron.fv t
289 fv1 = rotate cwx (Tetrahedron.fv t)
290 expr1 = front fv0
291 expr2 = front fv1
292
293 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
294 prop_x_rotation_doesnt_affect_back t =
295 expr1 == expr2
296 where
297 fv0 = Tetrahedron.fv t
298 fv1 = rotate cwx (Tetrahedron.fv t)
299 expr1 = back fv0
300 expr2 = back fv1
301
302
303 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
304 prop_y_rotation_doesnt_affect_left t =
305 expr1 == expr2
306 where
307 fv0 = Tetrahedron.fv t
308 fv1 = rotate cwy (Tetrahedron.fv t)
309 expr1 = left fv0
310 expr2 = left fv1
311
312 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
313 prop_y_rotation_doesnt_affect_right t =
314 expr1 == expr2
315 where
316 fv0 = Tetrahedron.fv t
317 fv1 = rotate cwy (Tetrahedron.fv t)
318 expr1 = right fv0
319 expr2 = right fv1
320
321
322 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
323 prop_z_rotation_doesnt_affect_down t =
324 expr1 == expr2
325 where
326 fv0 = Tetrahedron.fv t
327 fv1 = rotate cwz (Tetrahedron.fv t)
328 expr1 = down fv0
329 expr2 = down fv1
330
331
332 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
333 prop_z_rotation_doesnt_affect_top t =
334 expr1 == expr2
335 where
336 fv0 = Tetrahedron.fv t
337 fv1 = rotate cwz (Tetrahedron.fv t)
338 expr1 = top fv0
339 expr2 = top fv1
340
341 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
342 prop_swapping_vertices_doesnt_affect_coefficients1 t =
343 c t 0 0 1 2 == c t' 0 0 1 2
344 where
345 t' = t { v0 = (v1 t), v1 = (v0 t) }
346
347 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
348 prop_swapping_vertices_doesnt_affect_coefficients2 t =
349 c t 0 1 1 1 == c t' 0 1 1 1
350 where
351 t' = t { v2 = (v3 t), v3 = (v2 t) }
352
353 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
354 prop_swapping_vertices_doesnt_affect_coefficients3 t =
355 c t 2 1 0 0 == c t' 2 1 0 0
356 where
357 t' = t { v2 = (v3 t), v3 = (v2 t) }
358
359 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
360 prop_swapping_vertices_doesnt_affect_coefficients4 t =
361 c t 2 0 0 1 == c t' 2 0 0 1
362 where
363 t' = t { v0 = (v3 t), v3 = (v0 t) }