4 find_containing_tetrahedron,
10 import Data.Maybe (fromJust)
11 import qualified Data.Vector as V (
20 import Prelude hiding (LT)
21 import Test.Framework (Test, testGroup)
22 import Test.Framework.Providers.QuickCheck2 (testProperty)
23 import Test.QuickCheck (Arbitrary(..), Gen, Positive(..), choose)
26 import Comparisons ((~=), (~~=))
27 import qualified Face (Face(..), center)
28 import FunctionValues (FunctionValues, eval, rotate)
29 import Misc (all_equal, disjoint)
30 import Point (Point(..), dot)
31 import Tetrahedron (Tetrahedron(..), barycenter, c, volume)
33 data Cube = Cube { h :: !Double,
37 fv :: !FunctionValues,
38 tetrahedra_volume :: !Double }
42 instance Arbitrary Cube where
44 (Positive h') <- arbitrary :: Gen (Positive Double)
45 i' <- choose (coordmin, coordmax)
46 j' <- choose (coordmin, coordmax)
47 k' <- choose (coordmin, coordmax)
48 fv' <- arbitrary :: Gen FunctionValues
49 (Positive tet_vol) <- arbitrary :: Gen (Positive Double)
50 return (Cube h' i' j' k' fv' tet_vol)
52 -- The idea here is that, when cubed in the volume formula,
53 -- these numbers don't overflow 64 bits. This number is not
54 -- magic in any other sense than that it does not cause test
55 -- failures, while 2^23 does.
56 coordmax = 4194304 -- 2^22
60 instance Show Cube where
62 "Cube_" ++ subscript ++ "\n" ++
63 " h: " ++ (show (h cube)) ++ "\n" ++
64 " Center: " ++ (show (center cube)) ++ "\n" ++
65 " xmin: " ++ (show (xmin cube)) ++ "\n" ++
66 " xmax: " ++ (show (xmax cube)) ++ "\n" ++
67 " ymin: " ++ (show (ymin cube)) ++ "\n" ++
68 " ymax: " ++ (show (ymax cube)) ++ "\n" ++
69 " zmin: " ++ (show (zmin cube)) ++ "\n" ++
70 " zmax: " ++ (show (zmax cube)) ++ "\n"
73 (show (i cube)) ++ "," ++ (show (j cube)) ++ "," ++ (show (k cube))
76 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
78 xmin :: Cube -> Double
79 xmin cube = (i' - 1/2)*delta
81 i' = fromIntegral (i cube) :: Double
84 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
86 xmax :: Cube -> Double
87 xmax cube = (i' + 1/2)*delta
89 i' = fromIntegral (i cube) :: Double
92 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
94 ymin :: Cube -> Double
95 ymin cube = (j' - 1/2)*delta
97 j' = fromIntegral (j cube) :: Double
100 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
102 ymax :: Cube -> Double
103 ymax cube = (j' + 1/2)*delta
105 j' = fromIntegral (j cube) :: Double
108 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
110 zmin :: Cube -> Double
111 zmin cube = (k' - 1/2)*delta
113 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)*delta
121 k' = fromIntegral (k cube) :: Double
125 -- | The center of Cube_ijk coincides with v_ijk at
126 -- (ih, jh, kh). See Sorokina and Zeilfelder, p. 76.
127 center :: Cube -> Point
132 i' = fromIntegral (i cube) :: Double
133 j' = fromIntegral (j cube) :: Double
134 k' = 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)*(h cube)
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)*(h cube)
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)*(h cube)
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)*(h cube)
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)*(h cube)
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)*(h cube)
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
624 front_left_top_tetrahedra cube
626 front_left_down_tetrahedra cube
629 front_right_top_tetrahedra cube
631 front_right_down_tetrahedra cube
637 back_left_top_tetrahedra cube
639 back_left_down_tetrahedra cube
642 back_right_top_tetrahedra cube
644 back_right_down_tetrahedra cube
646 -- Use the dot product instead of Euclidean distance here to save
647 -- a sqrt(). So, "distances" below really means "distances
649 distances :: V.Vector Double
650 distances = V.map ((dot p) . barycenter) candidates
652 shortest_distance :: Double
653 shortest_distance = V.minimum distances
655 -- Compute the index of the tetrahedron with the center closest to
656 -- p. This is a bad algorithm, but don't change it! If you make it
657 -- smarter by finding the index of shortest_distance in distances
658 -- (this should give the same answer and avoids recomputing the
659 -- dot product), the program gets slower. Seriously!
660 lucky_idx :: Maybe Int
661 lucky_idx = V.findIndex
662 (\t -> (barycenter t) `dot` p == shortest_distance)
674 prop_opposite_octant_tetrahedra_disjoint1 :: Cube -> Bool
675 prop_opposite_octant_tetrahedra_disjoint1 cube =
676 disjoint (front_left_top_tetrahedra cube) (front_right_down_tetrahedra cube)
678 prop_opposite_octant_tetrahedra_disjoint2 :: Cube -> Bool
679 prop_opposite_octant_tetrahedra_disjoint2 cube =
680 disjoint (back_left_top_tetrahedra cube) (back_right_down_tetrahedra cube)
682 prop_opposite_octant_tetrahedra_disjoint3 :: Cube -> Bool
683 prop_opposite_octant_tetrahedra_disjoint3 cube =
684 disjoint (front_left_top_tetrahedra cube) (back_right_top_tetrahedra cube)
686 prop_opposite_octant_tetrahedra_disjoint4 :: Cube -> Bool
687 prop_opposite_octant_tetrahedra_disjoint4 cube =
688 disjoint (front_left_down_tetrahedra cube) (back_right_down_tetrahedra cube)
690 prop_opposite_octant_tetrahedra_disjoint5 :: Cube -> Bool
691 prop_opposite_octant_tetrahedra_disjoint5 cube =
692 disjoint (front_left_top_tetrahedra cube) (back_left_down_tetrahedra cube)
694 prop_opposite_octant_tetrahedra_disjoint6 :: Cube -> Bool
695 prop_opposite_octant_tetrahedra_disjoint6 cube =
696 disjoint (front_right_top_tetrahedra cube) (back_right_down_tetrahedra cube)
699 -- | Since the grid size is necessarily positive, all tetrahedra
700 -- (which comprise cubes of positive volume) must have positive
702 prop_all_volumes_positive :: Cube -> Bool
703 prop_all_volumes_positive cube =
707 volumes = map volume ts
710 -- | In fact, since all of the tetrahedra are identical, we should
711 -- already know their volumes. There's 24 tetrahedra to a cube, so
712 -- we'd expect the volume of each one to be (1/24)*h^3.
713 prop_all_volumes_exact :: Cube -> Bool
714 prop_all_volumes_exact cube =
715 and [volume t ~~= (1/24)*(delta^(3::Int)) | t <- tetrahedra cube]
719 -- | All tetrahedron should have their v0 located at the center of the
721 prop_v0_all_equal :: Cube -> Bool
722 prop_v0_all_equal cube = (v0 t0) == (v0 t1)
724 t0 = head (tetrahedra cube) -- Doesn't matter which two we choose.
725 t1 = head $ tail (tetrahedra cube)
728 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Note that the
729 -- third and fourth indices of c-t3 have been switched. This is
730 -- because we store the triangles oriented such that their volume is
731 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
732 -- in opposite directions, one of them has to have negative volume!
733 prop_c0120_identity1 :: Cube -> Bool
734 prop_c0120_identity1 cube =
735 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
737 t0 = tetrahedron cube 0
738 t3 = tetrahedron cube 3
741 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
742 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
743 prop_c0120_identity2 :: Cube -> Bool
744 prop_c0120_identity2 cube =
745 c t1 0 1 2 0 ~= (c t1 0 0 2 1 + c t0 0 0 1 2) / 2
747 t0 = tetrahedron cube 0
748 t1 = tetrahedron cube 1
750 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
751 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
752 prop_c0120_identity3 :: Cube -> Bool
753 prop_c0120_identity3 cube =
754 c t2 0 1 2 0 ~= (c t2 0 0 2 1 + c t1 0 0 1 2) / 2
756 t1 = tetrahedron cube 1
757 t2 = tetrahedron cube 2
759 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
760 -- 'prop_c0120_identity1' with tetrahedrons 2 and 3.
761 prop_c0120_identity4 :: Cube -> Bool
762 prop_c0120_identity4 cube =
763 c t3 0 1 2 0 ~= (c t3 0 0 2 1 + c t2 0 0 1 2) / 2
765 t2 = tetrahedron cube 2
766 t3 = tetrahedron cube 3
769 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
770 -- 'prop_c0120_identity1' with tetrahedrons 4 and 5.
771 prop_c0120_identity5 :: Cube -> Bool
772 prop_c0120_identity5 cube =
773 c t5 0 1 2 0 ~= (c t5 0 0 2 1 + c t4 0 0 1 2) / 2
775 t4 = tetrahedron cube 4
776 t5 = tetrahedron cube 5
778 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
779 -- 'prop_c0120_identity1' with tetrahedrons 5 and 6.
780 prop_c0120_identity6 :: Cube -> Bool
781 prop_c0120_identity6 cube =
782 c t6 0 1 2 0 ~= (c t6 0 0 2 1 + c t5 0 0 1 2) / 2
784 t5 = tetrahedron cube 5
785 t6 = tetrahedron cube 6
788 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
789 -- 'prop_c0120_identity1' with tetrahedrons 6 and 7.
790 prop_c0120_identity7 :: Cube -> Bool
791 prop_c0120_identity7 cube =
792 c t7 0 1 2 0 ~= (c t7 0 0 2 1 + c t6 0 0 1 2) / 2
794 t6 = tetrahedron cube 6
795 t7 = tetrahedron cube 7
798 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
799 -- 'prop_c0120_identity1'.
800 prop_c0210_identity1 :: Cube -> Bool
801 prop_c0210_identity1 cube =
802 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
804 t0 = tetrahedron cube 0
805 t3 = tetrahedron cube 3
808 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
809 -- 'prop_c0120_identity1'.
810 prop_c0300_identity1 :: Cube -> Bool
811 prop_c0300_identity1 cube =
812 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
814 t0 = tetrahedron cube 0
815 t3 = tetrahedron cube 3
818 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
819 -- 'prop_c0120_identity1'.
820 prop_c1110_identity :: Cube -> Bool
821 prop_c1110_identity cube =
822 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
824 t0 = tetrahedron cube 0
825 t3 = tetrahedron cube 3
828 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
829 -- 'prop_c0120_identity1'.
830 prop_c1200_identity1 :: Cube -> Bool
831 prop_c1200_identity1 cube =
832 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
834 t0 = tetrahedron cube 0
835 t3 = tetrahedron cube 3
838 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
839 -- 'prop_c0120_identity1'.
840 prop_c2100_identity1 :: Cube -> Bool
841 prop_c2100_identity1 cube =
842 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
844 t0 = tetrahedron cube 0
845 t3 = tetrahedron cube 3
849 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). Note that the
850 -- third and fourth indices of c-t3 have been switched. This is
851 -- because we store the triangles oriented such that their volume is
852 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
853 -- point in opposite directions, one of them has to have negative
855 prop_c0102_identity1 :: Cube -> Bool
856 prop_c0102_identity1 cube =
857 c t0 0 1 0 2 ~= (c t0 0 0 1 2 + c t1 0 0 2 1) / 2
859 t0 = tetrahedron cube 0
860 t1 = tetrahedron cube 1
863 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
864 -- 'prop_c0102_identity1'.
865 prop_c0201_identity1 :: Cube -> Bool
866 prop_c0201_identity1 cube =
867 c t0 0 2 0 1 ~= (c t0 0 1 1 1 + c t1 0 1 1 1) / 2
869 t0 = tetrahedron cube 0
870 t1 = tetrahedron cube 1
873 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
874 -- 'prop_c0102_identity1'.
875 prop_c0300_identity2 :: Cube -> Bool
876 prop_c0300_identity2 cube =
877 c t0 0 3 0 0 ~= (c t0 0 2 1 0 + c t1 0 2 0 1) / 2
879 t0 = tetrahedron cube 0
880 t1 = tetrahedron cube 1
883 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
884 -- 'prop_c0102_identity1'.
885 prop_c1101_identity :: Cube -> Bool
886 prop_c1101_identity cube =
887 c t0 1 1 0 1 ~= (c t0 1 0 1 1 + c t1 1 0 1 1) / 2
889 t0 = tetrahedron cube 0
890 t1 = tetrahedron cube 1
893 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
894 -- 'prop_c0102_identity1'.
895 prop_c1200_identity2 :: Cube -> Bool
896 prop_c1200_identity2 cube =
897 c t0 1 2 0 0 ~= (c t0 1 1 1 0 + c t1 1 1 0 1) / 2
899 t0 = tetrahedron cube 0
900 t1 = tetrahedron cube 1
903 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
904 -- 'prop_c0102_identity1'.
905 prop_c2100_identity2 :: Cube -> Bool
906 prop_c2100_identity2 cube =
907 c t0 2 1 0 0 ~= (c t0 2 0 1 0 + c t1 2 0 0 1) / 2
909 t0 = tetrahedron cube 0
910 t1 = tetrahedron cube 1
913 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). The third and
914 -- fourth indices of c-t6 have been switched. This is because we
915 -- store the triangles oriented such that their volume is
916 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
917 -- point in opposite directions, one of them has to have negative
919 prop_c3000_identity :: Cube -> Bool
920 prop_c3000_identity cube =
921 c t0 3 0 0 0 ~= c t0 2 1 0 0 + c t6 2 1 0 0
922 - ((c t0 2 0 1 0 + c t0 2 0 0 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_c2010_identity :: Cube -> Bool
931 prop_c2010_identity cube =
932 c t0 2 0 1 0 ~= c t0 1 1 1 0 + c t6 1 1 0 1
933 - ((c t0 1 0 2 0 + 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_c2001_identity :: Cube -> Bool
942 prop_c2001_identity cube =
943 c t0 2 0 0 1 ~= c t0 1 1 0 1 + c t6 1 1 1 0
944 - ((c t0 1 0 0 2 + c t0 1 0 1 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_c1020_identity :: Cube -> Bool
953 prop_c1020_identity cube =
954 c t0 1 0 2 0 ~= c t0 0 1 2 0 + c t6 0 1 0 2
955 - ((c t0 0 0 3 0 + c t0 0 0 2 1)/ 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_c1002_identity :: Cube -> Bool
964 prop_c1002_identity cube =
965 c t0 1 0 0 2 ~= c t0 0 1 0 2 + c t6 0 1 2 0
966 - ((c t0 0 0 0 3 + c t0 0 0 1 2)/ 2)
968 t0 = tetrahedron cube 0
969 t6 = tetrahedron cube 6
972 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
973 -- 'prop_c3000_identity'.
974 prop_c1011_identity :: Cube -> Bool
975 prop_c1011_identity cube =
976 c t0 1 0 1 1 ~= c t0 0 1 1 1 + c t6 0 1 1 1 -
977 ((c t0 0 0 1 2 + c t0 0 0 2 1)/ 2)
979 t0 = tetrahedron cube 0
980 t6 = tetrahedron cube 6
983 -- | The function values at the interior should be the same for all
985 prop_interior_values_all_identical :: Cube -> Bool
986 prop_interior_values_all_identical cube =
987 all_equal [ eval (function_values tet) I | tet <- tetrahedra cube ]
990 -- | We know what (c t6 2 1 0 0) should be from Sorokina and Zeilfelder, p. 87.
991 -- This test checks the rotation works as expected.
992 prop_c_tilde_2100_rotation_correct :: Cube -> Bool
993 prop_c_tilde_2100_rotation_correct cube =
996 t0 = tetrahedron cube 0
997 t6 = tetrahedron cube 6
999 -- What gets computed for c2100 of t6.
1000 expr1 = eval (function_values t6) $
1002 (1/12)*(T + R + L + D) +
1003 (1/64)*(FT + FR + FL + FD) +
1006 (1/96)*(RT + LD + LT + RD) +
1007 (1/192)*(BT + BR + BL + BD)
1009 -- What should be computed for c2100 of t6.
1010 expr2 = eval (function_values t0) $
1012 (1/12)*(F + R + L + B) +
1013 (1/64)*(FT + RT + LT + BT) +
1016 (1/96)*(FR + FL + BR + BL) +
1017 (1/192)*(FD + RD + LD + BD)
1020 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
1021 -- Zeilfelder, p. 87. This test checks the actual value based on
1022 -- the FunctionValues of the cube.
1024 -- If 'prop_c_tilde_2100_rotation_correct' passes, then this test is
1026 prop_c_tilde_2100_correct :: Cube -> Bool
1027 prop_c_tilde_2100_correct cube =
1028 c t6 2 1 0 0 == expected
1030 t0 = tetrahedron cube 0
1031 t6 = tetrahedron cube 6
1032 fvs = function_values t0
1033 expected = eval fvs $
1035 (1/12)*(F + R + L + B) +
1036 (1/64)*(FT + RT + LT + BT) +
1039 (1/96)*(FR + FL + BR + BL) +
1040 (1/192)*(FD + RD + LD + BD)
1043 -- Tests to check that the correct edges are incidental.
1044 prop_t0_shares_edge_with_t1 :: Cube -> Bool
1045 prop_t0_shares_edge_with_t1 cube =
1046 (v1 t0) == (v1 t1) && (v3 t0) == (v2 t1)
1048 t0 = tetrahedron cube 0
1049 t1 = tetrahedron cube 1
1051 prop_t0_shares_edge_with_t3 :: Cube -> Bool
1052 prop_t0_shares_edge_with_t3 cube =
1053 (v1 t0) == (v1 t3) && (v2 t0) == (v3 t3)
1055 t0 = tetrahedron cube 0
1056 t3 = tetrahedron cube 3
1058 prop_t0_shares_edge_with_t6 :: Cube -> Bool
1059 prop_t0_shares_edge_with_t6 cube =
1060 (v2 t0) == (v3 t6) && (v3 t0) == (v2 t6)
1062 t0 = tetrahedron cube 0
1063 t6 = tetrahedron cube 6
1065 prop_t1_shares_edge_with_t2 :: Cube -> Bool
1066 prop_t1_shares_edge_with_t2 cube =
1067 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1069 t1 = tetrahedron cube 1
1070 t2 = tetrahedron cube 2
1072 prop_t1_shares_edge_with_t19 :: Cube -> Bool
1073 prop_t1_shares_edge_with_t19 cube =
1074 (v2 t1) == (v3 t19) && (v3 t1) == (v2 t19)
1076 t1 = tetrahedron cube 1
1077 t19 = tetrahedron cube 19
1079 prop_t2_shares_edge_with_t3 :: Cube -> Bool
1080 prop_t2_shares_edge_with_t3 cube =
1081 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1083 t1 = tetrahedron cube 1
1084 t2 = tetrahedron cube 2
1086 prop_t2_shares_edge_with_t12 :: Cube -> Bool
1087 prop_t2_shares_edge_with_t12 cube =
1088 (v2 t2) == (v3 t12) && (v3 t2) == (v2 t12)
1090 t2 = tetrahedron cube 2
1091 t12 = tetrahedron cube 12
1093 prop_t3_shares_edge_with_t21 :: Cube -> Bool
1094 prop_t3_shares_edge_with_t21 cube =
1095 (v2 t3) == (v3 t21) && (v3 t3) == (v2 t21)
1097 t3 = tetrahedron cube 3
1098 t21 = tetrahedron cube 21
1100 prop_t4_shares_edge_with_t5 :: Cube -> Bool
1101 prop_t4_shares_edge_with_t5 cube =
1102 (v1 t4) == (v1 t5) && (v3 t4) == (v2 t5)
1104 t4 = tetrahedron cube 4
1105 t5 = tetrahedron cube 5
1107 prop_t4_shares_edge_with_t7 :: Cube -> Bool
1108 prop_t4_shares_edge_with_t7 cube =
1109 (v1 t4) == (v1 t7) && (v2 t4) == (v3 t7)
1111 t4 = tetrahedron cube 4
1112 t7 = tetrahedron cube 7
1114 prop_t4_shares_edge_with_t10 :: Cube -> Bool
1115 prop_t4_shares_edge_with_t10 cube =
1116 (v2 t4) == (v3 t10) && (v3 t4) == (v2 t10)
1118 t4 = tetrahedron cube 4
1119 t10 = tetrahedron cube 10
1121 prop_t5_shares_edge_with_t6 :: Cube -> Bool
1122 prop_t5_shares_edge_with_t6 cube =
1123 (v1 t5) == (v1 t6) && (v3 t5) == (v2 t6)
1125 t5 = tetrahedron cube 5
1126 t6 = tetrahedron cube 6
1128 prop_t5_shares_edge_with_t16 :: Cube -> Bool
1129 prop_t5_shares_edge_with_t16 cube =
1130 (v2 t5) == (v3 t16) && (v3 t5) == (v2 t16)
1132 t5 = tetrahedron cube 5
1133 t16 = tetrahedron cube 16
1135 prop_t6_shares_edge_with_t7 :: Cube -> Bool
1136 prop_t6_shares_edge_with_t7 cube =
1137 (v1 t6) == (v1 t7) && (v3 t6) == (v2 t7)
1139 t6 = tetrahedron cube 6
1140 t7 = tetrahedron cube 7
1142 prop_t7_shares_edge_with_t20 :: Cube -> Bool
1143 prop_t7_shares_edge_with_t20 cube =
1144 (v2 t7) == (v3 t20) && (v2 t7) == (v3 t20)
1146 t7 = tetrahedron cube 7
1147 t20 = tetrahedron cube 20
1150 p79_26_properties :: Test.Framework.Test
1152 testGroup "p. 79, Section (2.6) Properties" [
1153 testProperty "c0120 identity1" prop_c0120_identity1,
1154 testProperty "c0120 identity2" prop_c0120_identity2,
1155 testProperty "c0120 identity3" prop_c0120_identity3,
1156 testProperty "c0120 identity4" prop_c0120_identity4,
1157 testProperty "c0120 identity5" prop_c0120_identity5,
1158 testProperty "c0120 identity6" prop_c0120_identity6,
1159 testProperty "c0120 identity7" prop_c0120_identity7,
1160 testProperty "c0210 identity1" prop_c0210_identity1,
1161 testProperty "c0300 identity1" prop_c0300_identity1,
1162 testProperty "c1110 identity" prop_c1110_identity,
1163 testProperty "c1200 identity1" prop_c1200_identity1,
1164 testProperty "c2100 identity1" prop_c2100_identity1]
1166 p79_27_properties :: Test.Framework.Test
1168 testGroup "p. 79, Section (2.7) Properties" [
1169 testProperty "c0102 identity1" prop_c0102_identity1,
1170 testProperty "c0201 identity1" prop_c0201_identity1,
1171 testProperty "c0300 identity2" prop_c0300_identity2,
1172 testProperty "c1101 identity" prop_c1101_identity,
1173 testProperty "c1200 identity2" prop_c1200_identity2,
1174 testProperty "c2100 identity2" prop_c2100_identity2 ]
1177 p79_28_properties :: Test.Framework.Test
1179 testGroup "p. 79, Section (2.8) Properties" [
1180 testProperty "c3000 identity" prop_c3000_identity,
1181 testProperty "c2010 identity" prop_c2010_identity,
1182 testProperty "c2001 identity" prop_c2001_identity,
1183 testProperty "c1020 identity" prop_c1020_identity,
1184 testProperty "c1002 identity" prop_c1002_identity,
1185 testProperty "c1011 identity" prop_c1011_identity ]
1188 edge_incidence_tests :: Test.Framework.Test
1189 edge_incidence_tests =
1190 testGroup "Edge Incidence Tests" [
1191 testProperty "t0 shares edge with t6" prop_t0_shares_edge_with_t6,
1192 testProperty "t0 shares edge with t1" prop_t0_shares_edge_with_t1,
1193 testProperty "t0 shares edge with t3" prop_t0_shares_edge_with_t3,
1194 testProperty "t1 shares edge with t2" prop_t1_shares_edge_with_t2,
1195 testProperty "t1 shares edge with t19" prop_t1_shares_edge_with_t19,
1196 testProperty "t2 shares edge with t3" prop_t2_shares_edge_with_t3,
1197 testProperty "t2 shares edge with t12" prop_t2_shares_edge_with_t12,
1198 testProperty "t3 shares edge with t21" prop_t3_shares_edge_with_t21,
1199 testProperty "t4 shares edge with t5" prop_t4_shares_edge_with_t5,
1200 testProperty "t4 shares edge with t7" prop_t4_shares_edge_with_t7,
1201 testProperty "t4 shares edge with t10" prop_t4_shares_edge_with_t10,
1202 testProperty "t5 shares edge with t6" prop_t5_shares_edge_with_t6,
1203 testProperty "t5 shares edge with t16" prop_t5_shares_edge_with_t16,
1204 testProperty "t6 shares edge with t7" prop_t6_shares_edge_with_t7,
1205 testProperty "t7 shares edge with t20" prop_t7_shares_edge_with_t20 ]
1207 cube_properties :: Test.Framework.Test
1209 testGroup "Cube Properties" [
1213 edge_incidence_tests,
1214 testProperty "opposite octant tetrahedra are disjoint (1)"
1215 prop_opposite_octant_tetrahedra_disjoint1,
1216 testProperty "opposite octant tetrahedra are disjoint (2)"
1217 prop_opposite_octant_tetrahedra_disjoint2,
1218 testProperty "opposite octant tetrahedra are disjoint (3)"
1219 prop_opposite_octant_tetrahedra_disjoint3,
1220 testProperty "opposite octant tetrahedra are disjoint (4)"
1221 prop_opposite_octant_tetrahedra_disjoint4,
1222 testProperty "opposite octant tetrahedra are disjoint (5)"
1223 prop_opposite_octant_tetrahedra_disjoint5,
1224 testProperty "opposite octant tetrahedra are disjoint (6)"
1225 prop_opposite_octant_tetrahedra_disjoint6,
1226 testProperty "all volumes positive" prop_all_volumes_positive,
1227 testProperty "all volumes exact" prop_all_volumes_exact,
1228 testProperty "v0 all equal" prop_v0_all_equal,
1229 testProperty "interior values all identical"
1230 prop_interior_values_all_identical,
1231 testProperty "c-tilde_2100 rotation correct"
1232 prop_c_tilde_2100_rotation_correct,
1233 testProperty "c-tilde_2100 correct"
1234 prop_c_tilde_2100_correct ]