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 (
21 Arbitrary( arbitrary ),
27 Cardinal(F, B, L, R, D, T, FL, FR, FD, FT,
28 BL, BR, BD, BT, LD, LT, RD, RT, I),
35 import Comparisons ( (~=), (~~=) )
36 import qualified Face ( Face(..), center )
37 import FunctionValues ( FunctionValues, eval, rotate )
38 import Misc ( all_equal, disjoint )
39 import Point ( Point( Point ), dot )
41 Tetrahedron(Tetrahedron, function_values, v0, v1, v2, v3),
46 data Cube = Cube { i :: !Int,
49 fv :: !FunctionValues,
50 tetrahedra_volume :: !Double }
54 instance Arbitrary Cube where
56 i' <- choose (coordmin, coordmax)
57 j' <- choose (coordmin, coordmax)
58 k' <- choose (coordmin, coordmax)
59 fv' <- arbitrary :: Gen FunctionValues
60 (Positive tet_vol) <- arbitrary :: Gen (Positive Double)
61 return (Cube i' j' k' fv' tet_vol)
63 -- The idea here is that, when cubed in the volume formula,
64 -- these numbers don't overflow 64 bits. This number is not
65 -- magic in any other sense than that it does not cause test
66 -- failures, while 2^23 does.
67 coordmax = 4194304 :: Int -- 2^22
71 instance Show Cube where
73 "Cube_" ++ subscript ++ "\n" ++
74 " Center: " ++ (show (center cube)) ++ "\n" ++
75 " xmin: " ++ (show (xmin cube)) ++ "\n" ++
76 " xmax: " ++ (show (xmax cube)) ++ "\n" ++
77 " ymin: " ++ (show (ymin cube)) ++ "\n" ++
78 " ymax: " ++ (show (ymax cube)) ++ "\n" ++
79 " zmin: " ++ (show (zmin cube)) ++ "\n" ++
80 " zmax: " ++ (show (zmax cube)) ++ "\n"
83 (show (i cube)) ++ "," ++ (show (j cube)) ++ "," ++ (show (k cube))
86 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
88 xmin :: Cube -> Double
89 xmin cube = (i' - 1/2)
91 i' = fromIntegral (i cube) :: Double
93 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
95 xmax :: Cube -> Double
96 xmax cube = (i' + 1/2)
98 i' = fromIntegral (i cube) :: Double
100 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
102 ymin :: Cube -> Double
103 ymin cube = (j' - 1/2)
105 j' = fromIntegral (j cube) :: Double
107 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
109 ymax :: Cube -> Double
110 ymax cube = (j' + 1/2)
112 j' = fromIntegral (j cube) :: Double
114 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
116 zmin :: Cube -> Double
117 zmin cube = (k' - 1/2)
119 k' = fromIntegral (k cube) :: Double
121 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
123 zmax :: Cube -> Double
124 zmax cube = (k' + 1/2)
126 k' = fromIntegral (k cube) :: Double
129 -- | The center of Cube_ijk coincides with v_ijk at
130 -- (i, j, k). See Sorokina and Zeilfelder, p. 76.
131 center :: Cube -> Point
135 x = fromIntegral (i cube) :: Double
136 y = fromIntegral (j cube) :: Double
137 z = fromIntegral (k cube) :: Double
142 -- | The top (in the direction of z) face of the cube.
143 top_face :: Cube -> Face.Face
144 top_face cube = Face.Face v0' v1' v2' v3'
146 delta = (1/2) :: Double
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 )
155 -- | The back (in the direction of x) face of the cube.
156 back_face :: Cube -> Face.Face
157 back_face cube = Face.Face v0' v1' v2' v3'
159 delta = (1/2) :: Double
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 )
167 -- The bottom face (in the direction of -z) of the cube.
168 down_face :: Cube -> Face.Face
169 down_face cube = Face.Face v0' v1' v2' v3'
171 delta = (1/2) :: Double
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) )
180 -- | The front (in the direction of -x) face of the cube.
181 front_face :: Cube -> Face.Face
182 front_face cube = Face.Face v0' v1' v2' v3'
184 delta = (1/2) :: Double
186 v0' = cc + ( Point (-delta) (-delta) delta )
187 v1' = cc + ( Point (-delta) delta delta )
188 v2' = cc + ( Point (-delta) delta (-delta) )
189 v3' = cc + ( Point (-delta) (-delta) (-delta) )
191 -- | The left (in the direction of -y) face of the cube.
192 left_face :: Cube -> Face.Face
193 left_face cube = Face.Face v0' v1' v2' v3'
195 delta = (1/2) :: Double
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 -- | The right (in the direction of y) face of the cube.
204 right_face :: Cube -> Face.Face
205 right_face cube = Face.Face v0' v1' v2' v3'
207 delta = (1/2) :: Double
209 v0' = cc + ( Point (-delta) delta delta)
210 v1' = cc + ( Point delta delta delta )
211 v2' = cc + ( Point delta delta (-delta) )
212 v3' = cc + ( Point (-delta) delta (-delta) )
215 tetrahedron :: Cube -> Int -> Tetrahedron
218 Tetrahedron (fv cube) v0' v1' v2' v3' vol
225 vol = tetrahedra_volume cube
228 Tetrahedron fv' v0' v1' v2' v3' vol
235 fv' = rotate ccwx (fv cube)
236 vol = tetrahedra_volume cube
239 Tetrahedron fv' v0' v1' v2' v3' vol
246 fv' = rotate ccwx $ rotate ccwx $ fv cube
247 vol = tetrahedra_volume cube
250 Tetrahedron fv' v0' v1' v2' v3' vol
257 fv' = rotate cwx (fv cube)
258 vol = tetrahedra_volume cube
261 Tetrahedron fv' v0' v1' v2' v3' vol
268 fv' = rotate cwy (fv cube)
269 vol = tetrahedra_volume cube
272 Tetrahedron fv' v0' v1' v2' v3' vol
279 fv' = rotate cwy $ rotate cwz $ fv cube
280 vol = tetrahedra_volume cube
283 Tetrahedron fv' v0' v1' v2' v3' vol
290 fv' = rotate cwy $ rotate cwz
293 vol = tetrahedra_volume cube
296 Tetrahedron fv' v0' v1' v2' v3' vol
303 fv' = rotate cwy $ rotate ccwz $ fv cube
304 vol = tetrahedra_volume cube
307 Tetrahedron fv' v0' v1' v2' v3' vol
314 fv' = rotate cwy $ rotate cwy $ fv cube
315 vol = tetrahedra_volume cube
318 Tetrahedron fv' v0' v1' v2' v3' vol
325 fv' = rotate cwy $ rotate cwy
328 vol = tetrahedra_volume cube
330 tetrahedron cube 10 =
331 Tetrahedron fv' v0' v1' v2' v3' vol
338 fv' = rotate cwy $ rotate cwy
343 vol = tetrahedra_volume cube
345 tetrahedron cube 11 =
346 Tetrahedron fv' v0' v1' v2' v3' vol
353 fv' = rotate cwy $ rotate cwy
356 vol = tetrahedra_volume cube
358 tetrahedron cube 12 =
359 Tetrahedron fv' v0' v1' v2' v3' vol
366 fv' = rotate ccwy $ fv cube
367 vol = tetrahedra_volume cube
369 tetrahedron cube 13 =
370 Tetrahedron fv' v0' v1' v2' v3' vol
377 fv' = rotate ccwy $ rotate ccwz $ fv cube
378 vol = tetrahedra_volume cube
380 tetrahedron cube 14 =
381 Tetrahedron fv' v0' v1' v2' v3' vol
388 fv' = rotate ccwy $ rotate ccwz
391 vol = tetrahedra_volume cube
393 tetrahedron cube 15 =
394 Tetrahedron fv' v0' v1' v2' v3' vol
401 fv' = rotate ccwy $ rotate cwz $ fv cube
402 vol = tetrahedra_volume cube
404 tetrahedron cube 16 =
405 Tetrahedron fv' v0' v1' v2' v3' vol
412 fv' = rotate ccwz $ fv cube
413 vol = tetrahedra_volume cube
415 tetrahedron cube 17 =
416 Tetrahedron fv' v0' v1' v2' v3' vol
423 fv' = rotate ccwz $ rotate cwy $ fv cube
424 vol = tetrahedra_volume cube
426 tetrahedron cube 18 =
427 Tetrahedron fv' v0' v1' v2' v3' vol
434 fv' = rotate ccwz $ rotate cwy
437 vol = tetrahedra_volume cube
439 tetrahedron cube 19 =
440 Tetrahedron fv' v0' v1' v2' v3' vol
447 fv' = rotate ccwz $ rotate ccwy
449 vol = tetrahedra_volume cube
451 tetrahedron cube 20 =
452 Tetrahedron fv' v0' v1' v2' v3' vol
459 fv' = rotate cwz $ fv cube
460 vol = tetrahedra_volume cube
462 tetrahedron cube 21 =
463 Tetrahedron fv' v0' v1' v2' v3' vol
470 fv' = rotate cwz $ rotate ccwy $ fv cube
471 vol = tetrahedra_volume cube
473 tetrahedron cube 22 =
474 Tetrahedron fv' v0' v1' v2' v3' vol
481 fv' = rotate cwz $ rotate ccwy
484 vol = tetrahedra_volume cube
486 tetrahedron cube 23 =
487 Tetrahedron fv' v0' v1' v2' v3' vol
494 fv' = rotate cwz $ rotate cwy
496 vol = tetrahedra_volume cube
499 -- Only used in tests, so we don't need the added speed
501 tetrahedra :: Cube -> [Tetrahedron]
502 tetrahedra cube = [ tetrahedron cube n | n <- [0..23] ]
504 front_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
505 front_left_top_tetrahedra cube =
506 V.singleton (tetrahedron cube 0) `V.snoc`
507 (tetrahedron cube 3) `V.snoc`
508 (tetrahedron cube 6) `V.snoc`
509 (tetrahedron cube 7) `V.snoc`
510 (tetrahedron cube 20) `V.snoc`
511 (tetrahedron cube 21)
513 front_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
514 front_left_down_tetrahedra cube =
515 V.singleton (tetrahedron cube 0) `V.snoc`
516 (tetrahedron cube 2) `V.snoc`
517 (tetrahedron cube 3) `V.snoc`
518 (tetrahedron cube 12) `V.snoc`
519 (tetrahedron cube 15) `V.snoc`
520 (tetrahedron cube 21)
522 front_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
523 front_right_top_tetrahedra cube =
524 V.singleton (tetrahedron cube 0) `V.snoc`
525 (tetrahedron cube 1) `V.snoc`
526 (tetrahedron cube 5) `V.snoc`
527 (tetrahedron cube 6) `V.snoc`
528 (tetrahedron cube 16) `V.snoc`
529 (tetrahedron cube 19)
531 front_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
532 front_right_down_tetrahedra cube =
533 V.singleton (tetrahedron cube 1) `V.snoc`
534 (tetrahedron cube 2) `V.snoc`
535 (tetrahedron cube 12) `V.snoc`
536 (tetrahedron cube 13) `V.snoc`
537 (tetrahedron cube 18) `V.snoc`
538 (tetrahedron cube 19)
540 back_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
541 back_left_top_tetrahedra cube =
542 V.singleton (tetrahedron cube 0) `V.snoc`
543 (tetrahedron cube 3) `V.snoc`
544 (tetrahedron cube 6) `V.snoc`
545 (tetrahedron cube 7) `V.snoc`
546 (tetrahedron cube 20) `V.snoc`
547 (tetrahedron cube 21)
549 back_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
550 back_left_down_tetrahedra cube =
551 V.singleton (tetrahedron cube 8) `V.snoc`
552 (tetrahedron cube 11) `V.snoc`
553 (tetrahedron cube 14) `V.snoc`
554 (tetrahedron cube 15) `V.snoc`
555 (tetrahedron cube 22) `V.snoc`
556 (tetrahedron cube 23)
558 back_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
559 back_right_top_tetrahedra cube =
560 V.singleton (tetrahedron cube 4) `V.snoc`
561 (tetrahedron cube 5) `V.snoc`
562 (tetrahedron cube 9) `V.snoc`
563 (tetrahedron cube 10) `V.snoc`
564 (tetrahedron cube 16) `V.snoc`
565 (tetrahedron cube 17)
567 back_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
568 back_right_down_tetrahedra cube =
569 V.singleton (tetrahedron cube 8) `V.snoc`
570 (tetrahedron cube 9) `V.snoc`
571 (tetrahedron cube 13) `V.snoc`
572 (tetrahedron cube 14) `V.snoc`
573 (tetrahedron cube 17) `V.snoc`
574 (tetrahedron cube 18)
576 in_top_half :: Cube -> Point -> Bool
577 in_top_half cube (Point _ _ z) =
578 distance_from_top <= distance_from_bottom
580 distance_from_top = abs $ (zmax cube) - z
581 distance_from_bottom = abs $ (zmin cube) - z
583 in_front_half :: Cube -> Point -> Bool
584 in_front_half cube (Point x _ _) =
585 distance_from_front <= distance_from_back
587 distance_from_front = abs $ (xmin cube) - x
588 distance_from_back = abs $ (xmax cube) - x
591 in_left_half :: Cube -> Point -> Bool
592 in_left_half cube (Point _ y _) =
593 distance_from_left <= distance_from_right
595 distance_from_left = abs $ (ymin cube) - y
596 distance_from_right = abs $ (ymax cube) - y
599 -- | Takes a 'Cube', and returns the Tetrahedra belonging to it that
600 -- contain the given 'Point'. This should be faster than checking
601 -- every tetrahedron individually, since we determine which half
602 -- (hemisphere?) of the cube the point lies in three times: once in
603 -- each dimension. This allows us to eliminate non-candidates
606 -- This can throw an exception, but the use of 'head' might
607 -- save us some unnecessary computations.
609 {-# INLINE find_containing_tetrahedron #-}
610 find_containing_tetrahedron :: Cube -> Point -> Tetrahedron
611 find_containing_tetrahedron cube p =
612 candidates `V.unsafeIndex` (fromJust lucky_idx)
614 front_half = in_front_half cube p
615 top_half = in_top_half cube p
616 left_half = in_left_half cube p
618 candidates :: V.Vector Tetrahedron
623 front_left_top_tetrahedra cube
625 front_left_down_tetrahedra cube
628 front_right_top_tetrahedra cube
630 front_right_down_tetrahedra cube
632 | otherwise = -- back half
635 back_left_top_tetrahedra cube
637 back_left_down_tetrahedra cube
640 back_right_top_tetrahedra cube
642 back_right_down_tetrahedra cube
644 -- Use the dot product instead of Euclidean distance here to save
645 -- a sqrt(). So, "distances" below really means "distances
647 distances :: V.Vector Double
648 distances = V.map ((dot p) . barycenter) candidates
650 shortest_distance :: Double
651 shortest_distance = V.minimum distances
653 -- Compute the index of the tetrahedron with the center closest to
654 -- p. This is a bad algorithm, but don't change it! If you make it
655 -- smarter by finding the index of shortest_distance in distances
656 -- (this should give the same answer and avoids recomputing the
657 -- dot product), the program gets slower. Seriously!
658 lucky_idx :: Maybe Int
659 lucky_idx = V.findIndex
660 (\t -> (barycenter t) `dot` p == shortest_distance)
670 prop_opposite_octant_tetrahedra_disjoint1 :: Cube -> Bool
671 prop_opposite_octant_tetrahedra_disjoint1 cube =
672 disjoint (front_left_top_tetrahedra cube) (front_right_down_tetrahedra cube)
674 prop_opposite_octant_tetrahedra_disjoint2 :: Cube -> Bool
675 prop_opposite_octant_tetrahedra_disjoint2 cube =
676 disjoint (back_left_top_tetrahedra cube) (back_right_down_tetrahedra cube)
678 prop_opposite_octant_tetrahedra_disjoint3 :: Cube -> Bool
679 prop_opposite_octant_tetrahedra_disjoint3 cube =
680 disjoint (front_left_top_tetrahedra cube) (back_right_top_tetrahedra cube)
682 prop_opposite_octant_tetrahedra_disjoint4 :: Cube -> Bool
683 prop_opposite_octant_tetrahedra_disjoint4 cube =
684 disjoint (front_left_down_tetrahedra cube) (back_right_down_tetrahedra cube)
686 prop_opposite_octant_tetrahedra_disjoint5 :: Cube -> Bool
687 prop_opposite_octant_tetrahedra_disjoint5 cube =
688 disjoint (front_left_top_tetrahedra cube) (back_left_down_tetrahedra cube)
690 prop_opposite_octant_tetrahedra_disjoint6 :: Cube -> Bool
691 prop_opposite_octant_tetrahedra_disjoint6 cube =
692 disjoint (front_right_top_tetrahedra cube) (back_right_down_tetrahedra cube)
695 -- | Since the grid size is necessarily positive, all tetrahedra
696 -- (which comprise cubes of positive volume) must have positive
698 prop_all_volumes_positive :: Cube -> Bool
699 prop_all_volumes_positive cube =
703 volumes = map volume ts
706 -- | In fact, since all of the tetrahedra are identical, we should
707 -- already know their volumes. There's 24 tetrahedra to a cube, so
708 -- we'd expect the volume of each one to be 1/24.
709 prop_all_volumes_exact :: Cube -> Bool
710 prop_all_volumes_exact cube =
711 and [volume t ~~= 1/24 | t <- tetrahedra cube]
713 -- | All tetrahedron should have their v0 located at the center of the
715 prop_v0_all_equal :: Cube -> Bool
716 prop_v0_all_equal cube = (v0 t0) == (v0 t1)
718 t0 = head (tetrahedra cube) -- Doesn't matter which two we choose.
719 t1 = head $ tail (tetrahedra cube)
722 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Note that the
723 -- third and fourth indices of c-t3 have been switched. This is
724 -- because we store the triangles oriented such that their volume is
725 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
726 -- in opposite directions, one of them has to have negative volume!
727 prop_c0120_identity1 :: Cube -> Bool
728 prop_c0120_identity1 cube =
729 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
731 t0 = tetrahedron cube 0
732 t3 = tetrahedron cube 3
735 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
736 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
737 prop_c0120_identity2 :: Cube -> Bool
738 prop_c0120_identity2 cube =
739 c t1 0 1 2 0 ~= (c t1 0 0 2 1 + c t0 0 0 1 2) / 2
741 t0 = tetrahedron cube 0
742 t1 = tetrahedron cube 1
744 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
745 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
746 prop_c0120_identity3 :: Cube -> Bool
747 prop_c0120_identity3 cube =
748 c t2 0 1 2 0 ~= (c t2 0 0 2 1 + c t1 0 0 1 2) / 2
750 t1 = tetrahedron cube 1
751 t2 = tetrahedron cube 2
753 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
754 -- 'prop_c0120_identity1' with tetrahedrons 2 and 3.
755 prop_c0120_identity4 :: Cube -> Bool
756 prop_c0120_identity4 cube =
757 c t3 0 1 2 0 ~= (c t3 0 0 2 1 + c t2 0 0 1 2) / 2
759 t2 = tetrahedron cube 2
760 t3 = tetrahedron cube 3
763 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
764 -- 'prop_c0120_identity1' with tetrahedrons 4 and 5.
765 prop_c0120_identity5 :: Cube -> Bool
766 prop_c0120_identity5 cube =
767 c t5 0 1 2 0 ~= (c t5 0 0 2 1 + c t4 0 0 1 2) / 2
769 t4 = tetrahedron cube 4
770 t5 = tetrahedron cube 5
772 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
773 -- 'prop_c0120_identity1' with tetrahedrons 5 and 6.
774 prop_c0120_identity6 :: Cube -> Bool
775 prop_c0120_identity6 cube =
776 c t6 0 1 2 0 ~= (c t6 0 0 2 1 + c t5 0 0 1 2) / 2
778 t5 = tetrahedron cube 5
779 t6 = tetrahedron cube 6
782 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
783 -- 'prop_c0120_identity1' with tetrahedrons 6 and 7.
784 prop_c0120_identity7 :: Cube -> Bool
785 prop_c0120_identity7 cube =
786 c t7 0 1 2 0 ~= (c t7 0 0 2 1 + c t6 0 0 1 2) / 2
788 t6 = tetrahedron cube 6
789 t7 = tetrahedron cube 7
792 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
793 -- 'prop_c0120_identity1'.
794 prop_c0210_identity1 :: Cube -> Bool
795 prop_c0210_identity1 cube =
796 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
798 t0 = tetrahedron cube 0
799 t3 = tetrahedron cube 3
802 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
803 -- 'prop_c0120_identity1'.
804 prop_c0300_identity1 :: Cube -> Bool
805 prop_c0300_identity1 cube =
806 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
808 t0 = tetrahedron cube 0
809 t3 = tetrahedron cube 3
812 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
813 -- 'prop_c0120_identity1'.
814 prop_c1110_identity :: Cube -> Bool
815 prop_c1110_identity cube =
816 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
818 t0 = tetrahedron cube 0
819 t3 = tetrahedron cube 3
822 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
823 -- 'prop_c0120_identity1'.
824 prop_c1200_identity1 :: Cube -> Bool
825 prop_c1200_identity1 cube =
826 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
828 t0 = tetrahedron cube 0
829 t3 = tetrahedron cube 3
832 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
833 -- 'prop_c0120_identity1'.
834 prop_c2100_identity1 :: Cube -> Bool
835 prop_c2100_identity1 cube =
836 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
838 t0 = tetrahedron cube 0
839 t3 = tetrahedron cube 3
843 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). Note that the
844 -- third and fourth indices of c-t3 have been switched. This is
845 -- because we store the triangles oriented such that their volume is
846 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
847 -- point in opposite directions, one of them has to have negative
849 prop_c0102_identity1 :: Cube -> Bool
850 prop_c0102_identity1 cube =
851 c t0 0 1 0 2 ~= (c t0 0 0 1 2 + c t1 0 0 2 1) / 2
853 t0 = tetrahedron cube 0
854 t1 = tetrahedron cube 1
857 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
858 -- 'prop_c0102_identity1'.
859 prop_c0201_identity1 :: Cube -> Bool
860 prop_c0201_identity1 cube =
861 c t0 0 2 0 1 ~= (c t0 0 1 1 1 + c t1 0 1 1 1) / 2
863 t0 = tetrahedron cube 0
864 t1 = tetrahedron cube 1
867 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
868 -- 'prop_c0102_identity1'.
869 prop_c0300_identity2 :: Cube -> Bool
870 prop_c0300_identity2 cube =
871 c t0 0 3 0 0 ~= (c t0 0 2 1 0 + c t1 0 2 0 1) / 2
873 t0 = tetrahedron cube 0
874 t1 = tetrahedron cube 1
877 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
878 -- 'prop_c0102_identity1'.
879 prop_c1101_identity :: Cube -> Bool
880 prop_c1101_identity cube =
881 c t0 1 1 0 1 ~= (c t0 1 0 1 1 + c t1 1 0 1 1) / 2
883 t0 = tetrahedron cube 0
884 t1 = tetrahedron cube 1
887 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
888 -- 'prop_c0102_identity1'.
889 prop_c1200_identity2 :: Cube -> Bool
890 prop_c1200_identity2 cube =
891 c t0 1 2 0 0 ~= (c t0 1 1 1 0 + c t1 1 1 0 1) / 2
893 t0 = tetrahedron cube 0
894 t1 = tetrahedron cube 1
897 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
898 -- 'prop_c0102_identity1'.
899 prop_c2100_identity2 :: Cube -> Bool
900 prop_c2100_identity2 cube =
901 c t0 2 1 0 0 ~= (c t0 2 0 1 0 + c t1 2 0 0 1) / 2
903 t0 = tetrahedron cube 0
904 t1 = tetrahedron cube 1
907 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). The third and
908 -- fourth indices of c-t6 have been switched. This is because we
909 -- store the triangles oriented such that their volume is
910 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
911 -- point in opposite directions, one of them has to have negative
913 prop_c3000_identity :: Cube -> Bool
914 prop_c3000_identity cube =
915 c t0 3 0 0 0 ~= c t0 2 1 0 0 + c t6 2 1 0 0
916 - ((c t0 2 0 1 0 + c t0 2 0 0 1)/ 2)
918 t0 = tetrahedron cube 0
919 t6 = tetrahedron cube 6
922 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
923 -- 'prop_c3000_identity'.
924 prop_c2010_identity :: Cube -> Bool
925 prop_c2010_identity cube =
926 c t0 2 0 1 0 ~= c t0 1 1 1 0 + c t6 1 1 0 1
927 - ((c t0 1 0 2 0 + c t0 1 0 1 1)/ 2)
929 t0 = tetrahedron cube 0
930 t6 = tetrahedron cube 6
933 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
934 -- 'prop_c3000_identity'.
935 prop_c2001_identity :: Cube -> Bool
936 prop_c2001_identity cube =
937 c t0 2 0 0 1 ~= c t0 1 1 0 1 + c t6 1 1 1 0
938 - ((c t0 1 0 0 2 + c t0 1 0 1 1)/ 2)
940 t0 = tetrahedron cube 0
941 t6 = tetrahedron cube 6
944 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
945 -- 'prop_c3000_identity'.
946 prop_c1020_identity :: Cube -> Bool
947 prop_c1020_identity cube =
948 c t0 1 0 2 0 ~= c t0 0 1 2 0 + c t6 0 1 0 2
949 - ((c t0 0 0 3 0 + c t0 0 0 2 1)/ 2)
951 t0 = tetrahedron cube 0
952 t6 = tetrahedron cube 6
955 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
956 -- 'prop_c3000_identity'.
957 prop_c1002_identity :: Cube -> Bool
958 prop_c1002_identity cube =
959 c t0 1 0 0 2 ~= c t0 0 1 0 2 + c t6 0 1 2 0
960 - ((c t0 0 0 0 3 + c t0 0 0 1 2)/ 2)
962 t0 = tetrahedron cube 0
963 t6 = tetrahedron cube 6
966 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
967 -- 'prop_c3000_identity'.
968 prop_c1011_identity :: Cube -> Bool
969 prop_c1011_identity cube =
970 c t0 1 0 1 1 ~= c t0 0 1 1 1 + c t6 0 1 1 1 -
971 ((c t0 0 0 1 2 + c t0 0 0 2 1)/ 2)
973 t0 = tetrahedron cube 0
974 t6 = tetrahedron cube 6
977 -- | The function values at the interior should be the same for all
979 prop_interior_values_all_identical :: Cube -> Bool
980 prop_interior_values_all_identical cube =
981 all_equal [ eval (function_values tet) I | tet <- tetrahedra cube ]
984 -- | We know what (c t6 2 1 0 0) should be from Sorokina and Zeilfelder, p. 87.
985 -- This test checks the rotation works as expected.
986 prop_c_tilde_2100_rotation_correct :: Cube -> Bool
987 prop_c_tilde_2100_rotation_correct cube =
990 t0 = tetrahedron cube 0
991 t6 = tetrahedron cube 6
993 -- What gets computed for c2100 of t6.
994 expr1 = eval (function_values t6) $
996 (1/12)*(T + R + L + D) +
997 (1/64)*(FT + FR + FL + FD) +
1000 (1/96)*(RT + LD + LT + RD) +
1001 (1/192)*(BT + BR + BL + BD)
1003 -- What should be computed for c2100 of t6.
1004 expr2 = eval (function_values t0) $
1006 (1/12)*(F + R + L + B) +
1007 (1/64)*(FT + RT + LT + BT) +
1010 (1/96)*(FR + FL + BR + BL) +
1011 (1/192)*(FD + RD + LD + BD)
1014 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
1015 -- Zeilfelder, p. 87. This test checks the actual value based on
1016 -- the FunctionValues of the cube.
1018 -- If 'prop_c_tilde_2100_rotation_correct' passes, then this test is
1020 prop_c_tilde_2100_correct :: Cube -> Bool
1021 prop_c_tilde_2100_correct cube =
1022 c t6 2 1 0 0 ~= expected
1024 t0 = tetrahedron cube 0
1025 t6 = tetrahedron cube 6
1026 fvs = function_values t0
1027 expected = eval fvs $
1029 (1/12)*(F + R + L + B) +
1030 (1/64)*(FT + RT + LT + BT) +
1033 (1/96)*(FR + FL + BR + BL) +
1034 (1/192)*(FD + RD + LD + BD)
1037 -- Tests to check that the correct edges are incidental.
1038 prop_t0_shares_edge_with_t1 :: Cube -> Bool
1039 prop_t0_shares_edge_with_t1 cube =
1040 (v1 t0) == (v1 t1) && (v3 t0) == (v2 t1)
1042 t0 = tetrahedron cube 0
1043 t1 = tetrahedron cube 1
1045 prop_t0_shares_edge_with_t3 :: Cube -> Bool
1046 prop_t0_shares_edge_with_t3 cube =
1047 (v1 t0) == (v1 t3) && (v2 t0) == (v3 t3)
1049 t0 = tetrahedron cube 0
1050 t3 = tetrahedron cube 3
1052 prop_t0_shares_edge_with_t6 :: Cube -> Bool
1053 prop_t0_shares_edge_with_t6 cube =
1054 (v2 t0) == (v3 t6) && (v3 t0) == (v2 t6)
1056 t0 = tetrahedron cube 0
1057 t6 = tetrahedron cube 6
1059 prop_t1_shares_edge_with_t2 :: Cube -> Bool
1060 prop_t1_shares_edge_with_t2 cube =
1061 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1063 t1 = tetrahedron cube 1
1064 t2 = tetrahedron cube 2
1066 prop_t1_shares_edge_with_t19 :: Cube -> Bool
1067 prop_t1_shares_edge_with_t19 cube =
1068 (v2 t1) == (v3 t19) && (v3 t1) == (v2 t19)
1070 t1 = tetrahedron cube 1
1071 t19 = tetrahedron cube 19
1073 prop_t2_shares_edge_with_t3 :: Cube -> Bool
1074 prop_t2_shares_edge_with_t3 cube =
1075 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1077 t1 = tetrahedron cube 1
1078 t2 = tetrahedron cube 2
1080 prop_t2_shares_edge_with_t12 :: Cube -> Bool
1081 prop_t2_shares_edge_with_t12 cube =
1082 (v2 t2) == (v3 t12) && (v3 t2) == (v2 t12)
1084 t2 = tetrahedron cube 2
1085 t12 = tetrahedron cube 12
1087 prop_t3_shares_edge_with_t21 :: Cube -> Bool
1088 prop_t3_shares_edge_with_t21 cube =
1089 (v2 t3) == (v3 t21) && (v3 t3) == (v2 t21)
1091 t3 = tetrahedron cube 3
1092 t21 = tetrahedron cube 21
1094 prop_t4_shares_edge_with_t5 :: Cube -> Bool
1095 prop_t4_shares_edge_with_t5 cube =
1096 (v1 t4) == (v1 t5) && (v3 t4) == (v2 t5)
1098 t4 = tetrahedron cube 4
1099 t5 = tetrahedron cube 5
1101 prop_t4_shares_edge_with_t7 :: Cube -> Bool
1102 prop_t4_shares_edge_with_t7 cube =
1103 (v1 t4) == (v1 t7) && (v2 t4) == (v3 t7)
1105 t4 = tetrahedron cube 4
1106 t7 = tetrahedron cube 7
1108 prop_t4_shares_edge_with_t10 :: Cube -> Bool
1109 prop_t4_shares_edge_with_t10 cube =
1110 (v2 t4) == (v3 t10) && (v3 t4) == (v2 t10)
1112 t4 = tetrahedron cube 4
1113 t10 = tetrahedron cube 10
1115 prop_t5_shares_edge_with_t6 :: Cube -> Bool
1116 prop_t5_shares_edge_with_t6 cube =
1117 (v1 t5) == (v1 t6) && (v3 t5) == (v2 t6)
1119 t5 = tetrahedron cube 5
1120 t6 = tetrahedron cube 6
1122 prop_t5_shares_edge_with_t16 :: Cube -> Bool
1123 prop_t5_shares_edge_with_t16 cube =
1124 (v2 t5) == (v3 t16) && (v3 t5) == (v2 t16)
1126 t5 = tetrahedron cube 5
1127 t16 = tetrahedron cube 16
1129 prop_t6_shares_edge_with_t7 :: Cube -> Bool
1130 prop_t6_shares_edge_with_t7 cube =
1131 (v1 t6) == (v1 t7) && (v3 t6) == (v2 t7)
1133 t6 = tetrahedron cube 6
1134 t7 = tetrahedron cube 7
1136 prop_t7_shares_edge_with_t20 :: Cube -> Bool
1137 prop_t7_shares_edge_with_t20 cube =
1138 (v2 t7) == (v3 t20) && (v2 t7) == (v3 t20)
1140 t7 = tetrahedron cube 7
1141 t20 = tetrahedron cube 20
1144 p79_26_properties :: TestTree
1146 testGroup "p. 79, Section (2.6) properties" [
1147 testProperty "c0120 identity1" prop_c0120_identity1,
1148 testProperty "c0120 identity2" prop_c0120_identity2,
1149 testProperty "c0120 identity3" prop_c0120_identity3,
1150 testProperty "c0120 identity4" prop_c0120_identity4,
1151 testProperty "c0120 identity5" prop_c0120_identity5,
1152 testProperty "c0120 identity6" prop_c0120_identity6,
1153 testProperty "c0120 identity7" prop_c0120_identity7,
1154 testProperty "c0210 identity1" prop_c0210_identity1,
1155 testProperty "c0300 identity1" prop_c0300_identity1,
1156 testProperty "c1110 identity" prop_c1110_identity,
1157 testProperty "c1200 identity1" prop_c1200_identity1,
1158 testProperty "c2100 identity1" prop_c2100_identity1]
1160 p79_27_properties :: TestTree
1162 testGroup "p. 79, Section (2.7) properties" [
1163 testProperty "c0102 identity1" prop_c0102_identity1,
1164 testProperty "c0201 identity1" prop_c0201_identity1,
1165 testProperty "c0300 identity2" prop_c0300_identity2,
1166 testProperty "c1101 identity" prop_c1101_identity,
1167 testProperty "c1200 identity2" prop_c1200_identity2,
1168 testProperty "c2100 identity2" prop_c2100_identity2 ]
1171 p79_28_properties :: TestTree
1173 testGroup "p. 79, Section (2.8) properties" [
1174 testProperty "c3000 identity" prop_c3000_identity,
1175 testProperty "c2010 identity" prop_c2010_identity,
1176 testProperty "c2001 identity" prop_c2001_identity,
1177 testProperty "c1020 identity" prop_c1020_identity,
1178 testProperty "c1002 identity" prop_c1002_identity,
1179 testProperty "c1011 identity" prop_c1011_identity ]
1182 edge_incidence_tests :: TestTree
1183 edge_incidence_tests =
1184 testGroup "Edge incidence tests" [
1185 testProperty "t0 shares edge with t6" prop_t0_shares_edge_with_t6,
1186 testProperty "t0 shares edge with t1" prop_t0_shares_edge_with_t1,
1187 testProperty "t0 shares edge with t3" prop_t0_shares_edge_with_t3,
1188 testProperty "t1 shares edge with t2" prop_t1_shares_edge_with_t2,
1189 testProperty "t1 shares edge with t19" prop_t1_shares_edge_with_t19,
1190 testProperty "t2 shares edge with t3" prop_t2_shares_edge_with_t3,
1191 testProperty "t2 shares edge with t12" prop_t2_shares_edge_with_t12,
1192 testProperty "t3 shares edge with t21" prop_t3_shares_edge_with_t21,
1193 testProperty "t4 shares edge with t5" prop_t4_shares_edge_with_t5,
1194 testProperty "t4 shares edge with t7" prop_t4_shares_edge_with_t7,
1195 testProperty "t4 shares edge with t10" prop_t4_shares_edge_with_t10,
1196 testProperty "t5 shares edge with t6" prop_t5_shares_edge_with_t6,
1197 testProperty "t5 shares edge with t16" prop_t5_shares_edge_with_t16,
1198 testProperty "t6 shares edge with t7" prop_t6_shares_edge_with_t7,
1199 testProperty "t7 shares edge with t20" prop_t7_shares_edge_with_t20 ]
1201 cube_properties :: TestTree
1203 testGroup "Cube properties" [
1207 edge_incidence_tests,
1208 testProperty "opposite octant tetrahedra are disjoint (1)"
1209 prop_opposite_octant_tetrahedra_disjoint1,
1210 testProperty "opposite octant tetrahedra are disjoint (2)"
1211 prop_opposite_octant_tetrahedra_disjoint2,
1212 testProperty "opposite octant tetrahedra are disjoint (3)"
1213 prop_opposite_octant_tetrahedra_disjoint3,
1214 testProperty "opposite octant tetrahedra are disjoint (4)"
1215 prop_opposite_octant_tetrahedra_disjoint4,
1216 testProperty "opposite octant tetrahedra are disjoint (5)"
1217 prop_opposite_octant_tetrahedra_disjoint5,
1218 testProperty "opposite octant tetrahedra are disjoint (6)"
1219 prop_opposite_octant_tetrahedra_disjoint6,
1220 testProperty "all volumes positive" prop_all_volumes_positive,
1221 testProperty "all volumes exact" prop_all_volumes_exact,
1222 testProperty "v0 all equal" prop_v0_all_equal,
1223 testProperty "interior values all identical"
1224 prop_interior_values_all_identical,
1225 testProperty "c-tilde_2100 rotation correct"
1226 prop_c_tilde_2100_rotation_correct,
1227 testProperty "c-tilde_2100 correct"
1228 prop_c_tilde_2100_correct ]