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