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