4 find_containing_tetrahedron,
9 import Data.Maybe ( fromJust )
10 import qualified Data.Vector as V (
18 import Prelude hiding ( LT )
19 import Test.Tasty ( TestTree, testGroup )
20 import Test.Tasty.QuickCheck (
34 import Comparisons ( (~=), (~~=) )
35 import qualified Face ( Face(..), center )
36 import FunctionValues ( FunctionValues, eval, rotate )
37 import Misc ( all_equal, disjoint )
38 import Point ( Point(..), dot )
39 import Tetrahedron ( Tetrahedron(..), barycenter, c, volume )
41 data Cube = Cube { i :: !Int,
44 fv :: !FunctionValues,
45 tetrahedra_volume :: !Double }
49 instance Arbitrary Cube where
51 i' <- choose (coordmin, coordmax)
52 j' <- choose (coordmin, coordmax)
53 k' <- choose (coordmin, coordmax)
54 fv' <- arbitrary :: Gen FunctionValues
55 (Positive tet_vol) <- arbitrary :: Gen (Positive Double)
56 return (Cube i' j' k' fv' tet_vol)
58 -- The idea here is that, when cubed in the volume formula,
59 -- these numbers don't overflow 64 bits. This number is not
60 -- magic in any other sense than that it does not cause test
61 -- failures, while 2^23 does.
62 coordmax = 4194304 :: Int -- 2^22
66 instance Show Cube where
68 "Cube_" ++ subscript ++ "\n" ++
69 " Center: " ++ (show (center cube)) ++ "\n" ++
70 " xmin: " ++ (show (xmin cube)) ++ "\n" ++
71 " xmax: " ++ (show (xmax cube)) ++ "\n" ++
72 " ymin: " ++ (show (ymin cube)) ++ "\n" ++
73 " ymax: " ++ (show (ymax cube)) ++ "\n" ++
74 " zmin: " ++ (show (zmin cube)) ++ "\n" ++
75 " zmax: " ++ (show (zmax cube)) ++ "\n"
78 (show (i cube)) ++ "," ++ (show (j cube)) ++ "," ++ (show (k cube))
81 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
83 xmin :: Cube -> Double
84 xmin cube = (i' - 1/2)
86 i' = fromIntegral (i cube) :: Double
88 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
90 xmax :: Cube -> Double
91 xmax cube = (i' + 1/2)
93 i' = fromIntegral (i cube) :: Double
95 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
97 ymin :: Cube -> Double
98 ymin cube = (j' - 1/2)
100 j' = fromIntegral (j cube) :: Double
102 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
104 ymax :: Cube -> Double
105 ymax cube = (j' + 1/2)
107 j' = fromIntegral (j cube) :: Double
109 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
111 zmin :: Cube -> Double
112 zmin cube = (k' - 1/2)
114 k' = fromIntegral (k cube) :: Double
116 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
118 zmax :: Cube -> Double
119 zmax cube = (k' + 1/2)
121 k' = fromIntegral (k cube) :: Double
124 -- | The center of Cube_ijk coincides with v_ijk at
125 -- (i, j, k). See Sorokina and Zeilfelder, p. 76.
126 center :: Cube -> Point
130 x = fromIntegral (i cube) :: Double
131 y = fromIntegral (j cube) :: Double
132 z = fromIntegral (k cube) :: Double
137 -- | The top (in the direction of z) face of the cube.
138 top_face :: Cube -> Face.Face
139 top_face cube = Face.Face v0' v1' v2' v3'
141 delta = (1/2) :: Double
143 v0' = cc + ( Point delta (-delta) delta )
144 v1' = cc + ( Point delta delta delta )
145 v2' = cc + ( Point (-delta) delta delta )
146 v3' = cc + ( Point (-delta) (-delta) delta )
150 -- | The back (in the direction of x) face of the cube.
151 back_face :: Cube -> Face.Face
152 back_face cube = Face.Face v0' v1' v2' v3'
154 delta = (1/2) :: Double
156 v0' = cc + ( Point delta (-delta) (-delta) )
157 v1' = cc + ( Point delta delta (-delta) )
158 v2' = cc + ( Point delta delta delta )
159 v3' = cc + ( Point delta (-delta) delta )
162 -- The bottom face (in the direction of -z) of the cube.
163 down_face :: Cube -> Face.Face
164 down_face cube = Face.Face v0' v1' v2' v3'
166 delta = (1/2) :: Double
168 v0' = cc + ( Point (-delta) (-delta) (-delta) )
169 v1' = cc + ( Point (-delta) delta (-delta) )
170 v2' = cc + ( Point delta delta (-delta) )
171 v3' = cc + ( Point delta (-delta) (-delta) )
175 -- | The front (in the direction of -x) face of the cube.
176 front_face :: Cube -> Face.Face
177 front_face cube = Face.Face v0' v1' v2' v3'
179 delta = (1/2) :: Double
181 v0' = cc + ( Point (-delta) (-delta) delta )
182 v1' = cc + ( Point (-delta) delta delta )
183 v2' = cc + ( Point (-delta) delta (-delta) )
184 v3' = cc + ( Point (-delta) (-delta) (-delta) )
186 -- | The left (in the direction of -y) face of the cube.
187 left_face :: Cube -> Face.Face
188 left_face cube = Face.Face v0' v1' v2' v3'
190 delta = (1/2) :: Double
192 v0' = cc + ( Point delta (-delta) delta )
193 v1' = cc + ( Point (-delta) (-delta) delta )
194 v2' = cc + ( Point (-delta) (-delta) (-delta) )
195 v3' = cc + ( Point delta (-delta) (-delta) )
198 -- | The right (in the direction of y) face of the cube.
199 right_face :: Cube -> Face.Face
200 right_face cube = Face.Face v0' v1' v2' v3'
202 delta = (1/2) :: Double
204 v0' = cc + ( Point (-delta) delta delta)
205 v1' = cc + ( Point delta delta delta )
206 v2' = cc + ( Point delta delta (-delta) )
207 v3' = cc + ( Point (-delta) delta (-delta) )
210 tetrahedron :: Cube -> Int -> Tetrahedron
213 Tetrahedron (fv cube) v0' v1' v2' v3' vol
220 vol = tetrahedra_volume cube
223 Tetrahedron fv' v0' v1' v2' v3' vol
230 fv' = rotate ccwx (fv cube)
231 vol = tetrahedra_volume cube
234 Tetrahedron fv' v0' v1' v2' v3' vol
241 fv' = rotate ccwx $ rotate ccwx $ fv cube
242 vol = tetrahedra_volume cube
245 Tetrahedron fv' v0' v1' v2' v3' vol
252 fv' = rotate cwx (fv cube)
253 vol = tetrahedra_volume cube
256 Tetrahedron fv' v0' v1' v2' v3' vol
263 fv' = rotate cwy (fv cube)
264 vol = tetrahedra_volume cube
267 Tetrahedron fv' v0' v1' v2' v3' vol
274 fv' = rotate cwy $ rotate cwz $ fv cube
275 vol = tetrahedra_volume cube
278 Tetrahedron fv' v0' v1' v2' v3' vol
285 fv' = rotate cwy $ rotate cwz
288 vol = tetrahedra_volume cube
291 Tetrahedron fv' v0' v1' v2' v3' vol
298 fv' = rotate cwy $ rotate ccwz $ fv cube
299 vol = tetrahedra_volume cube
302 Tetrahedron fv' v0' v1' v2' v3' vol
309 fv' = rotate cwy $ rotate cwy $ fv cube
310 vol = tetrahedra_volume cube
313 Tetrahedron fv' v0' v1' v2' v3' vol
320 fv' = rotate cwy $ rotate cwy
323 vol = tetrahedra_volume cube
325 tetrahedron cube 10 =
326 Tetrahedron fv' v0' v1' v2' v3' vol
333 fv' = rotate cwy $ rotate cwy
338 vol = tetrahedra_volume cube
340 tetrahedron cube 11 =
341 Tetrahedron fv' v0' v1' v2' v3' vol
348 fv' = rotate cwy $ rotate cwy
351 vol = tetrahedra_volume cube
353 tetrahedron cube 12 =
354 Tetrahedron fv' v0' v1' v2' v3' vol
361 fv' = rotate ccwy $ fv cube
362 vol = tetrahedra_volume cube
364 tetrahedron cube 13 =
365 Tetrahedron fv' v0' v1' v2' v3' vol
372 fv' = rotate ccwy $ rotate ccwz $ fv cube
373 vol = tetrahedra_volume cube
375 tetrahedron cube 14 =
376 Tetrahedron fv' v0' v1' v2' v3' vol
383 fv' = rotate ccwy $ rotate ccwz
386 vol = tetrahedra_volume cube
388 tetrahedron cube 15 =
389 Tetrahedron fv' v0' v1' v2' v3' vol
396 fv' = rotate ccwy $ rotate cwz $ fv cube
397 vol = tetrahedra_volume cube
399 tetrahedron cube 16 =
400 Tetrahedron fv' v0' v1' v2' v3' vol
407 fv' = rotate ccwz $ fv cube
408 vol = tetrahedra_volume cube
410 tetrahedron cube 17 =
411 Tetrahedron fv' v0' v1' v2' v3' vol
418 fv' = rotate ccwz $ rotate cwy $ fv cube
419 vol = tetrahedra_volume cube
421 tetrahedron cube 18 =
422 Tetrahedron fv' v0' v1' v2' v3' vol
429 fv' = rotate ccwz $ rotate cwy
432 vol = tetrahedra_volume cube
434 tetrahedron cube 19 =
435 Tetrahedron fv' v0' v1' v2' v3' vol
442 fv' = rotate ccwz $ rotate ccwy
444 vol = tetrahedra_volume cube
446 tetrahedron cube 20 =
447 Tetrahedron fv' v0' v1' v2' v3' vol
454 fv' = rotate cwz $ fv cube
455 vol = tetrahedra_volume cube
457 tetrahedron cube 21 =
458 Tetrahedron fv' v0' v1' v2' v3' vol
465 fv' = rotate cwz $ rotate ccwy $ fv cube
466 vol = tetrahedra_volume cube
468 tetrahedron cube 22 =
469 Tetrahedron fv' v0' v1' v2' v3' vol
476 fv' = rotate cwz $ rotate ccwy
479 vol = tetrahedra_volume cube
481 tetrahedron cube 23 =
482 Tetrahedron fv' v0' v1' v2' v3' vol
489 fv' = rotate cwz $ rotate cwy
491 vol = tetrahedra_volume cube
494 -- Only used in tests, so we don't need the added speed
496 tetrahedra :: Cube -> [Tetrahedron]
497 tetrahedra cube = [ tetrahedron cube n | n <- [0..23] ]
499 front_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
500 front_left_top_tetrahedra cube =
501 V.singleton (tetrahedron cube 0) `V.snoc`
502 (tetrahedron cube 3) `V.snoc`
503 (tetrahedron cube 6) `V.snoc`
504 (tetrahedron cube 7) `V.snoc`
505 (tetrahedron cube 20) `V.snoc`
506 (tetrahedron cube 21)
508 front_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
509 front_left_down_tetrahedra cube =
510 V.singleton (tetrahedron cube 0) `V.snoc`
511 (tetrahedron cube 2) `V.snoc`
512 (tetrahedron cube 3) `V.snoc`
513 (tetrahedron cube 12) `V.snoc`
514 (tetrahedron cube 15) `V.snoc`
515 (tetrahedron cube 21)
517 front_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
518 front_right_top_tetrahedra cube =
519 V.singleton (tetrahedron cube 0) `V.snoc`
520 (tetrahedron cube 1) `V.snoc`
521 (tetrahedron cube 5) `V.snoc`
522 (tetrahedron cube 6) `V.snoc`
523 (tetrahedron cube 16) `V.snoc`
524 (tetrahedron cube 19)
526 front_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
527 front_right_down_tetrahedra cube =
528 V.singleton (tetrahedron cube 1) `V.snoc`
529 (tetrahedron cube 2) `V.snoc`
530 (tetrahedron cube 12) `V.snoc`
531 (tetrahedron cube 13) `V.snoc`
532 (tetrahedron cube 18) `V.snoc`
533 (tetrahedron cube 19)
535 back_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
536 back_left_top_tetrahedra cube =
537 V.singleton (tetrahedron cube 0) `V.snoc`
538 (tetrahedron cube 3) `V.snoc`
539 (tetrahedron cube 6) `V.snoc`
540 (tetrahedron cube 7) `V.snoc`
541 (tetrahedron cube 20) `V.snoc`
542 (tetrahedron cube 21)
544 back_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
545 back_left_down_tetrahedra cube =
546 V.singleton (tetrahedron cube 8) `V.snoc`
547 (tetrahedron cube 11) `V.snoc`
548 (tetrahedron cube 14) `V.snoc`
549 (tetrahedron cube 15) `V.snoc`
550 (tetrahedron cube 22) `V.snoc`
551 (tetrahedron cube 23)
553 back_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
554 back_right_top_tetrahedra cube =
555 V.singleton (tetrahedron cube 4) `V.snoc`
556 (tetrahedron cube 5) `V.snoc`
557 (tetrahedron cube 9) `V.snoc`
558 (tetrahedron cube 10) `V.snoc`
559 (tetrahedron cube 16) `V.snoc`
560 (tetrahedron cube 17)
562 back_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
563 back_right_down_tetrahedra cube =
564 V.singleton (tetrahedron cube 8) `V.snoc`
565 (tetrahedron cube 9) `V.snoc`
566 (tetrahedron cube 13) `V.snoc`
567 (tetrahedron cube 14) `V.snoc`
568 (tetrahedron cube 17) `V.snoc`
569 (tetrahedron cube 18)
571 in_top_half :: Cube -> Point -> Bool
572 in_top_half cube (Point _ _ z) =
573 distance_from_top <= distance_from_bottom
575 distance_from_top = abs $ (zmax cube) - z
576 distance_from_bottom = abs $ (zmin cube) - z
578 in_front_half :: Cube -> Point -> Bool
579 in_front_half cube (Point x _ _) =
580 distance_from_front <= distance_from_back
582 distance_from_front = abs $ (xmin cube) - x
583 distance_from_back = abs $ (xmax cube) - x
586 in_left_half :: Cube -> Point -> Bool
587 in_left_half cube (Point _ y _) =
588 distance_from_left <= distance_from_right
590 distance_from_left = abs $ (ymin cube) - y
591 distance_from_right = abs $ (ymax cube) - y
594 -- | Takes a 'Cube', and returns the Tetrahedra belonging to it that
595 -- contain the given 'Point'. This should be faster than checking
596 -- every tetrahedron individually, since we determine which half
597 -- (hemisphere?) of the cube the point lies in three times: once in
598 -- each dimension. This allows us to eliminate non-candidates
601 -- This can throw an exception, but the use of 'head' might
602 -- save us some unnecessary computations.
604 {-# INLINE find_containing_tetrahedron #-}
605 find_containing_tetrahedron :: Cube -> Point -> Tetrahedron
606 find_containing_tetrahedron cube p =
607 candidates `V.unsafeIndex` (fromJust lucky_idx)
609 front_half = in_front_half cube p
610 top_half = in_top_half cube p
611 left_half = in_left_half cube p
613 candidates :: V.Vector Tetrahedron
618 front_left_top_tetrahedra cube
620 front_left_down_tetrahedra cube
623 front_right_top_tetrahedra cube
625 front_right_down_tetrahedra cube
627 | otherwise = -- back half
630 back_left_top_tetrahedra cube
632 back_left_down_tetrahedra cube
635 back_right_top_tetrahedra cube
637 back_right_down_tetrahedra cube
639 -- Use the dot product instead of Euclidean distance here to save
640 -- a sqrt(). So, "distances" below really means "distances
642 distances :: V.Vector Double
643 distances = V.map ((dot p) . barycenter) candidates
645 shortest_distance :: Double
646 shortest_distance = V.minimum distances
648 -- Compute the index of the tetrahedron with the center closest to
649 -- p. This is a bad algorithm, but don't change it! If you make it
650 -- smarter by finding the index of shortest_distance in distances
651 -- (this should give the same answer and avoids recomputing the
652 -- dot product), the program gets slower. Seriously!
653 lucky_idx :: Maybe Int
654 lucky_idx = V.findIndex
655 (\t -> (barycenter t) `dot` p == shortest_distance)
665 prop_opposite_octant_tetrahedra_disjoint1 :: Cube -> Bool
666 prop_opposite_octant_tetrahedra_disjoint1 cube =
667 disjoint (front_left_top_tetrahedra cube) (front_right_down_tetrahedra cube)
669 prop_opposite_octant_tetrahedra_disjoint2 :: Cube -> Bool
670 prop_opposite_octant_tetrahedra_disjoint2 cube =
671 disjoint (back_left_top_tetrahedra cube) (back_right_down_tetrahedra cube)
673 prop_opposite_octant_tetrahedra_disjoint3 :: Cube -> Bool
674 prop_opposite_octant_tetrahedra_disjoint3 cube =
675 disjoint (front_left_top_tetrahedra cube) (back_right_top_tetrahedra cube)
677 prop_opposite_octant_tetrahedra_disjoint4 :: Cube -> Bool
678 prop_opposite_octant_tetrahedra_disjoint4 cube =
679 disjoint (front_left_down_tetrahedra cube) (back_right_down_tetrahedra cube)
681 prop_opposite_octant_tetrahedra_disjoint5 :: Cube -> Bool
682 prop_opposite_octant_tetrahedra_disjoint5 cube =
683 disjoint (front_left_top_tetrahedra cube) (back_left_down_tetrahedra cube)
685 prop_opposite_octant_tetrahedra_disjoint6 :: Cube -> Bool
686 prop_opposite_octant_tetrahedra_disjoint6 cube =
687 disjoint (front_right_top_tetrahedra cube) (back_right_down_tetrahedra cube)
690 -- | Since the grid size is necessarily positive, all tetrahedra
691 -- (which comprise cubes of positive volume) must have positive
693 prop_all_volumes_positive :: Cube -> Bool
694 prop_all_volumes_positive cube =
698 volumes = map volume ts
701 -- | In fact, since all of the tetrahedra are identical, we should
702 -- already know their volumes. There's 24 tetrahedra to a cube, so
703 -- we'd expect the volume of each one to be 1/24.
704 prop_all_volumes_exact :: Cube -> Bool
705 prop_all_volumes_exact cube =
706 and [volume t ~~= 1/24 | t <- tetrahedra cube]
708 -- | All tetrahedron should have their v0 located at the center of the
710 prop_v0_all_equal :: Cube -> Bool
711 prop_v0_all_equal cube = (v0 t0) == (v0 t1)
713 t0 = head (tetrahedra cube) -- Doesn't matter which two we choose.
714 t1 = head $ tail (tetrahedra cube)
717 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Note that the
718 -- third and fourth indices of c-t3 have been switched. This is
719 -- because we store the triangles oriented such that their volume is
720 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
721 -- in opposite directions, one of them has to have negative volume!
722 prop_c0120_identity1 :: Cube -> Bool
723 prop_c0120_identity1 cube =
724 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
726 t0 = tetrahedron cube 0
727 t3 = tetrahedron cube 3
730 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
731 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
732 prop_c0120_identity2 :: Cube -> Bool
733 prop_c0120_identity2 cube =
734 c t1 0 1 2 0 ~= (c t1 0 0 2 1 + c t0 0 0 1 2) / 2
736 t0 = tetrahedron cube 0
737 t1 = tetrahedron cube 1
739 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
740 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
741 prop_c0120_identity3 :: Cube -> Bool
742 prop_c0120_identity3 cube =
743 c t2 0 1 2 0 ~= (c t2 0 0 2 1 + c t1 0 0 1 2) / 2
745 t1 = tetrahedron cube 1
746 t2 = tetrahedron cube 2
748 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
749 -- 'prop_c0120_identity1' with tetrahedrons 2 and 3.
750 prop_c0120_identity4 :: Cube -> Bool
751 prop_c0120_identity4 cube =
752 c t3 0 1 2 0 ~= (c t3 0 0 2 1 + c t2 0 0 1 2) / 2
754 t2 = tetrahedron cube 2
755 t3 = tetrahedron cube 3
758 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
759 -- 'prop_c0120_identity1' with tetrahedrons 4 and 5.
760 prop_c0120_identity5 :: Cube -> Bool
761 prop_c0120_identity5 cube =
762 c t5 0 1 2 0 ~= (c t5 0 0 2 1 + c t4 0 0 1 2) / 2
764 t4 = tetrahedron cube 4
765 t5 = tetrahedron cube 5
767 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
768 -- 'prop_c0120_identity1' with tetrahedrons 5 and 6.
769 prop_c0120_identity6 :: Cube -> Bool
770 prop_c0120_identity6 cube =
771 c t6 0 1 2 0 ~= (c t6 0 0 2 1 + c t5 0 0 1 2) / 2
773 t5 = tetrahedron cube 5
774 t6 = tetrahedron cube 6
777 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
778 -- 'prop_c0120_identity1' with tetrahedrons 6 and 7.
779 prop_c0120_identity7 :: Cube -> Bool
780 prop_c0120_identity7 cube =
781 c t7 0 1 2 0 ~= (c t7 0 0 2 1 + c t6 0 0 1 2) / 2
783 t6 = tetrahedron cube 6
784 t7 = tetrahedron cube 7
787 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
788 -- 'prop_c0120_identity1'.
789 prop_c0210_identity1 :: Cube -> Bool
790 prop_c0210_identity1 cube =
791 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
793 t0 = tetrahedron cube 0
794 t3 = tetrahedron cube 3
797 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
798 -- 'prop_c0120_identity1'.
799 prop_c0300_identity1 :: Cube -> Bool
800 prop_c0300_identity1 cube =
801 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
803 t0 = tetrahedron cube 0
804 t3 = tetrahedron cube 3
807 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
808 -- 'prop_c0120_identity1'.
809 prop_c1110_identity :: Cube -> Bool
810 prop_c1110_identity cube =
811 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
813 t0 = tetrahedron cube 0
814 t3 = tetrahedron cube 3
817 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
818 -- 'prop_c0120_identity1'.
819 prop_c1200_identity1 :: Cube -> Bool
820 prop_c1200_identity1 cube =
821 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
823 t0 = tetrahedron cube 0
824 t3 = tetrahedron cube 3
827 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
828 -- 'prop_c0120_identity1'.
829 prop_c2100_identity1 :: Cube -> Bool
830 prop_c2100_identity1 cube =
831 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
833 t0 = tetrahedron cube 0
834 t3 = tetrahedron cube 3
838 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). Note that the
839 -- third and fourth indices of c-t3 have been switched. This is
840 -- because we store the triangles oriented such that their volume is
841 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
842 -- point in opposite directions, one of them has to have negative
844 prop_c0102_identity1 :: Cube -> Bool
845 prop_c0102_identity1 cube =
846 c t0 0 1 0 2 ~= (c t0 0 0 1 2 + c t1 0 0 2 1) / 2
848 t0 = tetrahedron cube 0
849 t1 = tetrahedron cube 1
852 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
853 -- 'prop_c0102_identity1'.
854 prop_c0201_identity1 :: Cube -> Bool
855 prop_c0201_identity1 cube =
856 c t0 0 2 0 1 ~= (c t0 0 1 1 1 + c t1 0 1 1 1) / 2
858 t0 = tetrahedron cube 0
859 t1 = tetrahedron cube 1
862 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
863 -- 'prop_c0102_identity1'.
864 prop_c0300_identity2 :: Cube -> Bool
865 prop_c0300_identity2 cube =
866 c t0 0 3 0 0 ~= (c t0 0 2 1 0 + c t1 0 2 0 1) / 2
868 t0 = tetrahedron cube 0
869 t1 = tetrahedron cube 1
872 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
873 -- 'prop_c0102_identity1'.
874 prop_c1101_identity :: Cube -> Bool
875 prop_c1101_identity cube =
876 c t0 1 1 0 1 ~= (c t0 1 0 1 1 + c t1 1 0 1 1) / 2
878 t0 = tetrahedron cube 0
879 t1 = tetrahedron cube 1
882 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
883 -- 'prop_c0102_identity1'.
884 prop_c1200_identity2 :: Cube -> Bool
885 prop_c1200_identity2 cube =
886 c t0 1 2 0 0 ~= (c t0 1 1 1 0 + c t1 1 1 0 1) / 2
888 t0 = tetrahedron cube 0
889 t1 = tetrahedron cube 1
892 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
893 -- 'prop_c0102_identity1'.
894 prop_c2100_identity2 :: Cube -> Bool
895 prop_c2100_identity2 cube =
896 c t0 2 1 0 0 ~= (c t0 2 0 1 0 + c t1 2 0 0 1) / 2
898 t0 = tetrahedron cube 0
899 t1 = tetrahedron cube 1
902 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). The third and
903 -- fourth indices of c-t6 have been switched. This is because we
904 -- store the triangles oriented such that their volume is
905 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
906 -- point in opposite directions, one of them has to have negative
908 prop_c3000_identity :: Cube -> Bool
909 prop_c3000_identity cube =
910 c t0 3 0 0 0 ~= c t0 2 1 0 0 + c t6 2 1 0 0
911 - ((c t0 2 0 1 0 + c t0 2 0 0 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_c2010_identity :: Cube -> Bool
920 prop_c2010_identity cube =
921 c t0 2 0 1 0 ~= c t0 1 1 1 0 + c t6 1 1 0 1
922 - ((c t0 1 0 2 0 + c t0 1 0 1 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_c2001_identity :: Cube -> Bool
931 prop_c2001_identity cube =
932 c t0 2 0 0 1 ~= c t0 1 1 0 1 + c t6 1 1 1 0
933 - ((c t0 1 0 0 2 + c t0 1 0 1 1)/ 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_c1020_identity :: Cube -> Bool
942 prop_c1020_identity cube =
943 c t0 1 0 2 0 ~= c t0 0 1 2 0 + c t6 0 1 0 2
944 - ((c t0 0 0 3 0 + c t0 0 0 2 1)/ 2)
946 t0 = tetrahedron cube 0
947 t6 = tetrahedron cube 6
950 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
951 -- 'prop_c3000_identity'.
952 prop_c1002_identity :: Cube -> Bool
953 prop_c1002_identity cube =
954 c t0 1 0 0 2 ~= c t0 0 1 0 2 + c t6 0 1 2 0
955 - ((c t0 0 0 0 3 + c t0 0 0 1 2)/ 2)
957 t0 = tetrahedron cube 0
958 t6 = tetrahedron cube 6
961 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
962 -- 'prop_c3000_identity'.
963 prop_c1011_identity :: Cube -> Bool
964 prop_c1011_identity cube =
965 c t0 1 0 1 1 ~= c t0 0 1 1 1 + c t6 0 1 1 1 -
966 ((c t0 0 0 1 2 + c t0 0 0 2 1)/ 2)
968 t0 = tetrahedron cube 0
969 t6 = tetrahedron cube 6
972 -- | The function values at the interior should be the same for all
974 prop_interior_values_all_identical :: Cube -> Bool
975 prop_interior_values_all_identical cube =
976 all_equal [ eval (function_values tet) I | tet <- tetrahedra cube ]
979 -- | We know what (c t6 2 1 0 0) should be from Sorokina and Zeilfelder, p. 87.
980 -- This test checks the rotation works as expected.
981 prop_c_tilde_2100_rotation_correct :: Cube -> Bool
982 prop_c_tilde_2100_rotation_correct cube =
985 t0 = tetrahedron cube 0
986 t6 = tetrahedron cube 6
988 -- What gets computed for c2100 of t6.
989 expr1 = eval (function_values t6) $
991 (1/12)*(T + R + L + D) +
992 (1/64)*(FT + FR + FL + FD) +
995 (1/96)*(RT + LD + LT + RD) +
996 (1/192)*(BT + BR + BL + BD)
998 -- What should be computed for c2100 of t6.
999 expr2 = eval (function_values t0) $
1001 (1/12)*(F + R + L + B) +
1002 (1/64)*(FT + RT + LT + BT) +
1005 (1/96)*(FR + FL + BR + BL) +
1006 (1/192)*(FD + RD + LD + BD)
1009 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
1010 -- Zeilfelder, p. 87. This test checks the actual value based on
1011 -- the FunctionValues of the cube.
1013 -- If 'prop_c_tilde_2100_rotation_correct' passes, then this test is
1015 prop_c_tilde_2100_correct :: Cube -> Bool
1016 prop_c_tilde_2100_correct cube =
1017 c t6 2 1 0 0 ~= expected
1019 t0 = tetrahedron cube 0
1020 t6 = tetrahedron cube 6
1021 fvs = function_values t0
1022 expected = eval fvs $
1024 (1/12)*(F + R + L + B) +
1025 (1/64)*(FT + RT + LT + BT) +
1028 (1/96)*(FR + FL + BR + BL) +
1029 (1/192)*(FD + RD + LD + BD)
1032 -- Tests to check that the correct edges are incidental.
1033 prop_t0_shares_edge_with_t1 :: Cube -> Bool
1034 prop_t0_shares_edge_with_t1 cube =
1035 (v1 t0) == (v1 t1) && (v3 t0) == (v2 t1)
1037 t0 = tetrahedron cube 0
1038 t1 = tetrahedron cube 1
1040 prop_t0_shares_edge_with_t3 :: Cube -> Bool
1041 prop_t0_shares_edge_with_t3 cube =
1042 (v1 t0) == (v1 t3) && (v2 t0) == (v3 t3)
1044 t0 = tetrahedron cube 0
1045 t3 = tetrahedron cube 3
1047 prop_t0_shares_edge_with_t6 :: Cube -> Bool
1048 prop_t0_shares_edge_with_t6 cube =
1049 (v2 t0) == (v3 t6) && (v3 t0) == (v2 t6)
1051 t0 = tetrahedron cube 0
1052 t6 = tetrahedron cube 6
1054 prop_t1_shares_edge_with_t2 :: Cube -> Bool
1055 prop_t1_shares_edge_with_t2 cube =
1056 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1058 t1 = tetrahedron cube 1
1059 t2 = tetrahedron cube 2
1061 prop_t1_shares_edge_with_t19 :: Cube -> Bool
1062 prop_t1_shares_edge_with_t19 cube =
1063 (v2 t1) == (v3 t19) && (v3 t1) == (v2 t19)
1065 t1 = tetrahedron cube 1
1066 t19 = tetrahedron cube 19
1068 prop_t2_shares_edge_with_t3 :: Cube -> Bool
1069 prop_t2_shares_edge_with_t3 cube =
1070 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1072 t1 = tetrahedron cube 1
1073 t2 = tetrahedron cube 2
1075 prop_t2_shares_edge_with_t12 :: Cube -> Bool
1076 prop_t2_shares_edge_with_t12 cube =
1077 (v2 t2) == (v3 t12) && (v3 t2) == (v2 t12)
1079 t2 = tetrahedron cube 2
1080 t12 = tetrahedron cube 12
1082 prop_t3_shares_edge_with_t21 :: Cube -> Bool
1083 prop_t3_shares_edge_with_t21 cube =
1084 (v2 t3) == (v3 t21) && (v3 t3) == (v2 t21)
1086 t3 = tetrahedron cube 3
1087 t21 = tetrahedron cube 21
1089 prop_t4_shares_edge_with_t5 :: Cube -> Bool
1090 prop_t4_shares_edge_with_t5 cube =
1091 (v1 t4) == (v1 t5) && (v3 t4) == (v2 t5)
1093 t4 = tetrahedron cube 4
1094 t5 = tetrahedron cube 5
1096 prop_t4_shares_edge_with_t7 :: Cube -> Bool
1097 prop_t4_shares_edge_with_t7 cube =
1098 (v1 t4) == (v1 t7) && (v2 t4) == (v3 t7)
1100 t4 = tetrahedron cube 4
1101 t7 = tetrahedron cube 7
1103 prop_t4_shares_edge_with_t10 :: Cube -> Bool
1104 prop_t4_shares_edge_with_t10 cube =
1105 (v2 t4) == (v3 t10) && (v3 t4) == (v2 t10)
1107 t4 = tetrahedron cube 4
1108 t10 = tetrahedron cube 10
1110 prop_t5_shares_edge_with_t6 :: Cube -> Bool
1111 prop_t5_shares_edge_with_t6 cube =
1112 (v1 t5) == (v1 t6) && (v3 t5) == (v2 t6)
1114 t5 = tetrahedron cube 5
1115 t6 = tetrahedron cube 6
1117 prop_t5_shares_edge_with_t16 :: Cube -> Bool
1118 prop_t5_shares_edge_with_t16 cube =
1119 (v2 t5) == (v3 t16) && (v3 t5) == (v2 t16)
1121 t5 = tetrahedron cube 5
1122 t16 = tetrahedron cube 16
1124 prop_t6_shares_edge_with_t7 :: Cube -> Bool
1125 prop_t6_shares_edge_with_t7 cube =
1126 (v1 t6) == (v1 t7) && (v3 t6) == (v2 t7)
1128 t6 = tetrahedron cube 6
1129 t7 = tetrahedron cube 7
1131 prop_t7_shares_edge_with_t20 :: Cube -> Bool
1132 prop_t7_shares_edge_with_t20 cube =
1133 (v2 t7) == (v3 t20) && (v2 t7) == (v3 t20)
1135 t7 = tetrahedron cube 7
1136 t20 = tetrahedron cube 20
1139 p79_26_properties :: TestTree
1141 testGroup "p. 79, Section (2.6) properties" [
1142 testProperty "c0120 identity1" prop_c0120_identity1,
1143 testProperty "c0120 identity2" prop_c0120_identity2,
1144 testProperty "c0120 identity3" prop_c0120_identity3,
1145 testProperty "c0120 identity4" prop_c0120_identity4,
1146 testProperty "c0120 identity5" prop_c0120_identity5,
1147 testProperty "c0120 identity6" prop_c0120_identity6,
1148 testProperty "c0120 identity7" prop_c0120_identity7,
1149 testProperty "c0210 identity1" prop_c0210_identity1,
1150 testProperty "c0300 identity1" prop_c0300_identity1,
1151 testProperty "c1110 identity" prop_c1110_identity,
1152 testProperty "c1200 identity1" prop_c1200_identity1,
1153 testProperty "c2100 identity1" prop_c2100_identity1]
1155 p79_27_properties :: TestTree
1157 testGroup "p. 79, Section (2.7) properties" [
1158 testProperty "c0102 identity1" prop_c0102_identity1,
1159 testProperty "c0201 identity1" prop_c0201_identity1,
1160 testProperty "c0300 identity2" prop_c0300_identity2,
1161 testProperty "c1101 identity" prop_c1101_identity,
1162 testProperty "c1200 identity2" prop_c1200_identity2,
1163 testProperty "c2100 identity2" prop_c2100_identity2 ]
1166 p79_28_properties :: TestTree
1168 testGroup "p. 79, Section (2.8) properties" [
1169 testProperty "c3000 identity" prop_c3000_identity,
1170 testProperty "c2010 identity" prop_c2010_identity,
1171 testProperty "c2001 identity" prop_c2001_identity,
1172 testProperty "c1020 identity" prop_c1020_identity,
1173 testProperty "c1002 identity" prop_c1002_identity,
1174 testProperty "c1011 identity" prop_c1011_identity ]
1177 edge_incidence_tests :: TestTree
1178 edge_incidence_tests =
1179 testGroup "Edge incidence tests" [
1180 testProperty "t0 shares edge with t6" prop_t0_shares_edge_with_t6,
1181 testProperty "t0 shares edge with t1" prop_t0_shares_edge_with_t1,
1182 testProperty "t0 shares edge with t3" prop_t0_shares_edge_with_t3,
1183 testProperty "t1 shares edge with t2" prop_t1_shares_edge_with_t2,
1184 testProperty "t1 shares edge with t19" prop_t1_shares_edge_with_t19,
1185 testProperty "t2 shares edge with t3" prop_t2_shares_edge_with_t3,
1186 testProperty "t2 shares edge with t12" prop_t2_shares_edge_with_t12,
1187 testProperty "t3 shares edge with t21" prop_t3_shares_edge_with_t21,
1188 testProperty "t4 shares edge with t5" prop_t4_shares_edge_with_t5,
1189 testProperty "t4 shares edge with t7" prop_t4_shares_edge_with_t7,
1190 testProperty "t4 shares edge with t10" prop_t4_shares_edge_with_t10,
1191 testProperty "t5 shares edge with t6" prop_t5_shares_edge_with_t6,
1192 testProperty "t5 shares edge with t16" prop_t5_shares_edge_with_t16,
1193 testProperty "t6 shares edge with t7" prop_t6_shares_edge_with_t7,
1194 testProperty "t7 shares edge with t20" prop_t7_shares_edge_with_t20 ]
1196 cube_properties :: TestTree
1198 testGroup "Cube properties" [
1202 edge_incidence_tests,
1203 testProperty "opposite octant tetrahedra are disjoint (1)"
1204 prop_opposite_octant_tetrahedra_disjoint1,
1205 testProperty "opposite octant tetrahedra are disjoint (2)"
1206 prop_opposite_octant_tetrahedra_disjoint2,
1207 testProperty "opposite octant tetrahedra are disjoint (3)"
1208 prop_opposite_octant_tetrahedra_disjoint3,
1209 testProperty "opposite octant tetrahedra are disjoint (4)"
1210 prop_opposite_octant_tetrahedra_disjoint4,
1211 testProperty "opposite octant tetrahedra are disjoint (5)"
1212 prop_opposite_octant_tetrahedra_disjoint5,
1213 testProperty "opposite octant tetrahedra are disjoint (6)"
1214 prop_opposite_octant_tetrahedra_disjoint6,
1215 testProperty "all volumes positive" prop_all_volumes_positive,
1216 testProperty "all volumes exact" prop_all_volumes_exact,
1217 testProperty "v0 all equal" prop_v0_all_equal,
1218 testProperty "interior values all identical"
1219 prop_interior_values_all_identical,
1220 testProperty "c-tilde_2100 rotation correct"
1221 prop_c_tilde_2100_rotation_correct,
1222 testProperty "c-tilde_2100 correct"
1223 prop_c_tilde_2100_correct ]