]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Grid.hs
Add a test: test_tetrahedra_collision_sensitivity.
[spline3.git] / src / Tests / Grid.hs
1 module Tests.Grid
2 where
3
4 import Data.Maybe (fromJust)
5 import Test.HUnit
6
7 import Assertions
8 import Comparisons
9 import Cube hiding (i, j, k)
10 import Examples
11 import FunctionValues (value_at)
12 import Grid
13 import Point (Point)
14 import Tetrahedron
15 import ThreeDimensional
16
17
18 -- | Check the value of c0030 for tetrahedron0 belonging to the
19 -- cube centered on (1,1,1) with a grid constructed from the
20 -- trilinear values. See example one in the paper.
21 test_trilinear_c0030 :: Assertion
22 test_trilinear_c0030 =
23 assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
24 where
25 g = make_grid 1 trilinear
26 cube = fromJust $ cube_at g 1 1 1
27 t = tetrahedron0 cube
28
29
30 -- | Check the value of c0003 for tetrahedron0 belonging to the
31 -- cube centered on (1,1,1) with a grid constructed from the
32 -- trilinear values. See example one in the paper.
33 test_trilinear_c0003 :: Assertion
34 test_trilinear_c0003 =
35 assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
36 where
37 g = make_grid 1 trilinear
38 cube = fromJust $ cube_at g 1 1 1
39 t = tetrahedron0 cube
40
41
42 -- | Check the value of c0021 for tetrahedron0 belonging to the
43 -- cube centered on (1,1,1) with a grid constructed from the
44 -- trilinear values. See example one in the paper.
45 test_trilinear_c0021 :: Assertion
46 test_trilinear_c0021 =
47 assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
48 where
49 g = make_grid 1 trilinear
50 cube = fromJust $ cube_at g 1 1 1
51 t = tetrahedron0 cube
52
53
54 -- | Check the value of c0012 for tetrahedron0 belonging to the
55 -- cube centered on (1,1,1) with a grid constructed from the
56 -- trilinear values. See example one in the paper.
57 test_trilinear_c0012 :: Assertion
58 test_trilinear_c0012 =
59 assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
60 where
61 g = make_grid 1 trilinear
62 cube = fromJust $ cube_at g 1 1 1
63 t = tetrahedron0 cube
64
65
66 -- | Check the value of c0120 for tetrahedron0 belonging to the
67 -- cube centered on (1,1,1) with a grid constructed from the
68 -- trilinear values. See example one in the paper.
69 test_trilinear_c0120 :: Assertion
70 test_trilinear_c0120 =
71 assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
72 where
73 g = make_grid 1 trilinear
74 cube = fromJust $ cube_at g 1 1 1
75 t = tetrahedron0 cube
76
77
78 -- | Check the value of c0102 for tetrahedron0 belonging to the
79 -- cube centered on (1,1,1) with a grid constructed from the
80 -- trilinear values. See example one in the paper.
81 test_trilinear_c0102 :: Assertion
82 test_trilinear_c0102 =
83 assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
84 where
85 g = make_grid 1 trilinear
86 cube = fromJust $ cube_at g 1 1 1
87 t = tetrahedron0 cube
88
89
90 -- | Check the value of c0111 for tetrahedron0 belonging to the
91 -- cube centered on (1,1,1) with a grid constructed from the
92 -- trilinear values. See example one in the paper.
93 test_trilinear_c0111 :: Assertion
94 test_trilinear_c0111 =
95 assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
96 where
97 g = make_grid 1 trilinear
98 cube = fromJust $ cube_at g 1 1 1
99 t = tetrahedron0 cube
100
101
102 -- | Check the value of c0210 for tetrahedron0 belonging to the
103 -- cube centered on (1,1,1) with a grid constructed from the
104 -- trilinear values. See example one in the paper.
105 test_trilinear_c0210 :: Assertion
106 test_trilinear_c0210 =
107 assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
108 where
109 g = make_grid 1 trilinear
110 cube = fromJust $ cube_at g 1 1 1
111 t = tetrahedron0 cube
112
113
114 -- | Check the value of c0201 for tetrahedron0 belonging to the
115 -- cube centered on (1,1,1) with a grid constructed from the
116 -- trilinear values. See example one in the paper.
117 test_trilinear_c0201 :: Assertion
118 test_trilinear_c0201 =
119 assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
120 where
121 g = make_grid 1 trilinear
122 cube = fromJust $ cube_at g 1 1 1
123 t = tetrahedron0 cube
124
125
126 -- | Check the value of c0300 for tetrahedron0 belonging to the
127 -- cube centered on (1,1,1) with a grid constructed from the
128 -- trilinear values. See example one in the paper.
129 test_trilinear_c0300 :: Assertion
130 test_trilinear_c0300 =
131 assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
132 where
133 g = make_grid 1 trilinear
134 cube = fromJust $ cube_at g 1 1 1
135 t = tetrahedron0 cube
136
137
138 -- | Check the value of c1020 for tetrahedron0 belonging to the
139 -- cube centered on (1,1,1) with a grid constructed from the
140 -- trilinear values. See example one in the paper.
141 test_trilinear_c1020 :: Assertion
142 test_trilinear_c1020 =
143 assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
144 where
145 g = make_grid 1 trilinear
146 cube = fromJust $ cube_at g 1 1 1
147 t = tetrahedron0 cube
148
149
150 -- | Check the value of c1002 for tetrahedron0 belonging to the
151 -- cube centered on (1,1,1) with a grid constructed from the
152 -- trilinear values. See example one in the paper.
153 test_trilinear_c1002 :: Assertion
154 test_trilinear_c1002 =
155 assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
156 where
157 g = make_grid 1 trilinear
158 cube = fromJust $ cube_at g 1 1 1
159 t = tetrahedron0 cube
160
161
162 -- | Check the value of c1011 for tetrahedron0 belonging to the
163 -- cube centered on (1,1,1) with a grid constructed from the
164 -- trilinear values. See example one in the paper.
165 test_trilinear_c1011 :: Assertion
166 test_trilinear_c1011 =
167 assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
168 where
169 g = make_grid 1 trilinear
170 cube = fromJust $ cube_at g 1 1 1
171 t = tetrahedron0 cube
172
173
174 -- | Check the value of c1110 for tetrahedron0 belonging to the
175 -- cube centered on (1,1,1) with a grid constructed from the
176 -- trilinear values. See example one in the paper.
177 test_trilinear_c1110 :: Assertion
178 test_trilinear_c1110 =
179 assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
180 where
181 g = make_grid 1 trilinear
182 cube = fromJust $ cube_at g 1 1 1
183 t = tetrahedron0 cube
184
185
186 -- | Check the value of c1101 for tetrahedron0 belonging to the
187 -- cube centered on (1,1,1) with a grid constructed from the
188 -- trilinear values. See example one in the paper.
189 test_trilinear_c1101 :: Assertion
190 test_trilinear_c1101 =
191 assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
192 where
193 g = make_grid 1 trilinear
194 cube = fromJust $ cube_at g 1 1 1
195 t = tetrahedron0 cube
196
197
198 -- | Check the value of c1200 for tetrahedron0 belonging to the
199 -- cube centered on (1,1,1) with a grid constructed from the
200 -- trilinear values. See example one in the paper.
201 test_trilinear_c1200 :: Assertion
202 test_trilinear_c1200 =
203 assertAlmostEqual "c1200 is correct" (c t 1 2 0 0) 3
204 where
205 g = make_grid 1 trilinear
206 cube = fromJust $ cube_at g 1 1 1
207 t = tetrahedron0 cube
208
209
210 -- | Check the value of c2010 for tetrahedron0 belonging to the
211 -- cube centered on (1,1,1) with a grid constructed from the
212 -- trilinear values. See example one in the paper.
213 test_trilinear_c2010 :: Assertion
214 test_trilinear_c2010 =
215 assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
216 where
217 g = make_grid 1 trilinear
218 cube = fromJust $ cube_at g 1 1 1
219 t = tetrahedron0 cube
220
221
222 -- | Check the value of c2001 for tetrahedron0 belonging to the
223 -- cube centered on (1,1,1) with a grid constructed from the
224 -- trilinear values. See example one in the paper.
225 test_trilinear_c2001 :: Assertion
226 test_trilinear_c2001 =
227 assertAlmostEqual "c2001 is correct" (c t 2 0 0 1) 4
228 where
229 g = make_grid 1 trilinear
230 cube = fromJust $ cube_at g 1 1 1
231 t = tetrahedron0 cube
232
233
234 -- | Check the value of c2100 for tetrahedron0 belonging to the
235 -- cube centered on (1,1,1) with a grid constructed from the
236 -- trilinear values. See example one in the paper.
237 test_trilinear_c2100 :: Assertion
238 test_trilinear_c2100 =
239 assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
240 where
241 g = make_grid 1 trilinear
242 cube = fromJust $ cube_at g 1 1 1
243 t = tetrahedron0 cube
244
245
246 -- | Check the value of c3000 for tetrahedron0 belonging to the
247 -- cube centered on (1,1,1) with a grid constructed from the
248 -- trilinear values. See example one in the paper.
249 test_trilinear_c3000 :: Assertion
250 test_trilinear_c3000 =
251 assertAlmostEqual "c3000 is correct" (c t 3 0 0 0) 4
252 where
253 g = make_grid 1 trilinear
254 cube = fromJust $ cube_at g 1 1 1
255 t = tetrahedron0 cube
256
257
258 -- | Make sure that v0 of tetrahedron0 belonging to the cube centered
259 -- on (1,1,1) with a grid constructed from the trilinear values
260 -- winds up in the right place. See example one in the paper.
261 test_trilinear_f0_t0_v0 :: Assertion
262 test_trilinear_f0_t0_v0 =
263 assertEqual "v0 is correct" (v0 t) (1, 1, 1)
264 where
265 g = make_grid 1 trilinear
266 cube = fromJust $ cube_at g 1 1 1
267 t = tetrahedron0 cube
268
269
270 -- | Make sure that v1 of tetrahedron0 belonging to the cube centered
271 -- on (1,1,1) with a grid constructed from the trilinear values
272 -- winds up in the right place. See example one in the paper.
273 test_trilinear_f0_t0_v1 :: Assertion
274 test_trilinear_f0_t0_v1 =
275 assertEqual "v1 is correct" (v1 t) (0.5, 1, 1)
276 where
277 g = make_grid 1 trilinear
278 cube = fromJust $ cube_at g 1 1 1
279 t = tetrahedron0 cube
280
281
282 -- | Make sure that v2 of tetrahedron0 belonging to the cube centered
283 -- on (1,1,1) with a grid constructed from the trilinear values
284 -- winds up in the right place. See example one in the paper.
285 test_trilinear_f0_t0_v2 :: Assertion
286 test_trilinear_f0_t0_v2 =
287 assertEqual "v2 is correct" (v2 t) (0.5, 0.5, 1.5)
288 where
289 g = make_grid 1 trilinear
290 cube = fromJust $ cube_at g 1 1 1
291 t = tetrahedron0 cube
292
293
294 -- | Make sure that v3 of tetrahedron0 belonging to the cube centered
295 -- on (1,1,1) with a grid constructed from the trilinear values
296 -- winds up in the right place. See example one in the paper.
297 test_trilinear_f0_t0_v3 :: Assertion
298 test_trilinear_f0_t0_v3 =
299 assertClose "v3 is correct" (v3 t) (0.5, 1.5, 1.5)
300 where
301 g = make_grid 1 trilinear
302 cube = fromJust $ cube_at g 1 1 1
303 t = tetrahedron0 cube
304
305
306 test_trilinear_reproduced :: Assertion
307 test_trilinear_reproduced =
308 assertTrue "trilinears are reproduced correctly" $
309 and [p (i', j', k') ~= value_at trilinear i j k
310 | i <- [0..2],
311 j <- [0..2],
312 k <- [0..2],
313 t <- tetrahedra c0,
314 let p = polynomial t,
315 let i' = fromIntegral i,
316 let j' = fromIntegral j,
317 let k' = fromIntegral k]
318 where
319 g = make_grid 1 trilinear
320 c0 = fromJust $ cube_at g 1 1 1
321
322
323 test_zeros_reproduced :: Assertion
324 test_zeros_reproduced =
325 assertTrue "the zero function is reproduced correctly" $
326 and [p (i', j', k') ~= value_at zeros i j k
327 | i <- [0..2],
328 j <- [0..2],
329 k <- [0..2],
330 let i' = fromIntegral i,
331 let j' = fromIntegral j,
332 let k' = fromIntegral k]
333 where
334 g = make_grid 1 zeros
335 c0 = fromJust $ cube_at g 1 1 1
336 t0 = tetrahedron0 c0
337 p = polynomial t0
338
339
340 -- | Make sure we can reproduce a 9x9x9 trilinear from the 3x3x3 one.
341 test_trilinear9x9x9_reproduced :: Assertion
342 test_trilinear9x9x9_reproduced =
343 assertTrue "trilinear 9x9x9 is reproduced correctly" $
344 and [p (i', j', k') ~= value_at trilinear9x9x9 i j k
345 | i <- [0..8],
346 j <- [0..8],
347 k <- [0..8],
348 t <- tetrahedra c0,
349 let p = polynomial t,
350 let i' = (fromIntegral i) * 0.5,
351 let j' = (fromIntegral j) * 0.5,
352 let k' = (fromIntegral k) * 0.5]
353 where
354 g = make_grid 1 trilinear
355 c0 = fromJust $ cube_at g 1 1 1
356
357
358 -- | The point 'p' in this test lies on the boundary of tetrahedra 12 and 15.
359 -- However, the 'contains_point' test fails due to some numerical innacuracy.
360 -- This bug should have been fixed by setting a positive tolerance level.
361 --
362 -- Example from before the fix:
363 --
364 -- > b0 (tetrahedron12 c) p
365 -- -2.168404344971019e-18
366 -- > b0 (tetrahedron15 c) p
367 -- -3.4694469519536365e-18
368 --
369 test_tetrahedra_collision_sensitivity :: Assertion
370 test_tetrahedra_collision_sensitivity =
371 assertTrue "tetrahedron collision tests aren't too sensitive" $
372 contains_point t12 p &&
373 contains_point t15 p
374 where
375 g = make_grid 1 trilinear
376 c = cube_at g 0 17 1
377 p = (0, 16.75, 0.5) :: Point
378 t12 = tetrahedron12 c
379 t15 = tetrahedron15 c