4 find_containing_tetrahedron,
10 import Data.Maybe (fromJust)
11 import qualified Data.Vector as V (
20 import Prelude hiding (LT)
21 import Test.Framework (Test, testGroup)
22 import Test.Framework.Providers.QuickCheck2 (testProperty)
23 import Test.QuickCheck (Arbitrary(..), Gen, Positive(..), choose)
26 import Comparisons ((~=), (~~=))
27 import qualified Face (Face(Face, v0, v1, v2, v3))
29 import Misc (all_equal, disjoint)
31 import Tetrahedron (Tetrahedron(..), c, volume)
32 import ThreeDimensional
34 data Cube = Cube { h :: Double,
39 tetrahedra_volume :: Double }
43 instance Arbitrary Cube where
45 (Positive h') <- arbitrary :: Gen (Positive Double)
46 i' <- choose (coordmin, coordmax)
47 j' <- choose (coordmin, coordmax)
48 k' <- choose (coordmin, coordmax)
49 fv' <- arbitrary :: Gen FunctionValues
50 (Positive tet_vol) <- arbitrary :: Gen (Positive Double)
51 return (Cube h' i' j' k' fv' tet_vol)
53 coordmin = -268435456 -- -(2^29 / 2)
54 coordmax = 268435456 -- +(2^29 / 2)
57 instance Show Cube where
59 "Cube_" ++ subscript ++ "\n" ++
60 " h: " ++ (show (h cube)) ++ "\n" ++
61 " Center: " ++ (show (center cube)) ++ "\n" ++
62 " xmin: " ++ (show (xmin cube)) ++ "\n" ++
63 " xmax: " ++ (show (xmax cube)) ++ "\n" ++
64 " ymin: " ++ (show (ymin cube)) ++ "\n" ++
65 " ymax: " ++ (show (ymax cube)) ++ "\n" ++
66 " zmin: " ++ (show (zmin cube)) ++ "\n" ++
67 " zmax: " ++ (show (zmax cube)) ++ "\n" ++
68 " fv: " ++ (show (Cube.fv cube)) ++ "\n"
71 (show (i cube)) ++ "," ++ (show (j cube)) ++ "," ++ (show (k cube))
74 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
76 xmin :: Cube -> Double
77 xmin cube = (i' - 1/2)*delta
79 i' = fromIntegral (i cube) :: Double
82 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
84 xmax :: Cube -> Double
85 xmax cube = (i' + 1/2)*delta
87 i' = fromIntegral (i cube) :: Double
90 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
92 ymin :: Cube -> Double
93 ymin cube = (j' - 1/2)*delta
95 j' = fromIntegral (j cube) :: Double
98 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
100 ymax :: Cube -> Double
101 ymax cube = (j' + 1/2)*delta
103 j' = fromIntegral (j cube) :: Double
106 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
108 zmin :: Cube -> Double
109 zmin cube = (k' - 1/2)*delta
111 k' = fromIntegral (k cube) :: Double
114 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
116 zmax :: Cube -> Double
117 zmax cube = (k' + 1/2)*delta
119 k' = fromIntegral (k cube) :: Double
122 instance ThreeDimensional Cube where
123 -- | The center of Cube_ijk coincides with v_ijk at
124 -- (ih, jh, kh). See Sorokina and Zeilfelder, p. 76.
125 center cube = (x, y, z)
128 i' = fromIntegral (i cube) :: Double
129 j' = fromIntegral (j cube) :: Double
130 k' = fromIntegral (k cube) :: Double
135 -- | It's easy to tell if a point is within a cube; just make sure
136 -- that it falls on the proper side of each of the cube's faces.
137 contains_point cube (x, y, z)
138 | x < (xmin cube) = False
139 | x > (xmax cube) = False
140 | y < (ymin cube) = False
141 | y > (ymax cube) = False
142 | z < (zmin cube) = False
143 | z > (zmax cube) = False
150 -- | The top (in the direction of z) face of the cube.
151 top_face :: Cube -> Face.Face
152 top_face cube = Face.Face v0' v1' v2' v3'
154 delta = (1/2)*(h cube)
155 v0' = (center cube) + (delta, -delta, delta)
156 v1' = (center cube) + (delta, delta, delta)
157 v2' = (center cube) + (-delta, delta, delta)
158 v3' = (center cube) + (-delta, -delta, delta)
162 -- | The back (in the direction of x) face of the cube.
163 back_face :: Cube -> Face.Face
164 back_face cube = Face.Face v0' v1' v2' v3'
166 delta = (1/2)*(h cube)
167 v0' = (center cube) + (delta, -delta, -delta)
168 v1' = (center cube) + (delta, delta, -delta)
169 v2' = (center cube) + (delta, delta, delta)
170 v3' = (center cube) + (delta, -delta, delta)
173 -- The bottom face (in the direction of -z) of the cube.
174 down_face :: Cube -> Face.Face
175 down_face cube = Face.Face v0' v1' v2' v3'
177 delta = (1/2)*(h cube)
178 v0' = (center cube) + (-delta, -delta, -delta)
179 v1' = (center cube) + (-delta, delta, -delta)
180 v2' = (center cube) + (delta, delta, -delta)
181 v3' = (center cube) + (delta, -delta, -delta)
185 -- | The front (in the direction of -x) face of the cube.
186 front_face :: Cube -> Face.Face
187 front_face cube = Face.Face v0' v1' v2' v3'
189 delta = (1/2)*(h cube)
190 v0' = (center cube) + (-delta, -delta, delta)
191 v1' = (center cube) + (-delta, delta, delta)
192 v2' = (center cube) + (-delta, delta, -delta)
193 v3' = (center cube) + (-delta, -delta, -delta)
195 -- | The left (in the direction of -y) face of the cube.
196 left_face :: Cube -> Face.Face
197 left_face cube = Face.Face v0' v1' v2' v3'
199 delta = (1/2)*(h cube)
200 v0' = (center cube) + (delta, -delta, delta)
201 v1' = (center cube) + (-delta, -delta, delta)
202 v2' = (center cube) + (-delta, -delta, -delta)
203 v3' = (center cube) + (delta, -delta, -delta)
206 -- | The right (in the direction of y) face of the cube.
207 right_face :: Cube -> Face.Face
208 right_face cube = Face.Face v0' v1' v2' v3'
210 delta = (1/2)*(h cube)
211 v0' = (center cube) + (-delta, delta, delta)
212 v1' = (center cube) + (delta, delta, delta)
213 v2' = (center cube) + (delta, delta, -delta)
214 v3' = (center cube) + (-delta, delta, -delta)
217 tetrahedron :: Cube -> Int -> Tetrahedron
220 Tetrahedron (fv cube) v0' v1' v2' v3' vol
223 v1' = center (front_face cube)
224 v2' = Face.v0 (front_face cube)
225 v3' = Face.v1 (front_face cube)
226 vol = tetrahedra_volume cube
229 Tetrahedron fv' v0' v1' v2' v3' vol
232 v1' = center (front_face cube)
233 v2' = Face.v1 (front_face cube)
234 v3' = Face.v2 (front_face cube)
235 fv' = rotate ccwx (fv cube)
236 vol = tetrahedra_volume cube
239 Tetrahedron fv' v0' v1' v2' v3' vol
242 v1' = center (front_face cube)
243 v2' = Face.v2 (front_face cube)
244 v3' = Face.v3 (front_face cube)
245 fv' = rotate ccwx $ rotate ccwx $ fv cube
246 vol = tetrahedra_volume cube
249 Tetrahedron fv' v0' v1' v2' v3' vol
252 v1' = center (front_face cube)
253 v2' = Face.v3 (front_face cube)
254 v3' = Face.v0 (front_face cube)
255 fv' = rotate cwx (fv cube)
256 vol = tetrahedra_volume cube
259 Tetrahedron fv' v0' v1' v2' v3' vol
262 v1' = center (top_face cube)
263 v2' = Face.v0 (top_face cube)
264 v3' = Face.v1 (top_face cube)
265 fv' = rotate cwy (fv cube)
266 vol = tetrahedra_volume cube
269 Tetrahedron fv' v0' v1' v2' v3' vol
272 v1' = center (top_face cube)
273 v2' = Face.v1 (top_face cube)
274 v3' = Face.v2 (top_face cube)
275 fv' = rotate cwy $ rotate cwz $ fv cube
276 vol = tetrahedra_volume cube
279 Tetrahedron fv' v0' v1' v2' v3' vol
282 v1' = center (top_face cube)
283 v2' = Face.v2 (top_face cube)
284 v3' = Face.v3 (top_face cube)
285 fv' = rotate cwy $ rotate cwz
288 vol = tetrahedra_volume cube
291 Tetrahedron fv' v0' v1' v2' v3' vol
294 v1' = center (top_face cube)
295 v2' = Face.v3 (top_face cube)
296 v3' = Face.v0 (top_face cube)
297 fv' = rotate cwy $ rotate ccwz $ fv cube
298 vol = tetrahedra_volume cube
301 Tetrahedron fv' v0' v1' v2' v3' vol
304 v1' = center (back_face cube)
305 v2' = Face.v0 (back_face cube)
306 v3' = Face.v1 (back_face cube)
307 fv' = rotate cwy $ rotate cwy $ fv cube
308 vol = tetrahedra_volume cube
311 Tetrahedron fv' v0' v1' v2' v3' vol
314 v1' = center (back_face cube)
315 v2' = Face.v1 (back_face cube)
316 v3' = Face.v2 (back_face cube)
317 fv' = rotate cwy $ rotate cwy
320 vol = tetrahedra_volume cube
322 tetrahedron cube 10 =
323 Tetrahedron fv' v0' v1' v2' v3' vol
326 v1' = center (back_face cube)
327 v2' = Face.v2 (back_face cube)
328 v3' = Face.v3 (back_face cube)
329 fv' = rotate cwy $ rotate cwy
334 vol = tetrahedra_volume cube
336 tetrahedron cube 11 =
337 Tetrahedron fv' v0' v1' v2' v3' vol
340 v1' = center (back_face cube)
341 v2' = Face.v3 (back_face cube)
342 v3' = Face.v0 (back_face cube)
343 fv' = rotate cwy $ rotate cwy
346 vol = tetrahedra_volume cube
348 tetrahedron cube 12 =
349 Tetrahedron fv' v0' v1' v2' v3' vol
352 v1' = center (down_face cube)
353 v2' = Face.v0 (down_face cube)
354 v3' = Face.v1 (down_face cube)
355 fv' = rotate ccwy $ fv cube
356 vol = tetrahedra_volume cube
358 tetrahedron cube 13 =
359 Tetrahedron fv' v0' v1' v2' v3' vol
362 v1' = center (down_face cube)
363 v2' = Face.v1 (down_face cube)
364 v3' = Face.v2 (down_face cube)
365 fv' = rotate ccwy $ rotate ccwz $ fv cube
366 vol = tetrahedra_volume cube
368 tetrahedron cube 14 =
369 Tetrahedron fv' v0' v1' v2' v3' vol
372 v1' = center (down_face cube)
373 v2' = Face.v2 (down_face cube)
374 v3' = Face.v3 (down_face cube)
375 fv' = rotate ccwy $ rotate ccwz
378 vol = tetrahedra_volume cube
380 tetrahedron cube 15 =
381 Tetrahedron fv' v0' v1' v2' v3' vol
384 v1' = center (down_face cube)
385 v2' = Face.v3 (down_face cube)
386 v3' = Face.v0 (down_face cube)
387 fv' = rotate ccwy $ rotate cwz $ fv cube
388 vol = tetrahedra_volume cube
390 tetrahedron cube 16 =
391 Tetrahedron fv' v0' v1' v2' v3' vol
394 v1' = center (right_face cube)
395 v2' = Face.v0 (right_face cube)
396 v3' = Face.v1 (right_face cube)
397 fv' = rotate ccwz $ fv cube
398 vol = tetrahedra_volume cube
400 tetrahedron cube 17 =
401 Tetrahedron fv' v0' v1' v2' v3' vol
404 v1' = center (right_face cube)
405 v2' = Face.v1 (right_face cube)
406 v3' = Face.v2 (right_face cube)
407 fv' = rotate ccwz $ rotate cwy $ fv cube
408 vol = tetrahedra_volume cube
410 tetrahedron cube 18 =
411 Tetrahedron fv' v0' v1' v2' v3' vol
414 v1' = center (right_face cube)
415 v2' = Face.v2 (right_face cube)
416 v3' = Face.v3 (right_face cube)
417 fv' = rotate ccwz $ rotate cwy
420 vol = tetrahedra_volume cube
422 tetrahedron cube 19 =
423 Tetrahedron fv' v0' v1' v2' v3' vol
426 v1' = center (right_face cube)
427 v2' = Face.v3 (right_face cube)
428 v3' = Face.v0 (right_face cube)
429 fv' = rotate ccwz $ rotate ccwy
431 vol = tetrahedra_volume cube
433 tetrahedron cube 20 =
434 Tetrahedron fv' v0' v1' v2' v3' vol
437 v1' = center (left_face cube)
438 v2' = Face.v0 (left_face cube)
439 v3' = Face.v1 (left_face cube)
440 fv' = rotate cwz $ fv cube
441 vol = tetrahedra_volume cube
443 tetrahedron cube 21 =
444 Tetrahedron fv' v0' v1' v2' v3' vol
447 v1' = center (left_face cube)
448 v2' = Face.v1 (left_face cube)
449 v3' = Face.v2 (left_face cube)
450 fv' = rotate cwz $ rotate ccwy $ fv cube
451 vol = tetrahedra_volume cube
453 tetrahedron cube 22 =
454 Tetrahedron fv' v0' v1' v2' v3' vol
457 v1' = center (left_face cube)
458 v2' = Face.v2 (left_face cube)
459 v3' = Face.v3 (left_face cube)
460 fv' = rotate cwz $ rotate ccwy
463 vol = tetrahedra_volume cube
465 tetrahedron cube 23 =
466 Tetrahedron fv' v0' v1' v2' v3' vol
469 v1' = center (left_face cube)
470 v2' = Face.v3 (left_face cube)
471 v3' = Face.v0 (left_face cube)
472 fv' = rotate cwz $ rotate cwy
474 vol = tetrahedra_volume cube
476 -- Feels dirty, but whatever.
477 tetrahedron _ _ = error "asked for a nonexistent tetrahedron"
480 -- Only used in tests, so we don't need the added speed
482 tetrahedra :: Cube -> [Tetrahedron]
483 tetrahedra cube = [ tetrahedron cube n | n <- [0..23] ]
485 front_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
486 front_left_top_tetrahedra cube =
487 V.singleton (tetrahedron cube 0) `V.snoc`
488 (tetrahedron cube 3) `V.snoc`
489 (tetrahedron cube 6) `V.snoc`
490 (tetrahedron cube 7) `V.snoc`
491 (tetrahedron cube 20) `V.snoc`
492 (tetrahedron cube 21)
494 front_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
495 front_left_down_tetrahedra cube =
496 V.singleton (tetrahedron cube 0) `V.snoc`
497 (tetrahedron cube 2) `V.snoc`
498 (tetrahedron cube 3) `V.snoc`
499 (tetrahedron cube 12) `V.snoc`
500 (tetrahedron cube 15) `V.snoc`
501 (tetrahedron cube 21)
503 front_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
504 front_right_top_tetrahedra cube =
505 V.singleton (tetrahedron cube 0) `V.snoc`
506 (tetrahedron cube 1) `V.snoc`
507 (tetrahedron cube 5) `V.snoc`
508 (tetrahedron cube 6) `V.snoc`
509 (tetrahedron cube 16) `V.snoc`
510 (tetrahedron cube 19)
512 front_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
513 front_right_down_tetrahedra cube =
514 V.singleton (tetrahedron cube 1) `V.snoc`
515 (tetrahedron cube 2) `V.snoc`
516 (tetrahedron cube 12) `V.snoc`
517 (tetrahedron cube 13) `V.snoc`
518 (tetrahedron cube 18) `V.snoc`
519 (tetrahedron cube 19)
521 back_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
522 back_left_top_tetrahedra cube =
523 V.singleton (tetrahedron cube 0) `V.snoc`
524 (tetrahedron cube 3) `V.snoc`
525 (tetrahedron cube 6) `V.snoc`
526 (tetrahedron cube 7) `V.snoc`
527 (tetrahedron cube 20) `V.snoc`
528 (tetrahedron cube 21)
530 back_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
531 back_left_down_tetrahedra cube =
532 V.singleton (tetrahedron cube 8) `V.snoc`
533 (tetrahedron cube 11) `V.snoc`
534 (tetrahedron cube 14) `V.snoc`
535 (tetrahedron cube 15) `V.snoc`
536 (tetrahedron cube 22) `V.snoc`
537 (tetrahedron cube 23)
539 back_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
540 back_right_top_tetrahedra cube =
541 V.singleton (tetrahedron cube 4) `V.snoc`
542 (tetrahedron cube 5) `V.snoc`
543 (tetrahedron cube 9) `V.snoc`
544 (tetrahedron cube 10) `V.snoc`
545 (tetrahedron cube 16) `V.snoc`
546 (tetrahedron cube 17)
548 back_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
549 back_right_down_tetrahedra cube =
550 V.singleton (tetrahedron cube 8) `V.snoc`
551 (tetrahedron cube 9) `V.snoc`
552 (tetrahedron cube 13) `V.snoc`
553 (tetrahedron cube 14) `V.snoc`
554 (tetrahedron cube 17) `V.snoc`
555 (tetrahedron cube 18)
557 in_top_half :: Cube -> Point -> Bool
558 in_top_half cube (_,_,z) =
559 distance_from_top <= distance_from_bottom
561 distance_from_top = abs $ (zmax cube) - z
562 distance_from_bottom = abs $ (zmin cube) - z
564 in_front_half :: Cube -> Point -> Bool
565 in_front_half cube (x,_,_) =
566 distance_from_front <= distance_from_back
568 distance_from_front = abs $ (xmin cube) - x
569 distance_from_back = abs $ (xmax cube) - x
572 in_left_half :: Cube -> Point -> Bool
573 in_left_half cube (_,y,_) =
574 distance_from_left <= distance_from_right
576 distance_from_left = abs $ (ymin cube) - y
577 distance_from_right = abs $ (ymax cube) - y
580 -- | Takes a 'Cube', and returns the Tetrahedra belonging to it that
581 -- contain the given 'Point'. This should be faster than checking
582 -- every tetrahedron individually, since we determine which half
583 -- (hemisphere?) of the cube the point lies in three times: once in
584 -- each dimension. This allows us to eliminate non-candidates
587 -- This can throw an exception, but the use of 'head' might
588 -- save us some unnecessary computations.
590 find_containing_tetrahedron :: Cube -> Point -> Tetrahedron
591 find_containing_tetrahedron cube p =
592 candidates `V.unsafeIndex` (fromJust lucky_idx)
594 front_half = in_front_half cube p
595 top_half = in_top_half cube p
596 left_half = in_left_half cube p
603 front_left_top_tetrahedra cube
605 front_left_down_tetrahedra cube
608 front_right_top_tetrahedra cube
610 front_right_down_tetrahedra cube
616 back_left_top_tetrahedra cube
618 back_left_down_tetrahedra cube
621 back_right_top_tetrahedra cube
623 back_right_down_tetrahedra cube
625 -- Use the dot product instead of 'distance' here to save a
626 -- sqrt(). So, "distances" below really means "distances squared."
627 distances = V.map ((dot p) . center) candidates
628 shortest_distance = V.minimum distances
629 lucky_idx = V.findIndex
630 (\t -> (center t) `dot` p == shortest_distance)
642 prop_opposite_octant_tetrahedra_disjoint1 :: Cube -> Bool
643 prop_opposite_octant_tetrahedra_disjoint1 cube =
644 disjoint (front_left_top_tetrahedra cube) (front_right_down_tetrahedra cube)
646 prop_opposite_octant_tetrahedra_disjoint2 :: Cube -> Bool
647 prop_opposite_octant_tetrahedra_disjoint2 cube =
648 disjoint (back_left_top_tetrahedra cube) (back_right_down_tetrahedra cube)
650 prop_opposite_octant_tetrahedra_disjoint3 :: Cube -> Bool
651 prop_opposite_octant_tetrahedra_disjoint3 cube =
652 disjoint (front_left_top_tetrahedra cube) (back_right_top_tetrahedra cube)
654 prop_opposite_octant_tetrahedra_disjoint4 :: Cube -> Bool
655 prop_opposite_octant_tetrahedra_disjoint4 cube =
656 disjoint (front_left_down_tetrahedra cube) (back_right_down_tetrahedra cube)
658 prop_opposite_octant_tetrahedra_disjoint5 :: Cube -> Bool
659 prop_opposite_octant_tetrahedra_disjoint5 cube =
660 disjoint (front_left_top_tetrahedra cube) (back_left_down_tetrahedra cube)
662 prop_opposite_octant_tetrahedra_disjoint6 :: Cube -> Bool
663 prop_opposite_octant_tetrahedra_disjoint6 cube =
664 disjoint (front_right_top_tetrahedra cube) (back_right_down_tetrahedra cube)
667 -- | Since the grid size is necessarily positive, all tetrahedra
668 -- (which comprise cubes of positive volume) must have positive volume
670 prop_all_volumes_positive :: Cube -> Bool
671 prop_all_volumes_positive cube =
672 null nonpositive_volumes
675 volumes = map volume ts
676 nonpositive_volumes = filter (<= 0) volumes
678 -- | In fact, since all of the tetrahedra are identical, we should
679 -- already know their volumes. There's 24 tetrahedra to a cube, so
680 -- we'd expect the volume of each one to be (1/24)*h^3.
681 prop_all_volumes_exact :: Cube -> Bool
682 prop_all_volumes_exact cube =
683 and [volume t ~~= (1/24)*(delta^(3::Int)) | t <- tetrahedra cube]
687 -- | All tetrahedron should have their v0 located at the center of the cube.
688 prop_v0_all_equal :: Cube -> Bool
689 prop_v0_all_equal cube = (v0 t0) == (v0 t1)
691 t0 = head (tetrahedra cube) -- Doesn't matter which two we choose.
692 t1 = head $ tail (tetrahedra cube)
695 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Note that the
696 -- third and fourth indices of c-t3 have been switched. This is
697 -- because we store the triangles oriented such that their volume is
698 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
699 -- in opposite directions, one of them has to have negative volume!
700 prop_c0120_identity1 :: Cube -> Bool
701 prop_c0120_identity1 cube =
702 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
704 t0 = tetrahedron cube 0
705 t3 = tetrahedron cube 3
708 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
709 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
710 prop_c0120_identity2 :: Cube -> Bool
711 prop_c0120_identity2 cube =
712 c t1 0 1 2 0 ~= (c t1 0 0 2 1 + c t0 0 0 1 2) / 2
714 t0 = tetrahedron cube 0
715 t1 = tetrahedron cube 1
717 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
718 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
719 prop_c0120_identity3 :: Cube -> Bool
720 prop_c0120_identity3 cube =
721 c t2 0 1 2 0 ~= (c t2 0 0 2 1 + c t1 0 0 1 2) / 2
723 t1 = tetrahedron cube 1
724 t2 = tetrahedron cube 2
726 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
727 -- 'prop_c0120_identity1' with tetrahedrons 2 and 3.
728 prop_c0120_identity4 :: Cube -> Bool
729 prop_c0120_identity4 cube =
730 c t3 0 1 2 0 ~= (c t3 0 0 2 1 + c t2 0 0 1 2) / 2
732 t2 = tetrahedron cube 2
733 t3 = tetrahedron cube 3
736 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
737 -- 'prop_c0120_identity1' with tetrahedrons 4 and 5.
738 prop_c0120_identity5 :: Cube -> Bool
739 prop_c0120_identity5 cube =
740 c t5 0 1 2 0 ~= (c t5 0 0 2 1 + c t4 0 0 1 2) / 2
742 t4 = tetrahedron cube 4
743 t5 = tetrahedron cube 5
745 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
746 -- 'prop_c0120_identity1' with tetrahedrons 5 and 6.
747 prop_c0120_identity6 :: Cube -> Bool
748 prop_c0120_identity6 cube =
749 c t6 0 1 2 0 ~= (c t6 0 0 2 1 + c t5 0 0 1 2) / 2
751 t5 = tetrahedron cube 5
752 t6 = tetrahedron cube 6
755 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
756 -- 'prop_c0120_identity1' with tetrahedrons 6 and 7.
757 prop_c0120_identity7 :: Cube -> Bool
758 prop_c0120_identity7 cube =
759 c t7 0 1 2 0 ~= (c t7 0 0 2 1 + c t6 0 0 1 2) / 2
761 t6 = tetrahedron cube 6
762 t7 = tetrahedron cube 7
765 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
766 -- 'prop_c0120_identity1'.
767 prop_c0210_identity1 :: Cube -> Bool
768 prop_c0210_identity1 cube =
769 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
771 t0 = tetrahedron cube 0
772 t3 = tetrahedron cube 3
775 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
776 -- 'prop_c0120_identity1'.
777 prop_c0300_identity1 :: Cube -> Bool
778 prop_c0300_identity1 cube =
779 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
781 t0 = tetrahedron cube 0
782 t3 = tetrahedron cube 3
785 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
786 -- 'prop_c0120_identity1'.
787 prop_c1110_identity :: Cube -> Bool
788 prop_c1110_identity cube =
789 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
791 t0 = tetrahedron cube 0
792 t3 = tetrahedron cube 3
795 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
796 -- 'prop_c0120_identity1'.
797 prop_c1200_identity1 :: Cube -> Bool
798 prop_c1200_identity1 cube =
799 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
801 t0 = tetrahedron cube 0
802 t3 = tetrahedron cube 3
805 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
806 -- 'prop_c0120_identity1'.
807 prop_c2100_identity1 :: Cube -> Bool
808 prop_c2100_identity1 cube =
809 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
811 t0 = tetrahedron cube 0
812 t3 = tetrahedron cube 3
816 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). Note that the
817 -- third and fourth indices of c-t3 have been switched. This is
818 -- because we store the triangles oriented such that their volume is
819 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
820 -- point in opposite directions, one of them has to have negative
822 prop_c0102_identity1 :: Cube -> Bool
823 prop_c0102_identity1 cube =
824 c t0 0 1 0 2 ~= (c t0 0 0 1 2 + c t1 0 0 2 1) / 2
826 t0 = tetrahedron cube 0
827 t1 = tetrahedron cube 1
830 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
831 -- 'prop_c0102_identity1'.
832 prop_c0201_identity1 :: Cube -> Bool
833 prop_c0201_identity1 cube =
834 c t0 0 2 0 1 ~= (c t0 0 1 1 1 + c t1 0 1 1 1) / 2
836 t0 = tetrahedron cube 0
837 t1 = tetrahedron cube 1
840 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
841 -- 'prop_c0102_identity1'.
842 prop_c0300_identity2 :: Cube -> Bool
843 prop_c0300_identity2 cube =
844 c t0 0 3 0 0 ~= (c t0 0 2 1 0 + c t1 0 2 0 1) / 2
846 t0 = tetrahedron cube 0
847 t1 = tetrahedron cube 1
850 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
851 -- 'prop_c0102_identity1'.
852 prop_c1101_identity :: Cube -> Bool
853 prop_c1101_identity cube =
854 c t0 1 1 0 1 ~= (c t0 1 0 1 1 + c t1 1 0 1 1) / 2
856 t0 = tetrahedron cube 0
857 t1 = tetrahedron cube 1
860 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
861 -- 'prop_c0102_identity1'.
862 prop_c1200_identity2 :: Cube -> Bool
863 prop_c1200_identity2 cube =
864 c t0 1 2 0 0 ~= (c t0 1 1 1 0 + c t1 1 1 0 1) / 2
866 t0 = tetrahedron cube 0
867 t1 = tetrahedron cube 1
870 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
871 -- 'prop_c0102_identity1'.
872 prop_c2100_identity2 :: Cube -> Bool
873 prop_c2100_identity2 cube =
874 c t0 2 1 0 0 ~= (c t0 2 0 1 0 + c t1 2 0 0 1) / 2
876 t0 = tetrahedron cube 0
877 t1 = tetrahedron cube 1
880 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). The third and
881 -- fourth indices of c-t6 have been switched. This is because we
882 -- store the triangles oriented such that their volume is
883 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
884 -- point in opposite directions, one of them has to have negative
886 prop_c3000_identity :: Cube -> Bool
887 prop_c3000_identity cube =
888 c t0 3 0 0 0 ~= c t0 2 1 0 0 + c t6 2 1 0 0
889 - ((c t0 2 0 1 0 + c t0 2 0 0 1)/ 2)
891 t0 = tetrahedron cube 0
892 t6 = tetrahedron cube 6
895 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
896 -- 'prop_c3000_identity'.
897 prop_c2010_identity :: Cube -> Bool
898 prop_c2010_identity cube =
899 c t0 2 0 1 0 ~= c t0 1 1 1 0 + c t6 1 1 0 1
900 - ((c t0 1 0 2 0 + c t0 1 0 1 1)/ 2)
902 t0 = tetrahedron cube 0
903 t6 = tetrahedron cube 6
906 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
907 -- 'prop_c3000_identity'.
908 prop_c2001_identity :: Cube -> Bool
909 prop_c2001_identity cube =
910 c t0 2 0 0 1 ~= c t0 1 1 0 1 + c t6 1 1 1 0
911 - ((c t0 1 0 0 2 + c t0 1 0 1 1)/ 2)
913 t0 = tetrahedron cube 0
914 t6 = tetrahedron cube 6
917 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
918 -- 'prop_c3000_identity'.
919 prop_c1020_identity :: Cube -> Bool
920 prop_c1020_identity cube =
921 c t0 1 0 2 0 ~= c t0 0 1 2 0 + c t6 0 1 0 2
922 - ((c t0 0 0 3 0 + c t0 0 0 2 1)/ 2)
924 t0 = tetrahedron cube 0
925 t6 = tetrahedron cube 6
928 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
929 -- 'prop_c3000_identity'.
930 prop_c1002_identity :: Cube -> Bool
931 prop_c1002_identity cube =
932 c t0 1 0 0 2 ~= c t0 0 1 0 2 + c t6 0 1 2 0
933 - ((c t0 0 0 0 3 + c t0 0 0 1 2)/ 2)
935 t0 = tetrahedron cube 0
936 t6 = tetrahedron cube 6
939 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
940 -- 'prop_c3000_identity'.
941 prop_c1011_identity :: Cube -> Bool
942 prop_c1011_identity cube =
943 c t0 1 0 1 1 ~= c t0 0 1 1 1 + c t6 0 1 1 1 -
944 ((c t0 0 0 1 2 + c t0 0 0 2 1)/ 2)
946 t0 = tetrahedron cube 0
947 t6 = tetrahedron cube 6
950 -- | The function values at the interior should be the same for all
952 prop_interior_values_all_identical :: Cube -> Bool
953 prop_interior_values_all_identical cube =
954 all_equal [ eval (function_values tet) I | tet <- tetrahedra cube ]
957 -- | We know what (c t6 2 1 0 0) should be from Sorokina and Zeilfelder, p. 87.
958 -- This test checks the rotation works as expected.
959 prop_c_tilde_2100_rotation_correct :: Cube -> Bool
960 prop_c_tilde_2100_rotation_correct cube =
963 t0 = tetrahedron cube 0
964 t6 = tetrahedron cube 6
966 -- What gets computed for c2100 of t6.
967 expr1 = eval (function_values t6) $
969 (1/12)*(T + R + L + D) +
970 (1/64)*(FT + FR + FL + FD) +
973 (1/96)*(RT + LD + LT + RD) +
974 (1/192)*(BT + BR + BL + BD)
976 -- What should be computed for c2100 of t6.
977 expr2 = eval (function_values t0) $
979 (1/12)*(F + R + L + B) +
980 (1/64)*(FT + RT + LT + BT) +
983 (1/96)*(FR + FL + BR + BL) +
984 (1/192)*(FD + RD + LD + BD)
987 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
988 -- Zeilfelder, p. 87. This test checks the actual value based on
989 -- the FunctionValues of the cube.
991 -- If 'prop_c_tilde_2100_rotation_correct' passes, then this test is
993 prop_c_tilde_2100_correct :: Cube -> Bool
994 prop_c_tilde_2100_correct cube =
995 c t6 2 1 0 0 == expected
997 t0 = tetrahedron cube 0
998 t6 = tetrahedron cube 6
999 fvs = function_values t0
1000 expected = eval fvs $
1002 (1/12)*(F + R + L + B) +
1003 (1/64)*(FT + RT + LT + BT) +
1006 (1/96)*(FR + FL + BR + BL) +
1007 (1/192)*(FD + RD + LD + BD)
1010 -- Tests to check that the correct edges are incidental.
1011 prop_t0_shares_edge_with_t1 :: Cube -> Bool
1012 prop_t0_shares_edge_with_t1 cube =
1013 (v1 t0) == (v1 t1) && (v3 t0) == (v2 t1)
1015 t0 = tetrahedron cube 0
1016 t1 = tetrahedron cube 1
1018 prop_t0_shares_edge_with_t3 :: Cube -> Bool
1019 prop_t0_shares_edge_with_t3 cube =
1020 (v1 t0) == (v1 t3) && (v2 t0) == (v3 t3)
1022 t0 = tetrahedron cube 0
1023 t3 = tetrahedron cube 3
1025 prop_t0_shares_edge_with_t6 :: Cube -> Bool
1026 prop_t0_shares_edge_with_t6 cube =
1027 (v2 t0) == (v3 t6) && (v3 t0) == (v2 t6)
1029 t0 = tetrahedron cube 0
1030 t6 = tetrahedron cube 6
1032 prop_t1_shares_edge_with_t2 :: Cube -> Bool
1033 prop_t1_shares_edge_with_t2 cube =
1034 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1036 t1 = tetrahedron cube 1
1037 t2 = tetrahedron cube 2
1039 prop_t1_shares_edge_with_t19 :: Cube -> Bool
1040 prop_t1_shares_edge_with_t19 cube =
1041 (v2 t1) == (v3 t19) && (v3 t1) == (v2 t19)
1043 t1 = tetrahedron cube 1
1044 t19 = tetrahedron cube 19
1046 prop_t2_shares_edge_with_t3 :: Cube -> Bool
1047 prop_t2_shares_edge_with_t3 cube =
1048 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1050 t1 = tetrahedron cube 1
1051 t2 = tetrahedron cube 2
1053 prop_t2_shares_edge_with_t12 :: Cube -> Bool
1054 prop_t2_shares_edge_with_t12 cube =
1055 (v2 t2) == (v3 t12) && (v3 t2) == (v2 t12)
1057 t2 = tetrahedron cube 2
1058 t12 = tetrahedron cube 12
1060 prop_t3_shares_edge_with_t21 :: Cube -> Bool
1061 prop_t3_shares_edge_with_t21 cube =
1062 (v2 t3) == (v3 t21) && (v3 t3) == (v2 t21)
1064 t3 = tetrahedron cube 3
1065 t21 = tetrahedron cube 21
1067 prop_t4_shares_edge_with_t5 :: Cube -> Bool
1068 prop_t4_shares_edge_with_t5 cube =
1069 (v1 t4) == (v1 t5) && (v3 t4) == (v2 t5)
1071 t4 = tetrahedron cube 4
1072 t5 = tetrahedron cube 5
1074 prop_t4_shares_edge_with_t7 :: Cube -> Bool
1075 prop_t4_shares_edge_with_t7 cube =
1076 (v1 t4) == (v1 t7) && (v2 t4) == (v3 t7)
1078 t4 = tetrahedron cube 4
1079 t7 = tetrahedron cube 7
1081 prop_t4_shares_edge_with_t10 :: Cube -> Bool
1082 prop_t4_shares_edge_with_t10 cube =
1083 (v2 t4) == (v3 t10) && (v3 t4) == (v2 t10)
1085 t4 = tetrahedron cube 4
1086 t10 = tetrahedron cube 10
1088 prop_t5_shares_edge_with_t6 :: Cube -> Bool
1089 prop_t5_shares_edge_with_t6 cube =
1090 (v1 t5) == (v1 t6) && (v3 t5) == (v2 t6)
1092 t5 = tetrahedron cube 5
1093 t6 = tetrahedron cube 6
1095 prop_t5_shares_edge_with_t16 :: Cube -> Bool
1096 prop_t5_shares_edge_with_t16 cube =
1097 (v2 t5) == (v3 t16) && (v3 t5) == (v2 t16)
1099 t5 = tetrahedron cube 5
1100 t16 = tetrahedron cube 16
1102 prop_t6_shares_edge_with_t7 :: Cube -> Bool
1103 prop_t6_shares_edge_with_t7 cube =
1104 (v1 t6) == (v1 t7) && (v3 t6) == (v2 t7)
1106 t6 = tetrahedron cube 6
1107 t7 = tetrahedron cube 7
1109 prop_t7_shares_edge_with_t20 :: Cube -> Bool
1110 prop_t7_shares_edge_with_t20 cube =
1111 (v2 t7) == (v3 t20) && (v2 t7) == (v3 t20)
1113 t7 = tetrahedron cube 7
1114 t20 = tetrahedron cube 20
1117 p79_26_properties :: Test.Framework.Test
1119 testGroup "p. 79, Section (2.6) Properties" [
1120 testProperty "c0120 identity1" prop_c0120_identity1,
1121 testProperty "c0120 identity2" prop_c0120_identity2,
1122 testProperty "c0120 identity3" prop_c0120_identity3,
1123 testProperty "c0120 identity4" prop_c0120_identity4,
1124 testProperty "c0120 identity5" prop_c0120_identity5,
1125 testProperty "c0120 identity6" prop_c0120_identity6,
1126 testProperty "c0120 identity7" prop_c0120_identity7,
1127 testProperty "c0210 identity1" prop_c0210_identity1,
1128 testProperty "c0300 identity1" prop_c0300_identity1,
1129 testProperty "c1110 identity" prop_c1110_identity,
1130 testProperty "c1200 identity1" prop_c1200_identity1,
1131 testProperty "c2100 identity1" prop_c2100_identity1]
1133 p79_27_properties :: Test.Framework.Test
1135 testGroup "p. 79, Section (2.7) Properties" [
1136 testProperty "c0102 identity1" prop_c0102_identity1,
1137 testProperty "c0201 identity1" prop_c0201_identity1,
1138 testProperty "c0300 identity2" prop_c0300_identity2,
1139 testProperty "c1101 identity" prop_c1101_identity,
1140 testProperty "c1200 identity2" prop_c1200_identity2,
1141 testProperty "c2100 identity2" prop_c2100_identity2 ]
1144 p79_28_properties :: Test.Framework.Test
1146 testGroup "p. 79, Section (2.8) Properties" [
1147 testProperty "c3000 identity" prop_c3000_identity,
1148 testProperty "c2010 identity" prop_c2010_identity,
1149 testProperty "c2001 identity" prop_c2001_identity,
1150 testProperty "c1020 identity" prop_c1020_identity,
1151 testProperty "c1002 identity" prop_c1002_identity,
1152 testProperty "c1011 identity" prop_c1011_identity ]
1155 edge_incidence_tests :: Test.Framework.Test
1156 edge_incidence_tests =
1157 testGroup "Edge Incidence Tests" [
1158 testProperty "t0 shares edge with t6" prop_t0_shares_edge_with_t6,
1159 testProperty "t0 shares edge with t1" prop_t0_shares_edge_with_t1,
1160 testProperty "t0 shares edge with t3" prop_t0_shares_edge_with_t3,
1161 testProperty "t1 shares edge with t2" prop_t1_shares_edge_with_t2,
1162 testProperty "t1 shares edge with t19" prop_t1_shares_edge_with_t19,
1163 testProperty "t2 shares edge with t3" prop_t2_shares_edge_with_t3,
1164 testProperty "t2 shares edge with t12" prop_t2_shares_edge_with_t12,
1165 testProperty "t3 shares edge with t21" prop_t3_shares_edge_with_t21,
1166 testProperty "t4 shares edge with t5" prop_t4_shares_edge_with_t5,
1167 testProperty "t4 shares edge with t7" prop_t4_shares_edge_with_t7,
1168 testProperty "t4 shares edge with t10" prop_t4_shares_edge_with_t10,
1169 testProperty "t5 shares edge with t6" prop_t5_shares_edge_with_t6,
1170 testProperty "t5 shares edge with t16" prop_t5_shares_edge_with_t16,
1171 testProperty "t6 shares edge with t7" prop_t6_shares_edge_with_t7,
1172 testProperty "t7 shares edge with t20" prop_t7_shares_edge_with_t20 ]
1174 cube_properties :: Test.Framework.Test
1176 testGroup "Cube Properties" [
1180 edge_incidence_tests,
1181 testProperty "opposite octant tetrahedra are disjoint (1)"
1182 prop_opposite_octant_tetrahedra_disjoint1,
1183 testProperty "opposite octant tetrahedra are disjoint (2)"
1184 prop_opposite_octant_tetrahedra_disjoint2,
1185 testProperty "opposite octant tetrahedra are disjoint (3)"
1186 prop_opposite_octant_tetrahedra_disjoint3,
1187 testProperty "opposite octant tetrahedra are disjoint (4)"
1188 prop_opposite_octant_tetrahedra_disjoint4,
1189 testProperty "opposite octant tetrahedra are disjoint (5)"
1190 prop_opposite_octant_tetrahedra_disjoint5,
1191 testProperty "opposite octant tetrahedra are disjoint (6)"
1192 prop_opposite_octant_tetrahedra_disjoint6,
1193 testProperty "all volumes positive" prop_all_volumes_positive,
1194 testProperty "all volumes exact" prop_all_volumes_exact,
1195 testProperty "v0 all equal" prop_v0_all_equal,
1196 testProperty "interior values all identical"
1197 prop_interior_values_all_identical,
1198 testProperty "c-tilde_2100 rotation correct"
1199 prop_c_tilde_2100_rotation_correct,
1200 testProperty "c-tilde_2100 correct"
1201 prop_c_tilde_2100_correct ]