]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Tetrahedron.hs
3d47862bf638e69aeb8296b3ef1c946b8a44218d
[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 a tetrahedron does not contain a particular point chosen to
86 -- be outside of it (second test).
87 test_doesnt_contain_point2 :: Assertion
88 test_doesnt_contain_point2 =
89 assertEqual "doesn't contain an exterior point" False contained
90 where
91 p0 = (0, 1, 1)
92 p1 = (1, 1, 1)
93 p2 = (0.5, 0.5, 1)
94 p3 = (0.5, 0.5, 0.5)
95 exterior_point = (0, 0, 0)
96 t = Tetrahedron { v0 = p0,
97 v1 = p1,
98 v2 = p2,
99 v3 = p3,
100 fv = empty_values }
101 contained = contains_point t exterior_point
102
103
104 -- | Ensure that a tetrahedron does not contain a particular point chosen to
105 -- be outside of it (third test).
106 test_doesnt_contain_point3 :: Assertion
107 test_doesnt_contain_point3 =
108 assertEqual "doesn't contain an exterior point" False contained
109 where
110 p0 = (1, 1, 1)
111 p1 = (1, 0, 1)
112 p2 = (0.5, 0.5, 1)
113 p3 = (0.5, 0.5, 0.5)
114 exterior_point = (0, 0, 0)
115 t = Tetrahedron { v0 = p0,
116 v1 = p1,
117 v2 = p2,
118 v3 = p3,
119 fv = empty_values }
120 contained = contains_point t exterior_point
121
122
123 -- | Ensure that a tetrahedron does not contain a particular point chosen to
124 -- be outside of it (fourth test).
125 test_doesnt_contain_point4 :: Assertion
126 test_doesnt_contain_point4 =
127 assertEqual "doesn't contain an exterior point" False contained
128 where
129 p0 = (1, 0, 1)
130 p1 = (0, 0, 1)
131 p2 = (0.5, 0.5, 1)
132 p3 = (0.5, 0.5, 0.5)
133 exterior_point = (0, 0, 0)
134 t = Tetrahedron { v0 = p0,
135 v1 = p1,
136 v2 = p2,
137 v3 = p3,
138 fv = empty_values }
139 contained = contains_point t exterior_point
140
141
142 -- | Ensure that a tetrahedron does not contain a particular point chosen to
143 -- be outside of it (fifth test).
144 test_doesnt_contain_point5 :: Assertion
145 test_doesnt_contain_point5 =
146 assertEqual "doesn't contain an exterior point" False contained
147 where
148 p0 = (0, 0, 1)
149 p1 = (0, 1, 1)
150 p2 = (0.5, 0.5, 1)
151 p3 = (0.5, 0.5, 0.5)
152 exterior_point = (0, 0, 0)
153 t = Tetrahedron { v0 = p0,
154 v1 = p1,
155 v2 = p2,
156 v3 = p3,
157 fv = empty_values }
158 contained = contains_point t exterior_point
159
160
161 -- | The barycentric coordinate of v0 with respect to itself should
162 -- be one.
163 prop_b0_v0_always_unity :: Tetrahedron -> Property
164 prop_b0_v0_always_unity t =
165 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
166
167 -- | The barycentric coordinate of v1 with respect to v0 should
168 -- be zero.
169 prop_b0_v1_always_zero :: Tetrahedron -> Property
170 prop_b0_v1_always_zero t =
171 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
172
173 -- | The barycentric coordinate of v2 with respect to v0 should
174 -- be zero.
175 prop_b0_v2_always_zero :: Tetrahedron -> Property
176 prop_b0_v2_always_zero t =
177 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
178
179 -- | The barycentric coordinate of v3 with respect to v0 should
180 -- be zero.
181 prop_b0_v3_always_zero :: Tetrahedron -> Property
182 prop_b0_v3_always_zero t =
183 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
184
185 -- | The barycentric coordinate of v1 with respect to itself should
186 -- be one.
187 prop_b1_v1_always_unity :: Tetrahedron -> Property
188 prop_b1_v1_always_unity t =
189 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
190
191 -- | The barycentric coordinate of v0 with respect to v1 should
192 -- be zero.
193 prop_b1_v0_always_zero :: Tetrahedron -> Property
194 prop_b1_v0_always_zero t =
195 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
196
197 -- | The barycentric coordinate of v2 with respect to v1 should
198 -- be zero.
199 prop_b1_v2_always_zero :: Tetrahedron -> Property
200 prop_b1_v2_always_zero t =
201 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
202
203 -- | The barycentric coordinate of v3 with respect to v1 should
204 -- be zero.
205 prop_b1_v3_always_zero :: Tetrahedron -> Property
206 prop_b1_v3_always_zero t =
207 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
208
209 -- | The barycentric coordinate of v2 with respect to itself should
210 -- be one.
211 prop_b2_v2_always_unity :: Tetrahedron -> Property
212 prop_b2_v2_always_unity t =
213 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
214
215 -- | The barycentric coordinate of v0 with respect to v2 should
216 -- be zero.
217 prop_b2_v0_always_zero :: Tetrahedron -> Property
218 prop_b2_v0_always_zero t =
219 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
220
221 -- | The barycentric coordinate of v1 with respect to v2 should
222 -- be zero.
223 prop_b2_v1_always_zero :: Tetrahedron -> Property
224 prop_b2_v1_always_zero t =
225 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
226
227 -- | The barycentric coordinate of v3 with respect to v2 should
228 -- be zero.
229 prop_b2_v3_always_zero :: Tetrahedron -> Property
230 prop_b2_v3_always_zero t =
231 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
232
233 -- | The barycentric coordinate of v3 with respect to itself should
234 -- be one.
235 prop_b3_v3_always_unity :: Tetrahedron -> Property
236 prop_b3_v3_always_unity t =
237 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
238
239 -- | The barycentric coordinate of v0 with respect to v3 should
240 -- be zero.
241 prop_b3_v0_always_zero :: Tetrahedron -> Property
242 prop_b3_v0_always_zero t =
243 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
244
245 -- | The barycentric coordinate of v1 with respect to v3 should
246 -- be zero.
247 prop_b3_v1_always_zero :: Tetrahedron -> Property
248 prop_b3_v1_always_zero t =
249 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
250
251 -- | The barycentric coordinate of v2 with respect to v3 should
252 -- be zero.
253 prop_b3_v2_always_zero :: Tetrahedron -> Property
254 prop_b3_v2_always_zero t =
255 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
256
257
258 -- | Used for convenience in the next few tests; not a test itself.
259 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
260 p t i j k l = (polynomial t) (xi t i j k l)
261
262 -- | Given in Sorokina and Zeilfelder, p. 78.
263 prop_c3000_identity :: Tetrahedron -> Property
264 prop_c3000_identity t =
265 (volume t) > 0 ==>
266 c t 3 0 0 0 ~= p t 3 0 0 0
267
268 -- | Given in Sorokina and Zeilfelder, p. 78.
269 prop_c2100_identity :: Tetrahedron -> Property
270 prop_c2100_identity t =
271 (volume t) > 0 ==>
272 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
273 where
274 term1 = (1/3)*(p t 0 3 0 0)
275 term2 = (5/6)*(p t 3 0 0 0)
276 term3 = 3*(p t 2 1 0 0)
277 term4 = (3/2)*(p t 1 2 0 0)
278
279 -- | Given in Sorokina and Zeilfelder, p. 78.
280 prop_c1110_identity :: Tetrahedron -> Property
281 prop_c1110_identity t =
282 (volume t) > 0 ==>
283 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
284 where
285 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
286 term2 = (9/2)*(p t 1 1 1 0)
287 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
288 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
289
290 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
291 prop_x_rotation_doesnt_affect_front t =
292 expr1 == expr2
293 where
294 fv0 = Tetrahedron.fv t
295 fv1 = rotate cwx (Tetrahedron.fv t)
296 expr1 = front fv0
297 expr2 = front fv1
298
299 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
300 prop_x_rotation_doesnt_affect_back t =
301 expr1 == expr2
302 where
303 fv0 = Tetrahedron.fv t
304 fv1 = rotate cwx (Tetrahedron.fv t)
305 expr1 = back fv0
306 expr2 = back fv1
307
308
309 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
310 prop_y_rotation_doesnt_affect_left t =
311 expr1 == expr2
312 where
313 fv0 = Tetrahedron.fv t
314 fv1 = rotate cwy (Tetrahedron.fv t)
315 expr1 = left fv0
316 expr2 = left fv1
317
318 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
319 prop_y_rotation_doesnt_affect_right t =
320 expr1 == expr2
321 where
322 fv0 = Tetrahedron.fv t
323 fv1 = rotate cwy (Tetrahedron.fv t)
324 expr1 = right fv0
325 expr2 = right fv1
326
327
328 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
329 prop_z_rotation_doesnt_affect_down t =
330 expr1 == expr2
331 where
332 fv0 = Tetrahedron.fv t
333 fv1 = rotate cwz (Tetrahedron.fv t)
334 expr1 = down fv0
335 expr2 = down fv1
336
337
338 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
339 prop_z_rotation_doesnt_affect_top t =
340 expr1 == expr2
341 where
342 fv0 = Tetrahedron.fv t
343 fv1 = rotate cwz (Tetrahedron.fv t)
344 expr1 = top fv0
345 expr2 = top fv1
346
347 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
348 prop_swapping_vertices_doesnt_affect_coefficients1 t =
349 c t 0 0 1 2 == c t' 0 0 1 2
350 where
351 t' = t { v0 = (v1 t), v1 = (v0 t) }
352
353 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
354 prop_swapping_vertices_doesnt_affect_coefficients2 t =
355 c t 0 1 1 1 == c t' 0 1 1 1
356 where
357 t' = t { v2 = (v3 t), v3 = (v2 t) }
358
359 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
360 prop_swapping_vertices_doesnt_affect_coefficients3 t =
361 c t 2 1 0 0 == c t' 2 1 0 0
362 where
363 t' = t { v2 = (v3 t), v3 = (v2 t) }
364
365 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
366 prop_swapping_vertices_doesnt_affect_coefficients4 t =
367 c t 2 0 0 1 == c t' 2 0 0 1
368 where
369 t' = t { v0 = (v3 t), v3 = (v0 t) }