4 find_containing_tetrahedron,
10 import Data.Maybe (fromJust)
11 import qualified Data.Vector as V (
21 import Prelude hiding (LT)
22 import Test.Framework (Test, testGroup)
23 import Test.Framework.Providers.QuickCheck2 (testProperty)
24 import Test.QuickCheck (Arbitrary(..), Gen, Positive(..), choose)
27 import Comparisons ((~=), (~~=))
28 import qualified Face (Face(..), center)
29 import FunctionValues (FunctionValues, eval, rotate)
30 import Misc (all_equal, disjoint)
31 import Point (Point(..), dot)
32 import Tetrahedron (Tetrahedron(..), barycenter, c, volume)
34 data Cube = Cube { i :: !Int,
37 fv :: !FunctionValues,
38 tetrahedra_volume :: !Double }
42 instance Arbitrary Cube where
44 i' <- choose (coordmin, coordmax)
45 j' <- choose (coordmin, coordmax)
46 k' <- choose (coordmin, coordmax)
47 fv' <- arbitrary :: Gen FunctionValues
48 (Positive tet_vol) <- arbitrary :: Gen (Positive Double)
49 return (Cube i' j' k' fv' tet_vol)
51 -- The idea here is that, when cubed in the volume formula,
52 -- these numbers don't overflow 64 bits. This number is not
53 -- magic in any other sense than that it does not cause test
54 -- failures, while 2^23 does.
55 coordmax = 4194304 -- 2^22
59 instance Show Cube where
61 "Cube_" ++ subscript ++ "\n" ++
62 " Center: " ++ (show (center cube)) ++ "\n" ++
63 " xmin: " ++ (show (xmin cube)) ++ "\n" ++
64 " xmax: " ++ (show (xmax cube)) ++ "\n" ++
65 " ymin: " ++ (show (ymin cube)) ++ "\n" ++
66 " ymax: " ++ (show (ymax cube)) ++ "\n" ++
67 " zmin: " ++ (show (zmin cube)) ++ "\n" ++
68 " zmax: " ++ (show (zmax 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)
79 i' = fromIntegral (i cube) :: Double
81 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
83 xmax :: Cube -> Double
84 xmax cube = (i' + 1/2)
86 i' = fromIntegral (i cube) :: Double
88 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
90 ymin :: Cube -> Double
91 ymin cube = (j' - 1/2)
93 j' = fromIntegral (j cube) :: Double
95 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
97 ymax :: Cube -> Double
98 ymax cube = (j' + 1/2)
100 j' = fromIntegral (j cube) :: Double
102 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
104 zmin :: Cube -> Double
105 zmin cube = (k' - 1/2)
107 k' = fromIntegral (k cube) :: Double
109 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
111 zmax :: Cube -> Double
112 zmax cube = (k' + 1/2)
114 k' = fromIntegral (k cube) :: Double
117 -- | The center of Cube_ijk coincides with v_ijk at
118 -- (i, j, k). See Sorokina and Zeilfelder, p. 76.
119 center :: Cube -> Point
123 x = fromIntegral (i cube) :: Double
124 y = fromIntegral (j cube) :: Double
125 z = fromIntegral (k cube) :: Double
130 -- | The top (in the direction of z) face of the cube.
131 top_face :: Cube -> Face.Face
132 top_face cube = Face.Face v0' v1' v2' v3'
136 v0' = cc + ( Point delta (-delta) delta )
137 v1' = cc + ( Point delta delta delta )
138 v2' = cc + ( Point (-delta) delta delta )
139 v3' = cc + ( Point (-delta) (-delta) delta )
143 -- | The back (in the direction of x) face of the cube.
144 back_face :: Cube -> Face.Face
145 back_face cube = Face.Face v0' v1' v2' v3'
149 v0' = cc + ( Point delta (-delta) (-delta) )
150 v1' = cc + ( Point delta delta (-delta) )
151 v2' = cc + ( Point delta delta delta )
152 v3' = cc + ( Point delta (-delta) delta )
155 -- The bottom face (in the direction of -z) of the cube.
156 down_face :: Cube -> Face.Face
157 down_face cube = Face.Face v0' v1' v2' v3'
161 v0' = cc + ( Point (-delta) (-delta) (-delta) )
162 v1' = cc + ( Point (-delta) delta (-delta) )
163 v2' = cc + ( Point delta delta (-delta) )
164 v3' = cc + ( Point delta (-delta) (-delta) )
168 -- | The front (in the direction of -x) face of the cube.
169 front_face :: Cube -> Face.Face
170 front_face cube = Face.Face v0' v1' v2' v3'
174 v0' = cc + ( Point (-delta) (-delta) delta )
175 v1' = cc + ( Point (-delta) delta delta )
176 v2' = cc + ( Point (-delta) delta (-delta) )
177 v3' = cc + ( Point (-delta) (-delta) (-delta) )
179 -- | The left (in the direction of -y) face of the cube.
180 left_face :: Cube -> Face.Face
181 left_face cube = Face.Face v0' v1' v2' v3'
185 v0' = cc + ( Point delta (-delta) delta )
186 v1' = cc + ( Point (-delta) (-delta) delta )
187 v2' = cc + ( Point (-delta) (-delta) (-delta) )
188 v3' = cc + ( Point delta (-delta) (-delta) )
191 -- | The right (in the direction of y) face of the cube.
192 right_face :: Cube -> Face.Face
193 right_face cube = Face.Face v0' v1' v2' v3'
197 v0' = cc + ( Point (-delta) delta delta)
198 v1' = cc + ( Point delta delta delta )
199 v2' = cc + ( Point delta delta (-delta) )
200 v3' = cc + ( Point (-delta) delta (-delta) )
203 tetrahedron :: Cube -> Int -> Tetrahedron
206 Tetrahedron (fv cube) v0' v1' v2' v3' vol
213 vol = tetrahedra_volume cube
216 Tetrahedron fv' v0' v1' v2' v3' vol
223 fv' = rotate ccwx (fv cube)
224 vol = tetrahedra_volume cube
227 Tetrahedron fv' v0' v1' v2' v3' vol
234 fv' = rotate ccwx $ rotate ccwx $ fv cube
235 vol = tetrahedra_volume cube
238 Tetrahedron fv' v0' v1' v2' v3' vol
245 fv' = rotate cwx (fv cube)
246 vol = tetrahedra_volume cube
249 Tetrahedron fv' v0' v1' v2' v3' vol
256 fv' = rotate cwy (fv cube)
257 vol = tetrahedra_volume cube
260 Tetrahedron fv' v0' v1' v2' v3' vol
267 fv' = rotate cwy $ rotate cwz $ fv cube
268 vol = tetrahedra_volume cube
271 Tetrahedron fv' v0' v1' v2' v3' vol
278 fv' = rotate cwy $ rotate cwz
281 vol = tetrahedra_volume cube
284 Tetrahedron fv' v0' v1' v2' v3' vol
291 fv' = rotate cwy $ rotate ccwz $ fv cube
292 vol = tetrahedra_volume cube
295 Tetrahedron fv' v0' v1' v2' v3' vol
302 fv' = rotate cwy $ rotate cwy $ fv cube
303 vol = tetrahedra_volume cube
306 Tetrahedron fv' v0' v1' v2' v3' vol
313 fv' = rotate cwy $ rotate cwy
316 vol = tetrahedra_volume cube
318 tetrahedron cube 10 =
319 Tetrahedron fv' v0' v1' v2' v3' vol
326 fv' = rotate cwy $ rotate cwy
331 vol = tetrahedra_volume cube
333 tetrahedron cube 11 =
334 Tetrahedron fv' v0' v1' v2' v3' vol
341 fv' = rotate cwy $ rotate cwy
344 vol = tetrahedra_volume cube
346 tetrahedron cube 12 =
347 Tetrahedron fv' v0' v1' v2' v3' vol
354 fv' = rotate ccwy $ fv cube
355 vol = tetrahedra_volume cube
357 tetrahedron cube 13 =
358 Tetrahedron fv' v0' v1' v2' v3' vol
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
376 fv' = rotate ccwy $ rotate ccwz
379 vol = tetrahedra_volume cube
381 tetrahedron cube 15 =
382 Tetrahedron fv' v0' v1' v2' v3' vol
389 fv' = rotate ccwy $ rotate cwz $ fv cube
390 vol = tetrahedra_volume cube
392 tetrahedron cube 16 =
393 Tetrahedron fv' v0' v1' v2' v3' vol
400 fv' = rotate ccwz $ fv cube
401 vol = tetrahedra_volume cube
403 tetrahedron cube 17 =
404 Tetrahedron fv' v0' v1' v2' v3' vol
411 fv' = rotate ccwz $ rotate cwy $ fv cube
412 vol = tetrahedra_volume cube
414 tetrahedron cube 18 =
415 Tetrahedron fv' v0' v1' v2' v3' vol
422 fv' = rotate ccwz $ rotate cwy
425 vol = tetrahedra_volume cube
427 tetrahedron cube 19 =
428 Tetrahedron fv' v0' v1' v2' v3' vol
435 fv' = rotate ccwz $ rotate ccwy
437 vol = tetrahedra_volume cube
439 tetrahedron cube 20 =
440 Tetrahedron fv' v0' v1' v2' v3' vol
447 fv' = rotate cwz $ fv cube
448 vol = tetrahedra_volume cube
450 tetrahedron cube 21 =
451 Tetrahedron fv' v0' v1' v2' v3' vol
458 fv' = rotate cwz $ rotate ccwy $ fv cube
459 vol = tetrahedra_volume cube
461 tetrahedron cube 22 =
462 Tetrahedron fv' v0' v1' v2' v3' vol
469 fv' = rotate cwz $ rotate ccwy
472 vol = tetrahedra_volume cube
474 tetrahedron cube 23 =
475 Tetrahedron fv' v0' v1' v2' v3' vol
482 fv' = rotate cwz $ rotate cwy
484 vol = tetrahedra_volume cube
487 -- Only used in tests, so we don't need the added speed
489 tetrahedra :: Cube -> [Tetrahedron]
490 tetrahedra cube = [ tetrahedron cube n | n <- [0..23] ]
492 front_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
493 front_left_top_tetrahedra cube =
494 V.singleton (tetrahedron cube 0) `V.snoc`
495 (tetrahedron cube 3) `V.snoc`
496 (tetrahedron cube 6) `V.snoc`
497 (tetrahedron cube 7) `V.snoc`
498 (tetrahedron cube 20) `V.snoc`
499 (tetrahedron cube 21)
501 front_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
502 front_left_down_tetrahedra cube =
503 V.singleton (tetrahedron cube 0) `V.snoc`
504 (tetrahedron cube 2) `V.snoc`
505 (tetrahedron cube 3) `V.snoc`
506 (tetrahedron cube 12) `V.snoc`
507 (tetrahedron cube 15) `V.snoc`
508 (tetrahedron cube 21)
510 front_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
511 front_right_top_tetrahedra cube =
512 V.singleton (tetrahedron cube 0) `V.snoc`
513 (tetrahedron cube 1) `V.snoc`
514 (tetrahedron cube 5) `V.snoc`
515 (tetrahedron cube 6) `V.snoc`
516 (tetrahedron cube 16) `V.snoc`
517 (tetrahedron cube 19)
519 front_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
520 front_right_down_tetrahedra cube =
521 V.singleton (tetrahedron cube 1) `V.snoc`
522 (tetrahedron cube 2) `V.snoc`
523 (tetrahedron cube 12) `V.snoc`
524 (tetrahedron cube 13) `V.snoc`
525 (tetrahedron cube 18) `V.snoc`
526 (tetrahedron cube 19)
528 back_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
529 back_left_top_tetrahedra cube =
530 V.singleton (tetrahedron cube 0) `V.snoc`
531 (tetrahedron cube 3) `V.snoc`
532 (tetrahedron cube 6) `V.snoc`
533 (tetrahedron cube 7) `V.snoc`
534 (tetrahedron cube 20) `V.snoc`
535 (tetrahedron cube 21)
537 back_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
538 back_left_down_tetrahedra cube =
539 V.singleton (tetrahedron cube 8) `V.snoc`
540 (tetrahedron cube 11) `V.snoc`
541 (tetrahedron cube 14) `V.snoc`
542 (tetrahedron cube 15) `V.snoc`
543 (tetrahedron cube 22) `V.snoc`
544 (tetrahedron cube 23)
546 back_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
547 back_right_top_tetrahedra cube =
548 V.singleton (tetrahedron cube 4) `V.snoc`
549 (tetrahedron cube 5) `V.snoc`
550 (tetrahedron cube 9) `V.snoc`
551 (tetrahedron cube 10) `V.snoc`
552 (tetrahedron cube 16) `V.snoc`
553 (tetrahedron cube 17)
555 back_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
556 back_right_down_tetrahedra cube =
557 V.singleton (tetrahedron cube 8) `V.snoc`
558 (tetrahedron cube 9) `V.snoc`
559 (tetrahedron cube 13) `V.snoc`
560 (tetrahedron cube 14) `V.snoc`
561 (tetrahedron cube 17) `V.snoc`
562 (tetrahedron cube 18)
564 in_top_half :: Cube -> Point -> Bool
565 in_top_half cube (Point _ _ z) =
566 distance_from_top <= distance_from_bottom
568 distance_from_top = abs $ (zmax cube) - z
569 distance_from_bottom = abs $ (zmin cube) - z
571 in_front_half :: Cube -> Point -> Bool
572 in_front_half cube (Point x _ _) =
573 distance_from_front <= distance_from_back
575 distance_from_front = abs $ (xmin cube) - x
576 distance_from_back = abs $ (xmax cube) - x
579 in_left_half :: Cube -> Point -> Bool
580 in_left_half cube (Point _ y _) =
581 distance_from_left <= distance_from_right
583 distance_from_left = abs $ (ymin cube) - y
584 distance_from_right = abs $ (ymax cube) - y
587 -- | Takes a 'Cube', and returns the Tetrahedra belonging to it that
588 -- contain the given 'Point'. This should be faster than checking
589 -- every tetrahedron individually, since we determine which half
590 -- (hemisphere?) of the cube the point lies in three times: once in
591 -- each dimension. This allows us to eliminate non-candidates
594 -- This can throw an exception, but the use of 'head' might
595 -- save us some unnecessary computations.
597 {-# INLINE find_containing_tetrahedron #-}
598 find_containing_tetrahedron :: Cube -> Point -> Tetrahedron
599 find_containing_tetrahedron cube p =
600 candidates `V.unsafeIndex` (fromJust lucky_idx)
602 front_half = in_front_half cube p
603 top_half = in_top_half cube p
604 left_half = in_left_half cube p
606 candidates :: V.Vector Tetrahedron
612 front_left_top_tetrahedra cube
614 front_left_down_tetrahedra cube
617 front_right_top_tetrahedra cube
619 front_right_down_tetrahedra cube
625 back_left_top_tetrahedra cube
627 back_left_down_tetrahedra cube
630 back_right_top_tetrahedra cube
632 back_right_down_tetrahedra cube
634 -- Use the dot product instead of Euclidean distance here to save
635 -- a sqrt(). So, "distances" below really means "distances
637 distances :: V.Vector Double
638 distances = V.map ((dot p) . barycenter) candidates
640 shortest_distance :: Double
641 shortest_distance = V.minimum distances
643 -- Compute the index of the tetrahedron with the center closest to
644 -- p. This is a bad algorithm, but don't change it! If you make it
645 -- smarter by finding the index of shortest_distance in distances
646 -- (this should give the same answer and avoids recomputing the
647 -- dot product), the program gets slower. Seriously!
648 lucky_idx :: Maybe Int
649 lucky_idx = V.findIndex
650 (\t -> (barycenter t) `dot` p == shortest_distance)
662 prop_opposite_octant_tetrahedra_disjoint1 :: Cube -> Bool
663 prop_opposite_octant_tetrahedra_disjoint1 cube =
664 disjoint (front_left_top_tetrahedra cube) (front_right_down_tetrahedra cube)
666 prop_opposite_octant_tetrahedra_disjoint2 :: Cube -> Bool
667 prop_opposite_octant_tetrahedra_disjoint2 cube =
668 disjoint (back_left_top_tetrahedra cube) (back_right_down_tetrahedra cube)
670 prop_opposite_octant_tetrahedra_disjoint3 :: Cube -> Bool
671 prop_opposite_octant_tetrahedra_disjoint3 cube =
672 disjoint (front_left_top_tetrahedra cube) (back_right_top_tetrahedra cube)
674 prop_opposite_octant_tetrahedra_disjoint4 :: Cube -> Bool
675 prop_opposite_octant_tetrahedra_disjoint4 cube =
676 disjoint (front_left_down_tetrahedra cube) (back_right_down_tetrahedra cube)
678 prop_opposite_octant_tetrahedra_disjoint5 :: Cube -> Bool
679 prop_opposite_octant_tetrahedra_disjoint5 cube =
680 disjoint (front_left_top_tetrahedra cube) (back_left_down_tetrahedra cube)
682 prop_opposite_octant_tetrahedra_disjoint6 :: Cube -> Bool
683 prop_opposite_octant_tetrahedra_disjoint6 cube =
684 disjoint (front_right_top_tetrahedra cube) (back_right_down_tetrahedra cube)
687 -- | Since the grid size is necessarily positive, all tetrahedra
688 -- (which comprise cubes of positive volume) must have positive
690 prop_all_volumes_positive :: Cube -> Bool
691 prop_all_volumes_positive cube =
695 volumes = map volume ts
698 -- | In fact, since all of the tetrahedra are identical, we should
699 -- already know their volumes. There's 24 tetrahedra to a cube, so
700 -- we'd expect the volume of each one to be 1/24.
701 prop_all_volumes_exact :: Cube -> Bool
702 prop_all_volumes_exact cube =
703 and [volume t ~~= 1/24 | t <- tetrahedra cube]
705 -- | All tetrahedron should have their v0 located at the center of the
707 prop_v0_all_equal :: Cube -> Bool
708 prop_v0_all_equal cube = (v0 t0) == (v0 t1)
710 t0 = head (tetrahedra cube) -- Doesn't matter which two we choose.
711 t1 = head $ tail (tetrahedra cube)
714 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Note that the
715 -- third and fourth indices of c-t3 have been switched. This is
716 -- because we store the triangles oriented such that their volume is
717 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
718 -- in opposite directions, one of them has to have negative volume!
719 prop_c0120_identity1 :: Cube -> Bool
720 prop_c0120_identity1 cube =
721 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
723 t0 = tetrahedron cube 0
724 t3 = tetrahedron cube 3
727 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
728 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
729 prop_c0120_identity2 :: Cube -> Bool
730 prop_c0120_identity2 cube =
731 c t1 0 1 2 0 ~= (c t1 0 0 2 1 + c t0 0 0 1 2) / 2
733 t0 = tetrahedron cube 0
734 t1 = tetrahedron cube 1
736 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
737 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
738 prop_c0120_identity3 :: Cube -> Bool
739 prop_c0120_identity3 cube =
740 c t2 0 1 2 0 ~= (c t2 0 0 2 1 + c t1 0 0 1 2) / 2
742 t1 = tetrahedron cube 1
743 t2 = tetrahedron cube 2
745 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
746 -- 'prop_c0120_identity1' with tetrahedrons 2 and 3.
747 prop_c0120_identity4 :: Cube -> Bool
748 prop_c0120_identity4 cube =
749 c t3 0 1 2 0 ~= (c t3 0 0 2 1 + c t2 0 0 1 2) / 2
751 t2 = tetrahedron cube 2
752 t3 = tetrahedron cube 3
755 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
756 -- 'prop_c0120_identity1' with tetrahedrons 4 and 5.
757 prop_c0120_identity5 :: Cube -> Bool
758 prop_c0120_identity5 cube =
759 c t5 0 1 2 0 ~= (c t5 0 0 2 1 + c t4 0 0 1 2) / 2
761 t4 = tetrahedron cube 4
762 t5 = tetrahedron cube 5
764 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
765 -- 'prop_c0120_identity1' with tetrahedrons 5 and 6.
766 prop_c0120_identity6 :: Cube -> Bool
767 prop_c0120_identity6 cube =
768 c t6 0 1 2 0 ~= (c t6 0 0 2 1 + c t5 0 0 1 2) / 2
770 t5 = tetrahedron cube 5
771 t6 = tetrahedron cube 6
774 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
775 -- 'prop_c0120_identity1' with tetrahedrons 6 and 7.
776 prop_c0120_identity7 :: Cube -> Bool
777 prop_c0120_identity7 cube =
778 c t7 0 1 2 0 ~= (c t7 0 0 2 1 + c t6 0 0 1 2) / 2
780 t6 = tetrahedron cube 6
781 t7 = tetrahedron cube 7
784 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
785 -- 'prop_c0120_identity1'.
786 prop_c0210_identity1 :: Cube -> Bool
787 prop_c0210_identity1 cube =
788 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
790 t0 = tetrahedron cube 0
791 t3 = tetrahedron cube 3
794 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
795 -- 'prop_c0120_identity1'.
796 prop_c0300_identity1 :: Cube -> Bool
797 prop_c0300_identity1 cube =
798 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
800 t0 = tetrahedron cube 0
801 t3 = tetrahedron cube 3
804 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
805 -- 'prop_c0120_identity1'.
806 prop_c1110_identity :: Cube -> Bool
807 prop_c1110_identity cube =
808 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
810 t0 = tetrahedron cube 0
811 t3 = tetrahedron cube 3
814 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
815 -- 'prop_c0120_identity1'.
816 prop_c1200_identity1 :: Cube -> Bool
817 prop_c1200_identity1 cube =
818 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
820 t0 = tetrahedron cube 0
821 t3 = tetrahedron cube 3
824 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
825 -- 'prop_c0120_identity1'.
826 prop_c2100_identity1 :: Cube -> Bool
827 prop_c2100_identity1 cube =
828 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
830 t0 = tetrahedron cube 0
831 t3 = tetrahedron cube 3
835 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). Note that the
836 -- third and fourth indices of c-t3 have been switched. This is
837 -- because we store the triangles oriented such that their volume is
838 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
839 -- point in opposite directions, one of them has to have negative
841 prop_c0102_identity1 :: Cube -> Bool
842 prop_c0102_identity1 cube =
843 c t0 0 1 0 2 ~= (c t0 0 0 1 2 + c t1 0 0 2 1) / 2
845 t0 = tetrahedron cube 0
846 t1 = tetrahedron cube 1
849 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
850 -- 'prop_c0102_identity1'.
851 prop_c0201_identity1 :: Cube -> Bool
852 prop_c0201_identity1 cube =
853 c t0 0 2 0 1 ~= (c t0 0 1 1 1 + c t1 0 1 1 1) / 2
855 t0 = tetrahedron cube 0
856 t1 = tetrahedron cube 1
859 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
860 -- 'prop_c0102_identity1'.
861 prop_c0300_identity2 :: Cube -> Bool
862 prop_c0300_identity2 cube =
863 c t0 0 3 0 0 ~= (c t0 0 2 1 0 + c t1 0 2 0 1) / 2
865 t0 = tetrahedron cube 0
866 t1 = tetrahedron cube 1
869 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
870 -- 'prop_c0102_identity1'.
871 prop_c1101_identity :: Cube -> Bool
872 prop_c1101_identity cube =
873 c t0 1 1 0 1 ~= (c t0 1 0 1 1 + c t1 1 0 1 1) / 2
875 t0 = tetrahedron cube 0
876 t1 = tetrahedron cube 1
879 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
880 -- 'prop_c0102_identity1'.
881 prop_c1200_identity2 :: Cube -> Bool
882 prop_c1200_identity2 cube =
883 c t0 1 2 0 0 ~= (c t0 1 1 1 0 + c t1 1 1 0 1) / 2
885 t0 = tetrahedron cube 0
886 t1 = tetrahedron cube 1
889 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
890 -- 'prop_c0102_identity1'.
891 prop_c2100_identity2 :: Cube -> Bool
892 prop_c2100_identity2 cube =
893 c t0 2 1 0 0 ~= (c t0 2 0 1 0 + c t1 2 0 0 1) / 2
895 t0 = tetrahedron cube 0
896 t1 = tetrahedron cube 1
899 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). The third and
900 -- fourth indices of c-t6 have been switched. This is because we
901 -- store the triangles oriented such that their volume is
902 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
903 -- point in opposite directions, one of them has to have negative
905 prop_c3000_identity :: Cube -> Bool
906 prop_c3000_identity cube =
907 c t0 3 0 0 0 ~= c t0 2 1 0 0 + c t6 2 1 0 0
908 - ((c t0 2 0 1 0 + c t0 2 0 0 1)/ 2)
910 t0 = tetrahedron cube 0
911 t6 = tetrahedron cube 6
914 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
915 -- 'prop_c3000_identity'.
916 prop_c2010_identity :: Cube -> Bool
917 prop_c2010_identity cube =
918 c t0 2 0 1 0 ~= c t0 1 1 1 0 + c t6 1 1 0 1
919 - ((c t0 1 0 2 0 + c t0 1 0 1 1)/ 2)
921 t0 = tetrahedron cube 0
922 t6 = tetrahedron cube 6
925 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
926 -- 'prop_c3000_identity'.
927 prop_c2001_identity :: Cube -> Bool
928 prop_c2001_identity cube =
929 c t0 2 0 0 1 ~= c t0 1 1 0 1 + c t6 1 1 1 0
930 - ((c t0 1 0 0 2 + c t0 1 0 1 1)/ 2)
932 t0 = tetrahedron cube 0
933 t6 = tetrahedron cube 6
936 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
937 -- 'prop_c3000_identity'.
938 prop_c1020_identity :: Cube -> Bool
939 prop_c1020_identity cube =
940 c t0 1 0 2 0 ~= c t0 0 1 2 0 + c t6 0 1 0 2
941 - ((c t0 0 0 3 0 + c t0 0 0 2 1)/ 2)
943 t0 = tetrahedron cube 0
944 t6 = tetrahedron cube 6
947 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
948 -- 'prop_c3000_identity'.
949 prop_c1002_identity :: Cube -> Bool
950 prop_c1002_identity cube =
951 c t0 1 0 0 2 ~= c t0 0 1 0 2 + c t6 0 1 2 0
952 - ((c t0 0 0 0 3 + c t0 0 0 1 2)/ 2)
954 t0 = tetrahedron cube 0
955 t6 = tetrahedron cube 6
958 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
959 -- 'prop_c3000_identity'.
960 prop_c1011_identity :: Cube -> Bool
961 prop_c1011_identity cube =
962 c t0 1 0 1 1 ~= c t0 0 1 1 1 + c t6 0 1 1 1 -
963 ((c t0 0 0 1 2 + c t0 0 0 2 1)/ 2)
965 t0 = tetrahedron cube 0
966 t6 = tetrahedron cube 6
969 -- | The function values at the interior should be the same for all
971 prop_interior_values_all_identical :: Cube -> Bool
972 prop_interior_values_all_identical cube =
973 all_equal [ eval (function_values tet) I | tet <- tetrahedra cube ]
976 -- | We know what (c t6 2 1 0 0) should be from Sorokina and Zeilfelder, p. 87.
977 -- This test checks the rotation works as expected.
978 prop_c_tilde_2100_rotation_correct :: Cube -> Bool
979 prop_c_tilde_2100_rotation_correct cube =
982 t0 = tetrahedron cube 0
983 t6 = tetrahedron cube 6
985 -- What gets computed for c2100 of t6.
986 expr1 = eval (function_values t6) $
988 (1/12)*(T + R + L + D) +
989 (1/64)*(FT + FR + FL + FD) +
992 (1/96)*(RT + LD + LT + RD) +
993 (1/192)*(BT + BR + BL + BD)
995 -- What should be computed for c2100 of t6.
996 expr2 = eval (function_values t0) $
998 (1/12)*(F + R + L + B) +
999 (1/64)*(FT + RT + LT + BT) +
1002 (1/96)*(FR + FL + BR + BL) +
1003 (1/192)*(FD + RD + LD + BD)
1006 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
1007 -- Zeilfelder, p. 87. This test checks the actual value based on
1008 -- the FunctionValues of the cube.
1010 -- If 'prop_c_tilde_2100_rotation_correct' passes, then this test is
1012 prop_c_tilde_2100_correct :: Cube -> Bool
1013 prop_c_tilde_2100_correct cube =
1014 c t6 2 1 0 0 ~= expected
1016 t0 = tetrahedron cube 0
1017 t6 = tetrahedron cube 6
1018 fvs = function_values t0
1019 expected = eval fvs $
1021 (1/12)*(F + R + L + B) +
1022 (1/64)*(FT + RT + LT + BT) +
1025 (1/96)*(FR + FL + BR + BL) +
1026 (1/192)*(FD + RD + LD + BD)
1029 -- Tests to check that the correct edges are incidental.
1030 prop_t0_shares_edge_with_t1 :: Cube -> Bool
1031 prop_t0_shares_edge_with_t1 cube =
1032 (v1 t0) == (v1 t1) && (v3 t0) == (v2 t1)
1034 t0 = tetrahedron cube 0
1035 t1 = tetrahedron cube 1
1037 prop_t0_shares_edge_with_t3 :: Cube -> Bool
1038 prop_t0_shares_edge_with_t3 cube =
1039 (v1 t0) == (v1 t3) && (v2 t0) == (v3 t3)
1041 t0 = tetrahedron cube 0
1042 t3 = tetrahedron cube 3
1044 prop_t0_shares_edge_with_t6 :: Cube -> Bool
1045 prop_t0_shares_edge_with_t6 cube =
1046 (v2 t0) == (v3 t6) && (v3 t0) == (v2 t6)
1048 t0 = tetrahedron cube 0
1049 t6 = tetrahedron cube 6
1051 prop_t1_shares_edge_with_t2 :: Cube -> Bool
1052 prop_t1_shares_edge_with_t2 cube =
1053 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1055 t1 = tetrahedron cube 1
1056 t2 = tetrahedron cube 2
1058 prop_t1_shares_edge_with_t19 :: Cube -> Bool
1059 prop_t1_shares_edge_with_t19 cube =
1060 (v2 t1) == (v3 t19) && (v3 t1) == (v2 t19)
1062 t1 = tetrahedron cube 1
1063 t19 = tetrahedron cube 19
1065 prop_t2_shares_edge_with_t3 :: Cube -> Bool
1066 prop_t2_shares_edge_with_t3 cube =
1067 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1069 t1 = tetrahedron cube 1
1070 t2 = tetrahedron cube 2
1072 prop_t2_shares_edge_with_t12 :: Cube -> Bool
1073 prop_t2_shares_edge_with_t12 cube =
1074 (v2 t2) == (v3 t12) && (v3 t2) == (v2 t12)
1076 t2 = tetrahedron cube 2
1077 t12 = tetrahedron cube 12
1079 prop_t3_shares_edge_with_t21 :: Cube -> Bool
1080 prop_t3_shares_edge_with_t21 cube =
1081 (v2 t3) == (v3 t21) && (v3 t3) == (v2 t21)
1083 t3 = tetrahedron cube 3
1084 t21 = tetrahedron cube 21
1086 prop_t4_shares_edge_with_t5 :: Cube -> Bool
1087 prop_t4_shares_edge_with_t5 cube =
1088 (v1 t4) == (v1 t5) && (v3 t4) == (v2 t5)
1090 t4 = tetrahedron cube 4
1091 t5 = tetrahedron cube 5
1093 prop_t4_shares_edge_with_t7 :: Cube -> Bool
1094 prop_t4_shares_edge_with_t7 cube =
1095 (v1 t4) == (v1 t7) && (v2 t4) == (v3 t7)
1097 t4 = tetrahedron cube 4
1098 t7 = tetrahedron cube 7
1100 prop_t4_shares_edge_with_t10 :: Cube -> Bool
1101 prop_t4_shares_edge_with_t10 cube =
1102 (v2 t4) == (v3 t10) && (v3 t4) == (v2 t10)
1104 t4 = tetrahedron cube 4
1105 t10 = tetrahedron cube 10
1107 prop_t5_shares_edge_with_t6 :: Cube -> Bool
1108 prop_t5_shares_edge_with_t6 cube =
1109 (v1 t5) == (v1 t6) && (v3 t5) == (v2 t6)
1111 t5 = tetrahedron cube 5
1112 t6 = tetrahedron cube 6
1114 prop_t5_shares_edge_with_t16 :: Cube -> Bool
1115 prop_t5_shares_edge_with_t16 cube =
1116 (v2 t5) == (v3 t16) && (v3 t5) == (v2 t16)
1118 t5 = tetrahedron cube 5
1119 t16 = tetrahedron cube 16
1121 prop_t6_shares_edge_with_t7 :: Cube -> Bool
1122 prop_t6_shares_edge_with_t7 cube =
1123 (v1 t6) == (v1 t7) && (v3 t6) == (v2 t7)
1125 t6 = tetrahedron cube 6
1126 t7 = tetrahedron cube 7
1128 prop_t7_shares_edge_with_t20 :: Cube -> Bool
1129 prop_t7_shares_edge_with_t20 cube =
1130 (v2 t7) == (v3 t20) && (v2 t7) == (v3 t20)
1132 t7 = tetrahedron cube 7
1133 t20 = tetrahedron cube 20
1136 p79_26_properties :: Test.Framework.Test
1138 testGroup "p. 79, Section (2.6) Properties" [
1139 testProperty "c0120 identity1" prop_c0120_identity1,
1140 testProperty "c0120 identity2" prop_c0120_identity2,
1141 testProperty "c0120 identity3" prop_c0120_identity3,
1142 testProperty "c0120 identity4" prop_c0120_identity4,
1143 testProperty "c0120 identity5" prop_c0120_identity5,
1144 testProperty "c0120 identity6" prop_c0120_identity6,
1145 testProperty "c0120 identity7" prop_c0120_identity7,
1146 testProperty "c0210 identity1" prop_c0210_identity1,
1147 testProperty "c0300 identity1" prop_c0300_identity1,
1148 testProperty "c1110 identity" prop_c1110_identity,
1149 testProperty "c1200 identity1" prop_c1200_identity1,
1150 testProperty "c2100 identity1" prop_c2100_identity1]
1152 p79_27_properties :: Test.Framework.Test
1154 testGroup "p. 79, Section (2.7) Properties" [
1155 testProperty "c0102 identity1" prop_c0102_identity1,
1156 testProperty "c0201 identity1" prop_c0201_identity1,
1157 testProperty "c0300 identity2" prop_c0300_identity2,
1158 testProperty "c1101 identity" prop_c1101_identity,
1159 testProperty "c1200 identity2" prop_c1200_identity2,
1160 testProperty "c2100 identity2" prop_c2100_identity2 ]
1163 p79_28_properties :: Test.Framework.Test
1165 testGroup "p. 79, Section (2.8) Properties" [
1166 testProperty "c3000 identity" prop_c3000_identity,
1167 testProperty "c2010 identity" prop_c2010_identity,
1168 testProperty "c2001 identity" prop_c2001_identity,
1169 testProperty "c1020 identity" prop_c1020_identity,
1170 testProperty "c1002 identity" prop_c1002_identity,
1171 testProperty "c1011 identity" prop_c1011_identity ]
1174 edge_incidence_tests :: Test.Framework.Test
1175 edge_incidence_tests =
1176 testGroup "Edge Incidence Tests" [
1177 testProperty "t0 shares edge with t6" prop_t0_shares_edge_with_t6,
1178 testProperty "t0 shares edge with t1" prop_t0_shares_edge_with_t1,
1179 testProperty "t0 shares edge with t3" prop_t0_shares_edge_with_t3,
1180 testProperty "t1 shares edge with t2" prop_t1_shares_edge_with_t2,
1181 testProperty "t1 shares edge with t19" prop_t1_shares_edge_with_t19,
1182 testProperty "t2 shares edge with t3" prop_t2_shares_edge_with_t3,
1183 testProperty "t2 shares edge with t12" prop_t2_shares_edge_with_t12,
1184 testProperty "t3 shares edge with t21" prop_t3_shares_edge_with_t21,
1185 testProperty "t4 shares edge with t5" prop_t4_shares_edge_with_t5,
1186 testProperty "t4 shares edge with t7" prop_t4_shares_edge_with_t7,
1187 testProperty "t4 shares edge with t10" prop_t4_shares_edge_with_t10,
1188 testProperty "t5 shares edge with t6" prop_t5_shares_edge_with_t6,
1189 testProperty "t5 shares edge with t16" prop_t5_shares_edge_with_t16,
1190 testProperty "t6 shares edge with t7" prop_t6_shares_edge_with_t7,
1191 testProperty "t7 shares edge with t20" prop_t7_shares_edge_with_t20 ]
1193 cube_properties :: Test.Framework.Test
1195 testGroup "Cube Properties" [
1199 edge_incidence_tests,
1200 testProperty "opposite octant tetrahedra are disjoint (1)"
1201 prop_opposite_octant_tetrahedra_disjoint1,
1202 testProperty "opposite octant tetrahedra are disjoint (2)"
1203 prop_opposite_octant_tetrahedra_disjoint2,
1204 testProperty "opposite octant tetrahedra are disjoint (3)"
1205 prop_opposite_octant_tetrahedra_disjoint3,
1206 testProperty "opposite octant tetrahedra are disjoint (4)"
1207 prop_opposite_octant_tetrahedra_disjoint4,
1208 testProperty "opposite octant tetrahedra are disjoint (5)"
1209 prop_opposite_octant_tetrahedra_disjoint5,
1210 testProperty "opposite octant tetrahedra are disjoint (6)"
1211 prop_opposite_octant_tetrahedra_disjoint6,
1212 testProperty "all volumes positive" prop_all_volumes_positive,
1213 testProperty "all volumes exact" prop_all_volumes_exact,
1214 testProperty "v0 all equal" prop_v0_all_equal,
1215 testProperty "interior values all identical"
1216 prop_interior_values_all_identical,
1217 testProperty "c-tilde_2100 rotation correct"
1218 prop_c_tilde_2100_rotation_correct,
1219 testProperty "c-tilde_2100 correct"
1220 prop_c_tilde_2100_correct ]