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(..), center)
28 import FunctionValues (FunctionValues, eval, rotate)
29 import Misc (all_equal, disjoint)
30 import Point (Point(..), dot)
31 import Tetrahedron (Tetrahedron(..), barycenter, c, volume)
33 data Cube = Cube { i :: !Int,
36 fv :: !FunctionValues,
37 tetrahedra_volume :: !Double }
41 instance Arbitrary Cube where
43 i' <- choose (coordmin, coordmax)
44 j' <- choose (coordmin, coordmax)
45 k' <- choose (coordmin, coordmax)
46 fv' <- arbitrary :: Gen FunctionValues
47 (Positive tet_vol) <- arbitrary :: Gen (Positive Double)
48 return (Cube i' j' k' fv' tet_vol)
50 -- The idea here is that, when cubed in the volume formula,
51 -- these numbers don't overflow 64 bits. This number is not
52 -- magic in any other sense than that it does not cause test
53 -- failures, while 2^23 does.
54 coordmax = 4194304 -- 2^22
58 instance Show Cube where
60 "Cube_" ++ subscript ++ "\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"
70 (show (i cube)) ++ "," ++ (show (j cube)) ++ "," ++ (show (k cube))
73 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
75 xmin :: Cube -> Double
76 xmin cube = (i' - 1/2)
78 i' = fromIntegral (i cube) :: Double
80 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
82 xmax :: Cube -> Double
83 xmax cube = (i' + 1/2)
85 i' = fromIntegral (i cube) :: Double
87 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
89 ymin :: Cube -> Double
90 ymin cube = (j' - 1/2)
92 j' = fromIntegral (j cube) :: Double
94 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
96 ymax :: Cube -> Double
97 ymax cube = (j' + 1/2)
99 j' = fromIntegral (j cube) :: Double
101 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
103 zmin :: Cube -> Double
104 zmin cube = (k' - 1/2)
106 k' = fromIntegral (k cube) :: Double
108 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
110 zmax :: Cube -> Double
111 zmax cube = (k' + 1/2)
113 k' = fromIntegral (k cube) :: Double
116 -- | The center of Cube_ijk coincides with v_ijk at
117 -- (i, j, k). See Sorokina and Zeilfelder, p. 76.
118 center :: Cube -> Point
122 x = fromIntegral (i cube) :: Double
123 y = fromIntegral (j cube) :: Double
124 z = fromIntegral (k cube) :: Double
129 -- | The top (in the direction of z) face of the cube.
130 top_face :: Cube -> Face.Face
131 top_face cube = Face.Face v0' v1' v2' v3'
135 v0' = cc + ( Point delta (-delta) delta )
136 v1' = cc + ( Point delta delta delta )
137 v2' = cc + ( Point (-delta) delta delta )
138 v3' = cc + ( Point (-delta) (-delta) delta )
142 -- | The back (in the direction of x) face of the cube.
143 back_face :: Cube -> Face.Face
144 back_face cube = Face.Face v0' v1' v2' v3'
148 v0' = cc + ( Point delta (-delta) (-delta) )
149 v1' = cc + ( Point delta delta (-delta) )
150 v2' = cc + ( Point delta delta delta )
151 v3' = cc + ( Point delta (-delta) delta )
154 -- The bottom face (in the direction of -z) of the cube.
155 down_face :: Cube -> Face.Face
156 down_face cube = Face.Face v0' v1' v2' v3'
160 v0' = cc + ( Point (-delta) (-delta) (-delta) )
161 v1' = cc + ( Point (-delta) delta (-delta) )
162 v2' = cc + ( Point delta delta (-delta) )
163 v3' = cc + ( Point delta (-delta) (-delta) )
167 -- | The front (in the direction of -x) face of the cube.
168 front_face :: Cube -> Face.Face
169 front_face cube = Face.Face v0' v1' v2' v3'
173 v0' = cc + ( Point (-delta) (-delta) delta )
174 v1' = cc + ( Point (-delta) delta delta )
175 v2' = cc + ( Point (-delta) delta (-delta) )
176 v3' = cc + ( Point (-delta) (-delta) (-delta) )
178 -- | The left (in the direction of -y) face of the cube.
179 left_face :: Cube -> Face.Face
180 left_face cube = Face.Face v0' v1' v2' v3'
184 v0' = cc + ( Point delta (-delta) delta )
185 v1' = cc + ( Point (-delta) (-delta) delta )
186 v2' = cc + ( Point (-delta) (-delta) (-delta) )
187 v3' = cc + ( Point delta (-delta) (-delta) )
190 -- | The right (in the direction of y) face of the cube.
191 right_face :: Cube -> Face.Face
192 right_face cube = Face.Face v0' v1' v2' v3'
196 v0' = cc + ( Point (-delta) delta delta)
197 v1' = cc + ( Point delta delta delta )
198 v2' = cc + ( Point delta delta (-delta) )
199 v3' = cc + ( Point (-delta) delta (-delta) )
202 tetrahedron :: Cube -> Int -> Tetrahedron
205 Tetrahedron (fv cube) v0' v1' v2' v3' vol
212 vol = tetrahedra_volume cube
215 Tetrahedron fv' v0' v1' v2' v3' vol
222 fv' = rotate ccwx (fv cube)
223 vol = tetrahedra_volume cube
226 Tetrahedron fv' v0' v1' v2' v3' vol
233 fv' = rotate ccwx $ rotate ccwx $ fv cube
234 vol = tetrahedra_volume cube
237 Tetrahedron fv' v0' v1' v2' v3' vol
244 fv' = rotate cwx (fv cube)
245 vol = tetrahedra_volume cube
248 Tetrahedron fv' v0' v1' v2' v3' vol
255 fv' = rotate cwy (fv cube)
256 vol = tetrahedra_volume cube
259 Tetrahedron fv' v0' v1' v2' v3' vol
266 fv' = rotate cwy $ rotate cwz $ fv cube
267 vol = tetrahedra_volume cube
270 Tetrahedron fv' v0' v1' v2' v3' vol
277 fv' = rotate cwy $ rotate cwz
280 vol = tetrahedra_volume cube
283 Tetrahedron fv' v0' v1' v2' v3' vol
290 fv' = rotate cwy $ rotate ccwz $ fv cube
291 vol = tetrahedra_volume cube
294 Tetrahedron fv' v0' v1' v2' v3' vol
301 fv' = rotate cwy $ rotate cwy $ fv cube
302 vol = tetrahedra_volume cube
305 Tetrahedron fv' v0' v1' v2' v3' vol
312 fv' = rotate cwy $ rotate cwy
315 vol = tetrahedra_volume cube
317 tetrahedron cube 10 =
318 Tetrahedron fv' v0' v1' v2' v3' vol
325 fv' = rotate cwy $ rotate cwy
330 vol = tetrahedra_volume cube
332 tetrahedron cube 11 =
333 Tetrahedron fv' v0' v1' v2' v3' vol
340 fv' = rotate cwy $ rotate cwy
343 vol = tetrahedra_volume cube
345 tetrahedron cube 12 =
346 Tetrahedron fv' v0' v1' v2' v3' vol
353 fv' = rotate ccwy $ fv cube
354 vol = tetrahedra_volume cube
356 tetrahedron cube 13 =
357 Tetrahedron fv' v0' v1' v2' v3' vol
364 fv' = rotate ccwy $ rotate ccwz $ fv cube
365 vol = tetrahedra_volume cube
367 tetrahedron cube 14 =
368 Tetrahedron fv' v0' v1' v2' v3' vol
375 fv' = rotate ccwy $ rotate ccwz
378 vol = tetrahedra_volume cube
380 tetrahedron cube 15 =
381 Tetrahedron fv' v0' v1' v2' v3' vol
388 fv' = rotate ccwy $ rotate cwz $ fv cube
389 vol = tetrahedra_volume cube
391 tetrahedron cube 16 =
392 Tetrahedron fv' v0' v1' v2' v3' vol
399 fv' = rotate ccwz $ fv cube
400 vol = tetrahedra_volume cube
402 tetrahedron cube 17 =
403 Tetrahedron fv' v0' v1' v2' v3' vol
410 fv' = rotate ccwz $ rotate cwy $ fv cube
411 vol = tetrahedra_volume cube
413 tetrahedron cube 18 =
414 Tetrahedron fv' v0' v1' v2' v3' vol
421 fv' = rotate ccwz $ rotate cwy
424 vol = tetrahedra_volume cube
426 tetrahedron cube 19 =
427 Tetrahedron fv' v0' v1' v2' v3' vol
434 fv' = rotate ccwz $ rotate ccwy
436 vol = tetrahedra_volume cube
438 tetrahedron cube 20 =
439 Tetrahedron fv' v0' v1' v2' v3' vol
446 fv' = rotate cwz $ fv cube
447 vol = tetrahedra_volume cube
449 tetrahedron cube 21 =
450 Tetrahedron fv' v0' v1' v2' v3' vol
457 fv' = rotate cwz $ rotate ccwy $ fv cube
458 vol = tetrahedra_volume cube
460 tetrahedron cube 22 =
461 Tetrahedron fv' v0' v1' v2' v3' vol
468 fv' = rotate cwz $ rotate ccwy
471 vol = tetrahedra_volume cube
473 tetrahedron cube 23 =
474 Tetrahedron fv' v0' v1' v2' v3' vol
481 fv' = rotate cwz $ rotate cwy
483 vol = tetrahedra_volume cube
486 -- Only used in tests, so we don't need the added speed
488 tetrahedra :: Cube -> [Tetrahedron]
489 tetrahedra cube = [ tetrahedron cube n | n <- [0..23] ]
491 front_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
492 front_left_top_tetrahedra cube =
493 V.singleton (tetrahedron cube 0) `V.snoc`
494 (tetrahedron cube 3) `V.snoc`
495 (tetrahedron cube 6) `V.snoc`
496 (tetrahedron cube 7) `V.snoc`
497 (tetrahedron cube 20) `V.snoc`
498 (tetrahedron cube 21)
500 front_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
501 front_left_down_tetrahedra cube =
502 V.singleton (tetrahedron cube 0) `V.snoc`
503 (tetrahedron cube 2) `V.snoc`
504 (tetrahedron cube 3) `V.snoc`
505 (tetrahedron cube 12) `V.snoc`
506 (tetrahedron cube 15) `V.snoc`
507 (tetrahedron cube 21)
509 front_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
510 front_right_top_tetrahedra cube =
511 V.singleton (tetrahedron cube 0) `V.snoc`
512 (tetrahedron cube 1) `V.snoc`
513 (tetrahedron cube 5) `V.snoc`
514 (tetrahedron cube 6) `V.snoc`
515 (tetrahedron cube 16) `V.snoc`
516 (tetrahedron cube 19)
518 front_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
519 front_right_down_tetrahedra cube =
520 V.singleton (tetrahedron cube 1) `V.snoc`
521 (tetrahedron cube 2) `V.snoc`
522 (tetrahedron cube 12) `V.snoc`
523 (tetrahedron cube 13) `V.snoc`
524 (tetrahedron cube 18) `V.snoc`
525 (tetrahedron cube 19)
527 back_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
528 back_left_top_tetrahedra cube =
529 V.singleton (tetrahedron cube 0) `V.snoc`
530 (tetrahedron cube 3) `V.snoc`
531 (tetrahedron cube 6) `V.snoc`
532 (tetrahedron cube 7) `V.snoc`
533 (tetrahedron cube 20) `V.snoc`
534 (tetrahedron cube 21)
536 back_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
537 back_left_down_tetrahedra cube =
538 V.singleton (tetrahedron cube 8) `V.snoc`
539 (tetrahedron cube 11) `V.snoc`
540 (tetrahedron cube 14) `V.snoc`
541 (tetrahedron cube 15) `V.snoc`
542 (tetrahedron cube 22) `V.snoc`
543 (tetrahedron cube 23)
545 back_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
546 back_right_top_tetrahedra cube =
547 V.singleton (tetrahedron cube 4) `V.snoc`
548 (tetrahedron cube 5) `V.snoc`
549 (tetrahedron cube 9) `V.snoc`
550 (tetrahedron cube 10) `V.snoc`
551 (tetrahedron cube 16) `V.snoc`
552 (tetrahedron cube 17)
554 back_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
555 back_right_down_tetrahedra cube =
556 V.singleton (tetrahedron cube 8) `V.snoc`
557 (tetrahedron cube 9) `V.snoc`
558 (tetrahedron cube 13) `V.snoc`
559 (tetrahedron cube 14) `V.snoc`
560 (tetrahedron cube 17) `V.snoc`
561 (tetrahedron cube 18)
563 in_top_half :: Cube -> Point -> Bool
564 in_top_half cube (Point _ _ z) =
565 distance_from_top <= distance_from_bottom
567 distance_from_top = abs $ (zmax cube) - z
568 distance_from_bottom = abs $ (zmin cube) - z
570 in_front_half :: Cube -> Point -> Bool
571 in_front_half cube (Point x _ _) =
572 distance_from_front <= distance_from_back
574 distance_from_front = abs $ (xmin cube) - x
575 distance_from_back = abs $ (xmax cube) - x
578 in_left_half :: Cube -> Point -> Bool
579 in_left_half cube (Point _ y _) =
580 distance_from_left <= distance_from_right
582 distance_from_left = abs $ (ymin cube) - y
583 distance_from_right = abs $ (ymax cube) - y
586 -- | Takes a 'Cube', and returns the Tetrahedra belonging to it that
587 -- contain the given 'Point'. This should be faster than checking
588 -- every tetrahedron individually, since we determine which half
589 -- (hemisphere?) of the cube the point lies in three times: once in
590 -- each dimension. This allows us to eliminate non-candidates
593 -- This can throw an exception, but the use of 'head' might
594 -- save us some unnecessary computations.
596 {-# INLINE find_containing_tetrahedron #-}
597 find_containing_tetrahedron :: Cube -> Point -> Tetrahedron
598 find_containing_tetrahedron cube p =
599 candidates `V.unsafeIndex` (fromJust lucky_idx)
601 front_half = in_front_half cube p
602 top_half = in_top_half cube p
603 left_half = in_left_half cube p
605 candidates :: V.Vector Tetrahedron
611 front_left_top_tetrahedra cube
613 front_left_down_tetrahedra cube
616 front_right_top_tetrahedra cube
618 front_right_down_tetrahedra cube
624 back_left_top_tetrahedra cube
626 back_left_down_tetrahedra cube
629 back_right_top_tetrahedra cube
631 back_right_down_tetrahedra cube
633 -- Use the dot product instead of Euclidean distance here to save
634 -- a sqrt(). So, "distances" below really means "distances
636 distances :: V.Vector Double
637 distances = V.map ((dot p) . barycenter) candidates
639 shortest_distance :: Double
640 shortest_distance = V.minimum distances
642 -- Compute the index of the tetrahedron with the center closest to
643 -- p. This is a bad algorithm, but don't change it! If you make it
644 -- smarter by finding the index of shortest_distance in distances
645 -- (this should give the same answer and avoids recomputing the
646 -- dot product), the program gets slower. Seriously!
647 lucky_idx :: Maybe Int
648 lucky_idx = V.findIndex
649 (\t -> (barycenter t) `dot` p == shortest_distance)
661 prop_opposite_octant_tetrahedra_disjoint1 :: Cube -> Bool
662 prop_opposite_octant_tetrahedra_disjoint1 cube =
663 disjoint (front_left_top_tetrahedra cube) (front_right_down_tetrahedra cube)
665 prop_opposite_octant_tetrahedra_disjoint2 :: Cube -> Bool
666 prop_opposite_octant_tetrahedra_disjoint2 cube =
667 disjoint (back_left_top_tetrahedra cube) (back_right_down_tetrahedra cube)
669 prop_opposite_octant_tetrahedra_disjoint3 :: Cube -> Bool
670 prop_opposite_octant_tetrahedra_disjoint3 cube =
671 disjoint (front_left_top_tetrahedra cube) (back_right_top_tetrahedra cube)
673 prop_opposite_octant_tetrahedra_disjoint4 :: Cube -> Bool
674 prop_opposite_octant_tetrahedra_disjoint4 cube =
675 disjoint (front_left_down_tetrahedra cube) (back_right_down_tetrahedra cube)
677 prop_opposite_octant_tetrahedra_disjoint5 :: Cube -> Bool
678 prop_opposite_octant_tetrahedra_disjoint5 cube =
679 disjoint (front_left_top_tetrahedra cube) (back_left_down_tetrahedra cube)
681 prop_opposite_octant_tetrahedra_disjoint6 :: Cube -> Bool
682 prop_opposite_octant_tetrahedra_disjoint6 cube =
683 disjoint (front_right_top_tetrahedra cube) (back_right_down_tetrahedra cube)
686 -- | Since the grid size is necessarily positive, all tetrahedra
687 -- (which comprise cubes of positive volume) must have positive
689 prop_all_volumes_positive :: Cube -> Bool
690 prop_all_volumes_positive cube =
694 volumes = map volume ts
697 -- | In fact, since all of the tetrahedra are identical, we should
698 -- already know their volumes. There's 24 tetrahedra to a cube, so
699 -- we'd expect the volume of each one to be 1/24.
700 prop_all_volumes_exact :: Cube -> Bool
701 prop_all_volumes_exact cube =
702 and [volume t ~~= 1/24 | t <- tetrahedra cube]
704 -- | All tetrahedron should have their v0 located at the center of the
706 prop_v0_all_equal :: Cube -> Bool
707 prop_v0_all_equal cube = (v0 t0) == (v0 t1)
709 t0 = head (tetrahedra cube) -- Doesn't matter which two we choose.
710 t1 = head $ tail (tetrahedra cube)
713 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Note that the
714 -- third and fourth indices of c-t3 have been switched. This is
715 -- because we store the triangles oriented such that their volume is
716 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
717 -- in opposite directions, one of them has to have negative volume!
718 prop_c0120_identity1 :: Cube -> Bool
719 prop_c0120_identity1 cube =
720 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
722 t0 = tetrahedron cube 0
723 t3 = tetrahedron cube 3
726 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
727 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
728 prop_c0120_identity2 :: Cube -> Bool
729 prop_c0120_identity2 cube =
730 c t1 0 1 2 0 ~= (c t1 0 0 2 1 + c t0 0 0 1 2) / 2
732 t0 = tetrahedron cube 0
733 t1 = tetrahedron cube 1
735 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
736 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
737 prop_c0120_identity3 :: Cube -> Bool
738 prop_c0120_identity3 cube =
739 c t2 0 1 2 0 ~= (c t2 0 0 2 1 + c t1 0 0 1 2) / 2
741 t1 = tetrahedron cube 1
742 t2 = tetrahedron cube 2
744 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
745 -- 'prop_c0120_identity1' with tetrahedrons 2 and 3.
746 prop_c0120_identity4 :: Cube -> Bool
747 prop_c0120_identity4 cube =
748 c t3 0 1 2 0 ~= (c t3 0 0 2 1 + c t2 0 0 1 2) / 2
750 t2 = tetrahedron cube 2
751 t3 = tetrahedron cube 3
754 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
755 -- 'prop_c0120_identity1' with tetrahedrons 4 and 5.
756 prop_c0120_identity5 :: Cube -> Bool
757 prop_c0120_identity5 cube =
758 c t5 0 1 2 0 ~= (c t5 0 0 2 1 + c t4 0 0 1 2) / 2
760 t4 = tetrahedron cube 4
761 t5 = tetrahedron cube 5
763 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
764 -- 'prop_c0120_identity1' with tetrahedrons 5 and 6.
765 prop_c0120_identity6 :: Cube -> Bool
766 prop_c0120_identity6 cube =
767 c t6 0 1 2 0 ~= (c t6 0 0 2 1 + c t5 0 0 1 2) / 2
769 t5 = tetrahedron cube 5
770 t6 = tetrahedron cube 6
773 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
774 -- 'prop_c0120_identity1' with tetrahedrons 6 and 7.
775 prop_c0120_identity7 :: Cube -> Bool
776 prop_c0120_identity7 cube =
777 c t7 0 1 2 0 ~= (c t7 0 0 2 1 + c t6 0 0 1 2) / 2
779 t6 = tetrahedron cube 6
780 t7 = tetrahedron cube 7
783 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
784 -- 'prop_c0120_identity1'.
785 prop_c0210_identity1 :: Cube -> Bool
786 prop_c0210_identity1 cube =
787 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
789 t0 = tetrahedron cube 0
790 t3 = tetrahedron cube 3
793 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
794 -- 'prop_c0120_identity1'.
795 prop_c0300_identity1 :: Cube -> Bool
796 prop_c0300_identity1 cube =
797 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
799 t0 = tetrahedron cube 0
800 t3 = tetrahedron cube 3
803 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
804 -- 'prop_c0120_identity1'.
805 prop_c1110_identity :: Cube -> Bool
806 prop_c1110_identity cube =
807 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
809 t0 = tetrahedron cube 0
810 t3 = tetrahedron cube 3
813 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
814 -- 'prop_c0120_identity1'.
815 prop_c1200_identity1 :: Cube -> Bool
816 prop_c1200_identity1 cube =
817 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
819 t0 = tetrahedron cube 0
820 t3 = tetrahedron cube 3
823 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
824 -- 'prop_c0120_identity1'.
825 prop_c2100_identity1 :: Cube -> Bool
826 prop_c2100_identity1 cube =
827 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
829 t0 = tetrahedron cube 0
830 t3 = tetrahedron cube 3
834 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). Note that the
835 -- third and fourth indices of c-t3 have been switched. This is
836 -- because we store the triangles oriented such that their volume is
837 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
838 -- point in opposite directions, one of them has to have negative
840 prop_c0102_identity1 :: Cube -> Bool
841 prop_c0102_identity1 cube =
842 c t0 0 1 0 2 ~= (c t0 0 0 1 2 + c t1 0 0 2 1) / 2
844 t0 = tetrahedron cube 0
845 t1 = tetrahedron cube 1
848 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
849 -- 'prop_c0102_identity1'.
850 prop_c0201_identity1 :: Cube -> Bool
851 prop_c0201_identity1 cube =
852 c t0 0 2 0 1 ~= (c t0 0 1 1 1 + c t1 0 1 1 1) / 2
854 t0 = tetrahedron cube 0
855 t1 = tetrahedron cube 1
858 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
859 -- 'prop_c0102_identity1'.
860 prop_c0300_identity2 :: Cube -> Bool
861 prop_c0300_identity2 cube =
862 c t0 0 3 0 0 ~= (c t0 0 2 1 0 + c t1 0 2 0 1) / 2
864 t0 = tetrahedron cube 0
865 t1 = tetrahedron cube 1
868 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
869 -- 'prop_c0102_identity1'.
870 prop_c1101_identity :: Cube -> Bool
871 prop_c1101_identity cube =
872 c t0 1 1 0 1 ~= (c t0 1 0 1 1 + c t1 1 0 1 1) / 2
874 t0 = tetrahedron cube 0
875 t1 = tetrahedron cube 1
878 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
879 -- 'prop_c0102_identity1'.
880 prop_c1200_identity2 :: Cube -> Bool
881 prop_c1200_identity2 cube =
882 c t0 1 2 0 0 ~= (c t0 1 1 1 0 + c t1 1 1 0 1) / 2
884 t0 = tetrahedron cube 0
885 t1 = tetrahedron cube 1
888 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
889 -- 'prop_c0102_identity1'.
890 prop_c2100_identity2 :: Cube -> Bool
891 prop_c2100_identity2 cube =
892 c t0 2 1 0 0 ~= (c t0 2 0 1 0 + c t1 2 0 0 1) / 2
894 t0 = tetrahedron cube 0
895 t1 = tetrahedron cube 1
898 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). The third and
899 -- fourth indices of c-t6 have been switched. This is because we
900 -- store the triangles oriented such that their volume is
901 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
902 -- point in opposite directions, one of them has to have negative
904 prop_c3000_identity :: Cube -> Bool
905 prop_c3000_identity cube =
906 c t0 3 0 0 0 ~= c t0 2 1 0 0 + c t6 2 1 0 0
907 - ((c t0 2 0 1 0 + c t0 2 0 0 1)/ 2)
909 t0 = tetrahedron cube 0
910 t6 = tetrahedron cube 6
913 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
914 -- 'prop_c3000_identity'.
915 prop_c2010_identity :: Cube -> Bool
916 prop_c2010_identity cube =
917 c t0 2 0 1 0 ~= c t0 1 1 1 0 + c t6 1 1 0 1
918 - ((c t0 1 0 2 0 + c t0 1 0 1 1)/ 2)
920 t0 = tetrahedron cube 0
921 t6 = tetrahedron cube 6
924 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
925 -- 'prop_c3000_identity'.
926 prop_c2001_identity :: Cube -> Bool
927 prop_c2001_identity cube =
928 c t0 2 0 0 1 ~= c t0 1 1 0 1 + c t6 1 1 1 0
929 - ((c t0 1 0 0 2 + c t0 1 0 1 1)/ 2)
931 t0 = tetrahedron cube 0
932 t6 = tetrahedron cube 6
935 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
936 -- 'prop_c3000_identity'.
937 prop_c1020_identity :: Cube -> Bool
938 prop_c1020_identity cube =
939 c t0 1 0 2 0 ~= c t0 0 1 2 0 + c t6 0 1 0 2
940 - ((c t0 0 0 3 0 + c t0 0 0 2 1)/ 2)
942 t0 = tetrahedron cube 0
943 t6 = tetrahedron cube 6
946 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
947 -- 'prop_c3000_identity'.
948 prop_c1002_identity :: Cube -> Bool
949 prop_c1002_identity cube =
950 c t0 1 0 0 2 ~= c t0 0 1 0 2 + c t6 0 1 2 0
951 - ((c t0 0 0 0 3 + c t0 0 0 1 2)/ 2)
953 t0 = tetrahedron cube 0
954 t6 = tetrahedron cube 6
957 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
958 -- 'prop_c3000_identity'.
959 prop_c1011_identity :: Cube -> Bool
960 prop_c1011_identity cube =
961 c t0 1 0 1 1 ~= c t0 0 1 1 1 + c t6 0 1 1 1 -
962 ((c t0 0 0 1 2 + c t0 0 0 2 1)/ 2)
964 t0 = tetrahedron cube 0
965 t6 = tetrahedron cube 6
968 -- | The function values at the interior should be the same for all
970 prop_interior_values_all_identical :: Cube -> Bool
971 prop_interior_values_all_identical cube =
972 all_equal [ eval (function_values tet) I | tet <- tetrahedra cube ]
975 -- | We know what (c t6 2 1 0 0) should be from Sorokina and Zeilfelder, p. 87.
976 -- This test checks the rotation works as expected.
977 prop_c_tilde_2100_rotation_correct :: Cube -> Bool
978 prop_c_tilde_2100_rotation_correct cube =
981 t0 = tetrahedron cube 0
982 t6 = tetrahedron cube 6
984 -- What gets computed for c2100 of t6.
985 expr1 = eval (function_values t6) $
987 (1/12)*(T + R + L + D) +
988 (1/64)*(FT + FR + FL + FD) +
991 (1/96)*(RT + LD + LT + RD) +
992 (1/192)*(BT + BR + BL + BD)
994 -- What should be computed for c2100 of t6.
995 expr2 = eval (function_values t0) $
997 (1/12)*(F + R + L + B) +
998 (1/64)*(FT + RT + LT + BT) +
1001 (1/96)*(FR + FL + BR + BL) +
1002 (1/192)*(FD + RD + LD + BD)
1005 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
1006 -- Zeilfelder, p. 87. This test checks the actual value based on
1007 -- the FunctionValues of the cube.
1009 -- If 'prop_c_tilde_2100_rotation_correct' passes, then this test is
1011 prop_c_tilde_2100_correct :: Cube -> Bool
1012 prop_c_tilde_2100_correct cube =
1013 c t6 2 1 0 0 == expected
1015 t0 = tetrahedron cube 0
1016 t6 = tetrahedron cube 6
1017 fvs = function_values t0
1018 expected = eval fvs $
1020 (1/12)*(F + R + L + B) +
1021 (1/64)*(FT + RT + LT + BT) +
1024 (1/96)*(FR + FL + BR + BL) +
1025 (1/192)*(FD + RD + LD + BD)
1028 -- Tests to check that the correct edges are incidental.
1029 prop_t0_shares_edge_with_t1 :: Cube -> Bool
1030 prop_t0_shares_edge_with_t1 cube =
1031 (v1 t0) == (v1 t1) && (v3 t0) == (v2 t1)
1033 t0 = tetrahedron cube 0
1034 t1 = tetrahedron cube 1
1036 prop_t0_shares_edge_with_t3 :: Cube -> Bool
1037 prop_t0_shares_edge_with_t3 cube =
1038 (v1 t0) == (v1 t3) && (v2 t0) == (v3 t3)
1040 t0 = tetrahedron cube 0
1041 t3 = tetrahedron cube 3
1043 prop_t0_shares_edge_with_t6 :: Cube -> Bool
1044 prop_t0_shares_edge_with_t6 cube =
1045 (v2 t0) == (v3 t6) && (v3 t0) == (v2 t6)
1047 t0 = tetrahedron cube 0
1048 t6 = tetrahedron cube 6
1050 prop_t1_shares_edge_with_t2 :: Cube -> Bool
1051 prop_t1_shares_edge_with_t2 cube =
1052 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1054 t1 = tetrahedron cube 1
1055 t2 = tetrahedron cube 2
1057 prop_t1_shares_edge_with_t19 :: Cube -> Bool
1058 prop_t1_shares_edge_with_t19 cube =
1059 (v2 t1) == (v3 t19) && (v3 t1) == (v2 t19)
1061 t1 = tetrahedron cube 1
1062 t19 = tetrahedron cube 19
1064 prop_t2_shares_edge_with_t3 :: Cube -> Bool
1065 prop_t2_shares_edge_with_t3 cube =
1066 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1068 t1 = tetrahedron cube 1
1069 t2 = tetrahedron cube 2
1071 prop_t2_shares_edge_with_t12 :: Cube -> Bool
1072 prop_t2_shares_edge_with_t12 cube =
1073 (v2 t2) == (v3 t12) && (v3 t2) == (v2 t12)
1075 t2 = tetrahedron cube 2
1076 t12 = tetrahedron cube 12
1078 prop_t3_shares_edge_with_t21 :: Cube -> Bool
1079 prop_t3_shares_edge_with_t21 cube =
1080 (v2 t3) == (v3 t21) && (v3 t3) == (v2 t21)
1082 t3 = tetrahedron cube 3
1083 t21 = tetrahedron cube 21
1085 prop_t4_shares_edge_with_t5 :: Cube -> Bool
1086 prop_t4_shares_edge_with_t5 cube =
1087 (v1 t4) == (v1 t5) && (v3 t4) == (v2 t5)
1089 t4 = tetrahedron cube 4
1090 t5 = tetrahedron cube 5
1092 prop_t4_shares_edge_with_t7 :: Cube -> Bool
1093 prop_t4_shares_edge_with_t7 cube =
1094 (v1 t4) == (v1 t7) && (v2 t4) == (v3 t7)
1096 t4 = tetrahedron cube 4
1097 t7 = tetrahedron cube 7
1099 prop_t4_shares_edge_with_t10 :: Cube -> Bool
1100 prop_t4_shares_edge_with_t10 cube =
1101 (v2 t4) == (v3 t10) && (v3 t4) == (v2 t10)
1103 t4 = tetrahedron cube 4
1104 t10 = tetrahedron cube 10
1106 prop_t5_shares_edge_with_t6 :: Cube -> Bool
1107 prop_t5_shares_edge_with_t6 cube =
1108 (v1 t5) == (v1 t6) && (v3 t5) == (v2 t6)
1110 t5 = tetrahedron cube 5
1111 t6 = tetrahedron cube 6
1113 prop_t5_shares_edge_with_t16 :: Cube -> Bool
1114 prop_t5_shares_edge_with_t16 cube =
1115 (v2 t5) == (v3 t16) && (v3 t5) == (v2 t16)
1117 t5 = tetrahedron cube 5
1118 t16 = tetrahedron cube 16
1120 prop_t6_shares_edge_with_t7 :: Cube -> Bool
1121 prop_t6_shares_edge_with_t7 cube =
1122 (v1 t6) == (v1 t7) && (v3 t6) == (v2 t7)
1124 t6 = tetrahedron cube 6
1125 t7 = tetrahedron cube 7
1127 prop_t7_shares_edge_with_t20 :: Cube -> Bool
1128 prop_t7_shares_edge_with_t20 cube =
1129 (v2 t7) == (v3 t20) && (v2 t7) == (v3 t20)
1131 t7 = tetrahedron cube 7
1132 t20 = tetrahedron cube 20
1135 p79_26_properties :: Test.Framework.Test
1137 testGroup "p. 79, Section (2.6) Properties" [
1138 testProperty "c0120 identity1" prop_c0120_identity1,
1139 testProperty "c0120 identity2" prop_c0120_identity2,
1140 testProperty "c0120 identity3" prop_c0120_identity3,
1141 testProperty "c0120 identity4" prop_c0120_identity4,
1142 testProperty "c0120 identity5" prop_c0120_identity5,
1143 testProperty "c0120 identity6" prop_c0120_identity6,
1144 testProperty "c0120 identity7" prop_c0120_identity7,
1145 testProperty "c0210 identity1" prop_c0210_identity1,
1146 testProperty "c0300 identity1" prop_c0300_identity1,
1147 testProperty "c1110 identity" prop_c1110_identity,
1148 testProperty "c1200 identity1" prop_c1200_identity1,
1149 testProperty "c2100 identity1" prop_c2100_identity1]
1151 p79_27_properties :: Test.Framework.Test
1153 testGroup "p. 79, Section (2.7) Properties" [
1154 testProperty "c0102 identity1" prop_c0102_identity1,
1155 testProperty "c0201 identity1" prop_c0201_identity1,
1156 testProperty "c0300 identity2" prop_c0300_identity2,
1157 testProperty "c1101 identity" prop_c1101_identity,
1158 testProperty "c1200 identity2" prop_c1200_identity2,
1159 testProperty "c2100 identity2" prop_c2100_identity2 ]
1162 p79_28_properties :: Test.Framework.Test
1164 testGroup "p. 79, Section (2.8) Properties" [
1165 testProperty "c3000 identity" prop_c3000_identity,
1166 testProperty "c2010 identity" prop_c2010_identity,
1167 testProperty "c2001 identity" prop_c2001_identity,
1168 testProperty "c1020 identity" prop_c1020_identity,
1169 testProperty "c1002 identity" prop_c1002_identity,
1170 testProperty "c1011 identity" prop_c1011_identity ]
1173 edge_incidence_tests :: Test.Framework.Test
1174 edge_incidence_tests =
1175 testGroup "Edge Incidence Tests" [
1176 testProperty "t0 shares edge with t6" prop_t0_shares_edge_with_t6,
1177 testProperty "t0 shares edge with t1" prop_t0_shares_edge_with_t1,
1178 testProperty "t0 shares edge with t3" prop_t0_shares_edge_with_t3,
1179 testProperty "t1 shares edge with t2" prop_t1_shares_edge_with_t2,
1180 testProperty "t1 shares edge with t19" prop_t1_shares_edge_with_t19,
1181 testProperty "t2 shares edge with t3" prop_t2_shares_edge_with_t3,
1182 testProperty "t2 shares edge with t12" prop_t2_shares_edge_with_t12,
1183 testProperty "t3 shares edge with t21" prop_t3_shares_edge_with_t21,
1184 testProperty "t4 shares edge with t5" prop_t4_shares_edge_with_t5,
1185 testProperty "t4 shares edge with t7" prop_t4_shares_edge_with_t7,
1186 testProperty "t4 shares edge with t10" prop_t4_shares_edge_with_t10,
1187 testProperty "t5 shares edge with t6" prop_t5_shares_edge_with_t6,
1188 testProperty "t5 shares edge with t16" prop_t5_shares_edge_with_t16,
1189 testProperty "t6 shares edge with t7" prop_t6_shares_edge_with_t7,
1190 testProperty "t7 shares edge with t20" prop_t7_shares_edge_with_t20 ]
1192 cube_properties :: Test.Framework.Test
1194 testGroup "Cube Properties" [
1198 edge_incidence_tests,
1199 testProperty "opposite octant tetrahedra are disjoint (1)"
1200 prop_opposite_octant_tetrahedra_disjoint1,
1201 testProperty "opposite octant tetrahedra are disjoint (2)"
1202 prop_opposite_octant_tetrahedra_disjoint2,
1203 testProperty "opposite octant tetrahedra are disjoint (3)"
1204 prop_opposite_octant_tetrahedra_disjoint3,
1205 testProperty "opposite octant tetrahedra are disjoint (4)"
1206 prop_opposite_octant_tetrahedra_disjoint4,
1207 testProperty "opposite octant tetrahedra are disjoint (5)"
1208 prop_opposite_octant_tetrahedra_disjoint5,
1209 testProperty "opposite octant tetrahedra are disjoint (6)"
1210 prop_opposite_octant_tetrahedra_disjoint6,
1211 testProperty "all volumes positive" prop_all_volumes_positive,
1212 testProperty "all volumes exact" prop_all_volumes_exact,
1213 testProperty "v0 all equal" prop_v0_all_equal,
1214 testProperty "interior values all identical"
1215 prop_interior_values_all_identical,
1216 testProperty "c-tilde_2100 rotation correct"
1217 prop_c_tilde_2100_rotation_correct,
1218 testProperty "c-tilde_2100 correct"
1219 prop_c_tilde_2100_correct ]