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(Face, v0, v1, v2, v3))
28 import FunctionValues (FunctionValues, eval, rotate)
29 import Misc (all_equal, disjoint)
30 import Point (Point(..), dot)
31 import Tetrahedron (Tetrahedron(..), c, volume)
32 import ThreeDimensional
34 data Cube = Cube { h :: !Double,
38 fv :: !FunctionValues,
39 tetrahedra_volume :: !Double }
43 instance Arbitrary Cube where
45 (Positive h') <- arbitrary :: Gen (Positive Double)
46 i' <- choose (coordmin, coordmax)
47 j' <- choose (coordmin, coordmax)
48 k' <- choose (coordmin, coordmax)
49 fv' <- arbitrary :: Gen FunctionValues
50 (Positive tet_vol) <- arbitrary :: Gen (Positive Double)
51 return (Cube h' i' j' k' fv' tet_vol)
53 -- The idea here is that, when cubed in the volume formula,
54 -- these numbers don't overflow 64 bits. This number is not
55 -- magic in any other sense than that it does not cause test
56 -- failures, while 2^23 does.
57 coordmax = 4194304 -- 2^22
61 instance Show Cube where
63 "Cube_" ++ subscript ++ "\n" ++
64 " h: " ++ (show (h cube)) ++ "\n" ++
65 " Center: " ++ (show (center cube)) ++ "\n" ++
66 " xmin: " ++ (show (xmin cube)) ++ "\n" ++
67 " xmax: " ++ (show (xmax cube)) ++ "\n" ++
68 " ymin: " ++ (show (ymin cube)) ++ "\n" ++
69 " ymax: " ++ (show (ymax cube)) ++ "\n" ++
70 " zmin: " ++ (show (zmin cube)) ++ "\n" ++
71 " zmax: " ++ (show (zmax cube)) ++ "\n"
74 (show (i cube)) ++ "," ++ (show (j cube)) ++ "," ++ (show (k cube))
77 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
79 xmin :: Cube -> Double
80 xmin cube = (i' - 1/2)*delta
82 i' = fromIntegral (i cube) :: Double
85 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
87 xmax :: Cube -> Double
88 xmax cube = (i' + 1/2)*delta
90 i' = fromIntegral (i cube) :: Double
93 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
95 ymin :: Cube -> Double
96 ymin cube = (j' - 1/2)*delta
98 j' = fromIntegral (j cube) :: Double
101 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
103 ymax :: Cube -> Double
104 ymax cube = (j' + 1/2)*delta
106 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)*delta
114 k' = fromIntegral (k cube) :: Double
117 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
119 zmax :: Cube -> Double
120 zmax cube = (k' + 1/2)*delta
122 k' = fromIntegral (k cube) :: Double
125 instance ThreeDimensional Cube where
126 -- | The center of Cube_ijk coincides with v_ijk at
127 -- (ih, jh, kh). See Sorokina and Zeilfelder, p. 76.
128 center cube = Point x y z
131 i' = fromIntegral (i cube) :: Double
132 j' = fromIntegral (j cube) :: Double
133 k' = fromIntegral (k cube) :: Double
138 -- | It's easy to tell if a point is within a cube; just make sure
139 -- that it falls on the proper side of each of the cube's faces.
140 contains_point cube (Point x y z)
141 | x < (xmin cube) = False
142 | x > (xmax cube) = False
143 | y < (ymin cube) = False
144 | y > (ymax cube) = False
145 | z < (zmin cube) = False
146 | z > (zmax cube) = False
153 -- | The top (in the direction of z) face of the cube.
154 top_face :: Cube -> Face.Face
155 top_face cube = Face.Face v0' v1' v2' v3'
157 delta = (1/2)*(h cube)
159 v0' = cc + ( Point delta (-delta) delta )
160 v1' = cc + ( Point delta delta delta )
161 v2' = cc + ( Point (-delta) delta delta )
162 v3' = cc + ( Point (-delta) (-delta) delta )
166 -- | The back (in the direction of x) face of the cube.
167 back_face :: Cube -> Face.Face
168 back_face cube = Face.Face v0' v1' v2' v3'
170 delta = (1/2)*(h cube)
172 v0' = cc + ( Point delta (-delta) (-delta) )
173 v1' = cc + ( Point delta delta (-delta) )
174 v2' = cc + ( Point delta delta delta )
175 v3' = cc + ( Point delta (-delta) delta )
178 -- The bottom face (in the direction of -z) of the cube.
179 down_face :: Cube -> Face.Face
180 down_face cube = Face.Face v0' v1' v2' v3'
182 delta = (1/2)*(h cube)
184 v0' = cc + ( Point (-delta) (-delta) (-delta) )
185 v1' = cc + ( Point (-delta) delta (-delta) )
186 v2' = cc + ( Point delta delta (-delta) )
187 v3' = cc + ( Point delta (-delta) (-delta) )
191 -- | The front (in the direction of -x) face of the cube.
192 front_face :: Cube -> Face.Face
193 front_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) )
202 -- | The left (in the direction of -y) face of the cube.
203 left_face :: Cube -> Face.Face
204 left_face cube = Face.Face v0' v1' v2' v3'
206 delta = (1/2)*(h cube)
208 v0' = cc + ( Point delta (-delta) delta )
209 v1' = cc + ( Point (-delta) (-delta) delta )
210 v2' = cc + ( Point (-delta) (-delta) (-delta) )
211 v3' = cc + ( Point delta (-delta) (-delta) )
214 -- | The right (in the direction of y) face of the cube.
215 right_face :: Cube -> Face.Face
216 right_face cube = Face.Face v0' v1' v2' v3'
218 delta = (1/2)*(h cube)
220 v0' = cc + ( Point (-delta) delta delta)
221 v1' = cc + ( Point delta delta delta )
222 v2' = cc + ( Point delta delta (-delta) )
223 v3' = cc + ( Point (-delta) delta (-delta) )
226 tetrahedron :: Cube -> Int -> Tetrahedron
229 Tetrahedron (fv cube) v0' v1' v2' v3' vol
236 vol = tetrahedra_volume cube
239 Tetrahedron fv' v0' v1' v2' v3' vol
246 fv' = rotate ccwx (fv cube)
247 vol = tetrahedra_volume cube
250 Tetrahedron fv' v0' v1' v2' v3' vol
257 fv' = rotate ccwx $ rotate ccwx $ fv cube
258 vol = tetrahedra_volume cube
261 Tetrahedron fv' v0' v1' v2' v3' vol
268 fv' = rotate cwx (fv cube)
269 vol = tetrahedra_volume cube
272 Tetrahedron fv' v0' v1' v2' v3' vol
279 fv' = rotate cwy (fv cube)
280 vol = tetrahedra_volume cube
283 Tetrahedron fv' v0' v1' v2' v3' vol
290 fv' = rotate cwy $ rotate cwz $ fv cube
291 vol = tetrahedra_volume cube
294 Tetrahedron fv' v0' v1' v2' v3' vol
301 fv' = rotate cwy $ rotate cwz
304 vol = tetrahedra_volume cube
307 Tetrahedron fv' v0' v1' v2' v3' vol
314 fv' = rotate cwy $ rotate ccwz $ fv cube
315 vol = tetrahedra_volume cube
318 Tetrahedron fv' v0' v1' v2' v3' vol
325 fv' = rotate cwy $ rotate cwy $ fv cube
326 vol = tetrahedra_volume cube
329 Tetrahedron fv' v0' v1' v2' v3' vol
336 fv' = rotate cwy $ rotate cwy
339 vol = tetrahedra_volume cube
341 tetrahedron cube 10 =
342 Tetrahedron fv' v0' v1' v2' v3' vol
349 fv' = rotate cwy $ rotate cwy
354 vol = tetrahedra_volume cube
356 tetrahedron cube 11 =
357 Tetrahedron fv' v0' v1' v2' v3' vol
364 fv' = rotate cwy $ rotate cwy
367 vol = tetrahedra_volume cube
369 tetrahedron cube 12 =
370 Tetrahedron fv' v0' v1' v2' v3' vol
377 fv' = rotate ccwy $ fv cube
378 vol = tetrahedra_volume cube
380 tetrahedron cube 13 =
381 Tetrahedron fv' v0' v1' v2' v3' vol
388 fv' = rotate ccwy $ rotate ccwz $ fv cube
389 vol = tetrahedra_volume cube
391 tetrahedron cube 14 =
392 Tetrahedron fv' v0' v1' v2' v3' vol
399 fv' = rotate ccwy $ rotate ccwz
402 vol = tetrahedra_volume cube
404 tetrahedron cube 15 =
405 Tetrahedron fv' v0' v1' v2' v3' vol
412 fv' = rotate ccwy $ rotate cwz $ fv cube
413 vol = tetrahedra_volume cube
415 tetrahedron cube 16 =
416 Tetrahedron fv' v0' v1' v2' v3' vol
423 fv' = rotate ccwz $ fv cube
424 vol = tetrahedra_volume cube
426 tetrahedron cube 17 =
427 Tetrahedron fv' v0' v1' v2' v3' vol
434 fv' = rotate ccwz $ rotate cwy $ fv cube
435 vol = tetrahedra_volume cube
437 tetrahedron cube 18 =
438 Tetrahedron fv' v0' v1' v2' v3' vol
445 fv' = rotate ccwz $ rotate cwy
448 vol = tetrahedra_volume cube
450 tetrahedron cube 19 =
451 Tetrahedron fv' v0' v1' v2' v3' vol
458 fv' = rotate ccwz $ rotate ccwy
460 vol = tetrahedra_volume cube
462 tetrahedron cube 20 =
463 Tetrahedron fv' v0' v1' v2' v3' vol
470 fv' = rotate cwz $ fv cube
471 vol = tetrahedra_volume cube
473 tetrahedron cube 21 =
474 Tetrahedron fv' v0' v1' v2' v3' vol
481 fv' = rotate cwz $ rotate ccwy $ fv cube
482 vol = tetrahedra_volume cube
484 tetrahedron cube 22 =
485 Tetrahedron fv' v0' v1' v2' v3' vol
492 fv' = rotate cwz $ rotate ccwy
495 vol = tetrahedra_volume cube
497 tetrahedron cube 23 =
498 Tetrahedron fv' v0' v1' v2' v3' vol
505 fv' = rotate cwz $ rotate cwy
507 vol = tetrahedra_volume cube
509 -- Feels dirty, but whatever.
510 tetrahedron _ _ = error "asked for a nonexistent tetrahedron"
513 -- Only used in tests, so we don't need the added speed
515 tetrahedra :: Cube -> [Tetrahedron]
516 tetrahedra cube = [ tetrahedron cube n | n <- [0..23] ]
518 front_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
519 front_left_top_tetrahedra cube =
520 V.singleton (tetrahedron cube 0) `V.snoc`
521 (tetrahedron cube 3) `V.snoc`
522 (tetrahedron cube 6) `V.snoc`
523 (tetrahedron cube 7) `V.snoc`
524 (tetrahedron cube 20) `V.snoc`
525 (tetrahedron cube 21)
527 front_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
528 front_left_down_tetrahedra cube =
529 V.singleton (tetrahedron cube 0) `V.snoc`
530 (tetrahedron cube 2) `V.snoc`
531 (tetrahedron cube 3) `V.snoc`
532 (tetrahedron cube 12) `V.snoc`
533 (tetrahedron cube 15) `V.snoc`
534 (tetrahedron cube 21)
536 front_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
537 front_right_top_tetrahedra cube =
538 V.singleton (tetrahedron cube 0) `V.snoc`
539 (tetrahedron cube 1) `V.snoc`
540 (tetrahedron cube 5) `V.snoc`
541 (tetrahedron cube 6) `V.snoc`
542 (tetrahedron cube 16) `V.snoc`
543 (tetrahedron cube 19)
545 front_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
546 front_right_down_tetrahedra cube =
547 V.singleton (tetrahedron cube 1) `V.snoc`
548 (tetrahedron cube 2) `V.snoc`
549 (tetrahedron cube 12) `V.snoc`
550 (tetrahedron cube 13) `V.snoc`
551 (tetrahedron cube 18) `V.snoc`
552 (tetrahedron cube 19)
554 back_left_top_tetrahedra :: Cube -> V.Vector Tetrahedron
555 back_left_top_tetrahedra cube =
556 V.singleton (tetrahedron cube 0) `V.snoc`
557 (tetrahedron cube 3) `V.snoc`
558 (tetrahedron cube 6) `V.snoc`
559 (tetrahedron cube 7) `V.snoc`
560 (tetrahedron cube 20) `V.snoc`
561 (tetrahedron cube 21)
563 back_left_down_tetrahedra :: Cube -> V.Vector Tetrahedron
564 back_left_down_tetrahedra cube =
565 V.singleton (tetrahedron cube 8) `V.snoc`
566 (tetrahedron cube 11) `V.snoc`
567 (tetrahedron cube 14) `V.snoc`
568 (tetrahedron cube 15) `V.snoc`
569 (tetrahedron cube 22) `V.snoc`
570 (tetrahedron cube 23)
572 back_right_top_tetrahedra :: Cube -> V.Vector Tetrahedron
573 back_right_top_tetrahedra cube =
574 V.singleton (tetrahedron cube 4) `V.snoc`
575 (tetrahedron cube 5) `V.snoc`
576 (tetrahedron cube 9) `V.snoc`
577 (tetrahedron cube 10) `V.snoc`
578 (tetrahedron cube 16) `V.snoc`
579 (tetrahedron cube 17)
581 back_right_down_tetrahedra :: Cube -> V.Vector Tetrahedron
582 back_right_down_tetrahedra cube =
583 V.singleton (tetrahedron cube 8) `V.snoc`
584 (tetrahedron cube 9) `V.snoc`
585 (tetrahedron cube 13) `V.snoc`
586 (tetrahedron cube 14) `V.snoc`
587 (tetrahedron cube 17) `V.snoc`
588 (tetrahedron cube 18)
590 in_top_half :: Cube -> Point -> Bool
591 in_top_half cube (Point _ _ z) =
592 distance_from_top <= distance_from_bottom
594 distance_from_top = abs $ (zmax cube) - z
595 distance_from_bottom = abs $ (zmin cube) - z
597 in_front_half :: Cube -> Point -> Bool
598 in_front_half cube (Point x _ _) =
599 distance_from_front <= distance_from_back
601 distance_from_front = abs $ (xmin cube) - x
602 distance_from_back = abs $ (xmax cube) - x
605 in_left_half :: Cube -> Point -> Bool
606 in_left_half cube (Point _ y _) =
607 distance_from_left <= distance_from_right
609 distance_from_left = abs $ (ymin cube) - y
610 distance_from_right = abs $ (ymax cube) - y
613 -- | Takes a 'Cube', and returns the Tetrahedra belonging to it that
614 -- contain the given 'Point'. This should be faster than checking
615 -- every tetrahedron individually, since we determine which half
616 -- (hemisphere?) of the cube the point lies in three times: once in
617 -- each dimension. This allows us to eliminate non-candidates
620 -- This can throw an exception, but the use of 'head' might
621 -- save us some unnecessary computations.
623 find_containing_tetrahedron :: Cube -> Point -> Tetrahedron
624 find_containing_tetrahedron cube p =
625 candidates `V.unsafeIndex` (fromJust lucky_idx)
627 front_half = in_front_half cube p
628 top_half = in_top_half cube p
629 left_half = in_left_half cube p
636 front_left_top_tetrahedra cube
638 front_left_down_tetrahedra cube
641 front_right_top_tetrahedra cube
643 front_right_down_tetrahedra cube
649 back_left_top_tetrahedra cube
651 back_left_down_tetrahedra cube
654 back_right_top_tetrahedra cube
656 back_right_down_tetrahedra cube
658 -- Use the dot product instead of Euclidean distance here to save
659 -- a sqrt(). So, "distances" below really means "distances
661 distances = V.map ((dot p) . center) candidates
662 shortest_distance = V.minimum distances
663 lucky_idx = V.findIndex
664 (\t -> (center t) `dot` p == shortest_distance)
676 prop_opposite_octant_tetrahedra_disjoint1 :: Cube -> Bool
677 prop_opposite_octant_tetrahedra_disjoint1 cube =
678 disjoint (front_left_top_tetrahedra cube) (front_right_down_tetrahedra cube)
680 prop_opposite_octant_tetrahedra_disjoint2 :: Cube -> Bool
681 prop_opposite_octant_tetrahedra_disjoint2 cube =
682 disjoint (back_left_top_tetrahedra cube) (back_right_down_tetrahedra cube)
684 prop_opposite_octant_tetrahedra_disjoint3 :: Cube -> Bool
685 prop_opposite_octant_tetrahedra_disjoint3 cube =
686 disjoint (front_left_top_tetrahedra cube) (back_right_top_tetrahedra cube)
688 prop_opposite_octant_tetrahedra_disjoint4 :: Cube -> Bool
689 prop_opposite_octant_tetrahedra_disjoint4 cube =
690 disjoint (front_left_down_tetrahedra cube) (back_right_down_tetrahedra cube)
692 prop_opposite_octant_tetrahedra_disjoint5 :: Cube -> Bool
693 prop_opposite_octant_tetrahedra_disjoint5 cube =
694 disjoint (front_left_top_tetrahedra cube) (back_left_down_tetrahedra cube)
696 prop_opposite_octant_tetrahedra_disjoint6 :: Cube -> Bool
697 prop_opposite_octant_tetrahedra_disjoint6 cube =
698 disjoint (front_right_top_tetrahedra cube) (back_right_down_tetrahedra cube)
701 -- | Since the grid size is necessarily positive, all tetrahedra
702 -- (which comprise cubes of positive volume) must have positive
704 prop_all_volumes_positive :: Cube -> Bool
705 prop_all_volumes_positive cube =
709 volumes = map volume ts
712 -- | In fact, since all of the tetrahedra are identical, we should
713 -- already know their volumes. There's 24 tetrahedra to a cube, so
714 -- we'd expect the volume of each one to be (1/24)*h^3.
715 prop_all_volumes_exact :: Cube -> Bool
716 prop_all_volumes_exact cube =
717 and [volume t ~~= (1/24)*(delta^(3::Int)) | t <- tetrahedra cube]
721 -- | All tetrahedron should have their v0 located at the center of the cube.
722 prop_v0_all_equal :: Cube -> Bool
723 prop_v0_all_equal cube = (v0 t0) == (v0 t1)
725 t0 = head (tetrahedra cube) -- Doesn't matter which two we choose.
726 t1 = head $ tail (tetrahedra cube)
729 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Note that the
730 -- third and fourth indices of c-t3 have been switched. This is
731 -- because we store the triangles oriented such that their volume is
732 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
733 -- in opposite directions, one of them has to have negative volume!
734 prop_c0120_identity1 :: Cube -> Bool
735 prop_c0120_identity1 cube =
736 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
738 t0 = tetrahedron cube 0
739 t3 = tetrahedron cube 3
742 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
743 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
744 prop_c0120_identity2 :: Cube -> Bool
745 prop_c0120_identity2 cube =
746 c t1 0 1 2 0 ~= (c t1 0 0 2 1 + c t0 0 0 1 2) / 2
748 t0 = tetrahedron cube 0
749 t1 = tetrahedron cube 1
751 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
752 -- 'prop_c0120_identity1' with tetrahedrons 1 and 2.
753 prop_c0120_identity3 :: Cube -> Bool
754 prop_c0120_identity3 cube =
755 c t2 0 1 2 0 ~= (c t2 0 0 2 1 + c t1 0 0 1 2) / 2
757 t1 = tetrahedron cube 1
758 t2 = tetrahedron cube 2
760 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
761 -- 'prop_c0120_identity1' with tetrahedrons 2 and 3.
762 prop_c0120_identity4 :: Cube -> Bool
763 prop_c0120_identity4 cube =
764 c t3 0 1 2 0 ~= (c t3 0 0 2 1 + c t2 0 0 1 2) / 2
766 t2 = tetrahedron cube 2
767 t3 = tetrahedron cube 3
770 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
771 -- 'prop_c0120_identity1' with tetrahedrons 4 and 5.
772 prop_c0120_identity5 :: Cube -> Bool
773 prop_c0120_identity5 cube =
774 c t5 0 1 2 0 ~= (c t5 0 0 2 1 + c t4 0 0 1 2) / 2
776 t4 = tetrahedron cube 4
777 t5 = tetrahedron cube 5
779 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
780 -- 'prop_c0120_identity1' with tetrahedrons 5 and 6.
781 prop_c0120_identity6 :: Cube -> Bool
782 prop_c0120_identity6 cube =
783 c t6 0 1 2 0 ~= (c t6 0 0 2 1 + c t5 0 0 1 2) / 2
785 t5 = tetrahedron cube 5
786 t6 = tetrahedron cube 6
789 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). Repeats
790 -- 'prop_c0120_identity1' with tetrahedrons 6 and 7.
791 prop_c0120_identity7 :: Cube -> Bool
792 prop_c0120_identity7 cube =
793 c t7 0 1 2 0 ~= (c t7 0 0 2 1 + c t6 0 0 1 2) / 2
795 t6 = tetrahedron cube 6
796 t7 = tetrahedron cube 7
799 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
800 -- 'prop_c0120_identity1'.
801 prop_c0210_identity1 :: Cube -> Bool
802 prop_c0210_identity1 cube =
803 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
805 t0 = tetrahedron cube 0
806 t3 = tetrahedron cube 3
809 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
810 -- 'prop_c0120_identity1'.
811 prop_c0300_identity1 :: Cube -> Bool
812 prop_c0300_identity1 cube =
813 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
815 t0 = tetrahedron cube 0
816 t3 = tetrahedron cube 3
819 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
820 -- 'prop_c0120_identity1'.
821 prop_c1110_identity :: Cube -> Bool
822 prop_c1110_identity cube =
823 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
825 t0 = tetrahedron cube 0
826 t3 = tetrahedron cube 3
829 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
830 -- 'prop_c0120_identity1'.
831 prop_c1200_identity1 :: Cube -> Bool
832 prop_c1200_identity1 cube =
833 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
835 t0 = tetrahedron cube 0
836 t3 = tetrahedron cube 3
839 -- | Given in Sorokina and Zeilfelder, p. 79, (2.6). See
840 -- 'prop_c0120_identity1'.
841 prop_c2100_identity1 :: Cube -> Bool
842 prop_c2100_identity1 cube =
843 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
845 t0 = tetrahedron cube 0
846 t3 = tetrahedron cube 3
850 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). Note that the
851 -- third and fourth indices of c-t3 have been switched. This is
852 -- because we store the triangles oriented such that their volume is
853 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
854 -- point in opposite directions, one of them has to have negative
856 prop_c0102_identity1 :: Cube -> Bool
857 prop_c0102_identity1 cube =
858 c t0 0 1 0 2 ~= (c t0 0 0 1 2 + c t1 0 0 2 1) / 2
860 t0 = tetrahedron cube 0
861 t1 = tetrahedron cube 1
864 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
865 -- 'prop_c0102_identity1'.
866 prop_c0201_identity1 :: Cube -> Bool
867 prop_c0201_identity1 cube =
868 c t0 0 2 0 1 ~= (c t0 0 1 1 1 + c t1 0 1 1 1) / 2
870 t0 = tetrahedron cube 0
871 t1 = tetrahedron cube 1
874 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
875 -- 'prop_c0102_identity1'.
876 prop_c0300_identity2 :: Cube -> Bool
877 prop_c0300_identity2 cube =
878 c t0 0 3 0 0 ~= (c t0 0 2 1 0 + c t1 0 2 0 1) / 2
880 t0 = tetrahedron cube 0
881 t1 = tetrahedron cube 1
884 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
885 -- 'prop_c0102_identity1'.
886 prop_c1101_identity :: Cube -> Bool
887 prop_c1101_identity cube =
888 c t0 1 1 0 1 ~= (c t0 1 0 1 1 + c t1 1 0 1 1) / 2
890 t0 = tetrahedron cube 0
891 t1 = tetrahedron cube 1
894 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
895 -- 'prop_c0102_identity1'.
896 prop_c1200_identity2 :: Cube -> Bool
897 prop_c1200_identity2 cube =
898 c t0 1 2 0 0 ~= (c t0 1 1 1 0 + c t1 1 1 0 1) / 2
900 t0 = tetrahedron cube 0
901 t1 = tetrahedron cube 1
904 -- | Given in Sorokina and Zeilfelder, p. 79, (2.7). See
905 -- 'prop_c0102_identity1'.
906 prop_c2100_identity2 :: Cube -> Bool
907 prop_c2100_identity2 cube =
908 c t0 2 1 0 0 ~= (c t0 2 0 1 0 + c t1 2 0 0 1) / 2
910 t0 = tetrahedron cube 0
911 t1 = tetrahedron cube 1
914 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). The third and
915 -- fourth indices of c-t6 have been switched. This is because we
916 -- store the triangles oriented such that their volume is
917 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde
918 -- point in opposite directions, one of them has to have negative
920 prop_c3000_identity :: Cube -> Bool
921 prop_c3000_identity cube =
922 c t0 3 0 0 0 ~= c t0 2 1 0 0 + c t6 2 1 0 0
923 - ((c t0 2 0 1 0 + c t0 2 0 0 1)/ 2)
925 t0 = tetrahedron cube 0
926 t6 = tetrahedron cube 6
929 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
930 -- 'prop_c3000_identity'.
931 prop_c2010_identity :: Cube -> Bool
932 prop_c2010_identity cube =
933 c t0 2 0 1 0 ~= c t0 1 1 1 0 + c t6 1 1 0 1
934 - ((c t0 1 0 2 0 + c t0 1 0 1 1)/ 2)
936 t0 = tetrahedron cube 0
937 t6 = tetrahedron cube 6
940 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
941 -- 'prop_c3000_identity'.
942 prop_c2001_identity :: Cube -> Bool
943 prop_c2001_identity cube =
944 c t0 2 0 0 1 ~= c t0 1 1 0 1 + c t6 1 1 1 0
945 - ((c t0 1 0 0 2 + c t0 1 0 1 1)/ 2)
947 t0 = tetrahedron cube 0
948 t6 = tetrahedron cube 6
951 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
952 -- 'prop_c3000_identity'.
953 prop_c1020_identity :: Cube -> Bool
954 prop_c1020_identity cube =
955 c t0 1 0 2 0 ~= c t0 0 1 2 0 + c t6 0 1 0 2
956 - ((c t0 0 0 3 0 + c t0 0 0 2 1)/ 2)
958 t0 = tetrahedron cube 0
959 t6 = tetrahedron cube 6
962 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
963 -- 'prop_c3000_identity'.
964 prop_c1002_identity :: Cube -> Bool
965 prop_c1002_identity cube =
966 c t0 1 0 0 2 ~= c t0 0 1 0 2 + c t6 0 1 2 0
967 - ((c t0 0 0 0 3 + c t0 0 0 1 2)/ 2)
969 t0 = tetrahedron cube 0
970 t6 = tetrahedron cube 6
973 -- | Given in Sorokina and Zeilfelder, p. 79, (2.8). See
974 -- 'prop_c3000_identity'.
975 prop_c1011_identity :: Cube -> Bool
976 prop_c1011_identity cube =
977 c t0 1 0 1 1 ~= c t0 0 1 1 1 + c t6 0 1 1 1 -
978 ((c t0 0 0 1 2 + c t0 0 0 2 1)/ 2)
980 t0 = tetrahedron cube 0
981 t6 = tetrahedron cube 6
984 -- | The function values at the interior should be the same for all
986 prop_interior_values_all_identical :: Cube -> Bool
987 prop_interior_values_all_identical cube =
988 all_equal [ eval (function_values tet) I | tet <- tetrahedra cube ]
991 -- | We know what (c t6 2 1 0 0) should be from Sorokina and Zeilfelder, p. 87.
992 -- This test checks the rotation works as expected.
993 prop_c_tilde_2100_rotation_correct :: Cube -> Bool
994 prop_c_tilde_2100_rotation_correct cube =
997 t0 = tetrahedron cube 0
998 t6 = tetrahedron cube 6
1000 -- What gets computed for c2100 of t6.
1001 expr1 = eval (function_values t6) $
1003 (1/12)*(T + R + L + D) +
1004 (1/64)*(FT + FR + FL + FD) +
1007 (1/96)*(RT + LD + LT + RD) +
1008 (1/192)*(BT + BR + BL + BD)
1010 -- What should be computed for c2100 of t6.
1011 expr2 = eval (function_values t0) $
1013 (1/12)*(F + R + L + B) +
1014 (1/64)*(FT + RT + LT + BT) +
1017 (1/96)*(FR + FL + BR + BL) +
1018 (1/192)*(FD + RD + LD + BD)
1021 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
1022 -- Zeilfelder, p. 87. This test checks the actual value based on
1023 -- the FunctionValues of the cube.
1025 -- If 'prop_c_tilde_2100_rotation_correct' passes, then this test is
1027 prop_c_tilde_2100_correct :: Cube -> Bool
1028 prop_c_tilde_2100_correct cube =
1029 c t6 2 1 0 0 == expected
1031 t0 = tetrahedron cube 0
1032 t6 = tetrahedron cube 6
1033 fvs = function_values t0
1034 expected = eval fvs $
1036 (1/12)*(F + R + L + B) +
1037 (1/64)*(FT + RT + LT + BT) +
1040 (1/96)*(FR + FL + BR + BL) +
1041 (1/192)*(FD + RD + LD + BD)
1044 -- Tests to check that the correct edges are incidental.
1045 prop_t0_shares_edge_with_t1 :: Cube -> Bool
1046 prop_t0_shares_edge_with_t1 cube =
1047 (v1 t0) == (v1 t1) && (v3 t0) == (v2 t1)
1049 t0 = tetrahedron cube 0
1050 t1 = tetrahedron cube 1
1052 prop_t0_shares_edge_with_t3 :: Cube -> Bool
1053 prop_t0_shares_edge_with_t3 cube =
1054 (v1 t0) == (v1 t3) && (v2 t0) == (v3 t3)
1056 t0 = tetrahedron cube 0
1057 t3 = tetrahedron cube 3
1059 prop_t0_shares_edge_with_t6 :: Cube -> Bool
1060 prop_t0_shares_edge_with_t6 cube =
1061 (v2 t0) == (v3 t6) && (v3 t0) == (v2 t6)
1063 t0 = tetrahedron cube 0
1064 t6 = tetrahedron cube 6
1066 prop_t1_shares_edge_with_t2 :: Cube -> Bool
1067 prop_t1_shares_edge_with_t2 cube =
1068 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1070 t1 = tetrahedron cube 1
1071 t2 = tetrahedron cube 2
1073 prop_t1_shares_edge_with_t19 :: Cube -> Bool
1074 prop_t1_shares_edge_with_t19 cube =
1075 (v2 t1) == (v3 t19) && (v3 t1) == (v2 t19)
1077 t1 = tetrahedron cube 1
1078 t19 = tetrahedron cube 19
1080 prop_t2_shares_edge_with_t3 :: Cube -> Bool
1081 prop_t2_shares_edge_with_t3 cube =
1082 (v1 t1) == (v1 t2) && (v3 t1) == (v2 t2)
1084 t1 = tetrahedron cube 1
1085 t2 = tetrahedron cube 2
1087 prop_t2_shares_edge_with_t12 :: Cube -> Bool
1088 prop_t2_shares_edge_with_t12 cube =
1089 (v2 t2) == (v3 t12) && (v3 t2) == (v2 t12)
1091 t2 = tetrahedron cube 2
1092 t12 = tetrahedron cube 12
1094 prop_t3_shares_edge_with_t21 :: Cube -> Bool
1095 prop_t3_shares_edge_with_t21 cube =
1096 (v2 t3) == (v3 t21) && (v3 t3) == (v2 t21)
1098 t3 = tetrahedron cube 3
1099 t21 = tetrahedron cube 21
1101 prop_t4_shares_edge_with_t5 :: Cube -> Bool
1102 prop_t4_shares_edge_with_t5 cube =
1103 (v1 t4) == (v1 t5) && (v3 t4) == (v2 t5)
1105 t4 = tetrahedron cube 4
1106 t5 = tetrahedron cube 5
1108 prop_t4_shares_edge_with_t7 :: Cube -> Bool
1109 prop_t4_shares_edge_with_t7 cube =
1110 (v1 t4) == (v1 t7) && (v2 t4) == (v3 t7)
1112 t4 = tetrahedron cube 4
1113 t7 = tetrahedron cube 7
1115 prop_t4_shares_edge_with_t10 :: Cube -> Bool
1116 prop_t4_shares_edge_with_t10 cube =
1117 (v2 t4) == (v3 t10) && (v3 t4) == (v2 t10)
1119 t4 = tetrahedron cube 4
1120 t10 = tetrahedron cube 10
1122 prop_t5_shares_edge_with_t6 :: Cube -> Bool
1123 prop_t5_shares_edge_with_t6 cube =
1124 (v1 t5) == (v1 t6) && (v3 t5) == (v2 t6)
1126 t5 = tetrahedron cube 5
1127 t6 = tetrahedron cube 6
1129 prop_t5_shares_edge_with_t16 :: Cube -> Bool
1130 prop_t5_shares_edge_with_t16 cube =
1131 (v2 t5) == (v3 t16) && (v3 t5) == (v2 t16)
1133 t5 = tetrahedron cube 5
1134 t16 = tetrahedron cube 16
1136 prop_t6_shares_edge_with_t7 :: Cube -> Bool
1137 prop_t6_shares_edge_with_t7 cube =
1138 (v1 t6) == (v1 t7) && (v3 t6) == (v2 t7)
1140 t6 = tetrahedron cube 6
1141 t7 = tetrahedron cube 7
1143 prop_t7_shares_edge_with_t20 :: Cube -> Bool
1144 prop_t7_shares_edge_with_t20 cube =
1145 (v2 t7) == (v3 t20) && (v2 t7) == (v3 t20)
1147 t7 = tetrahedron cube 7
1148 t20 = tetrahedron cube 20
1151 p79_26_properties :: Test.Framework.Test
1153 testGroup "p. 79, Section (2.6) Properties" [
1154 testProperty "c0120 identity1" prop_c0120_identity1,
1155 testProperty "c0120 identity2" prop_c0120_identity2,
1156 testProperty "c0120 identity3" prop_c0120_identity3,
1157 testProperty "c0120 identity4" prop_c0120_identity4,
1158 testProperty "c0120 identity5" prop_c0120_identity5,
1159 testProperty "c0120 identity6" prop_c0120_identity6,
1160 testProperty "c0120 identity7" prop_c0120_identity7,
1161 testProperty "c0210 identity1" prop_c0210_identity1,
1162 testProperty "c0300 identity1" prop_c0300_identity1,
1163 testProperty "c1110 identity" prop_c1110_identity,
1164 testProperty "c1200 identity1" prop_c1200_identity1,
1165 testProperty "c2100 identity1" prop_c2100_identity1]
1167 p79_27_properties :: Test.Framework.Test
1169 testGroup "p. 79, Section (2.7) Properties" [
1170 testProperty "c0102 identity1" prop_c0102_identity1,
1171 testProperty "c0201 identity1" prop_c0201_identity1,
1172 testProperty "c0300 identity2" prop_c0300_identity2,
1173 testProperty "c1101 identity" prop_c1101_identity,
1174 testProperty "c1200 identity2" prop_c1200_identity2,
1175 testProperty "c2100 identity2" prop_c2100_identity2 ]
1178 p79_28_properties :: Test.Framework.Test
1180 testGroup "p. 79, Section (2.8) Properties" [
1181 testProperty "c3000 identity" prop_c3000_identity,
1182 testProperty "c2010 identity" prop_c2010_identity,
1183 testProperty "c2001 identity" prop_c2001_identity,
1184 testProperty "c1020 identity" prop_c1020_identity,
1185 testProperty "c1002 identity" prop_c1002_identity,
1186 testProperty "c1011 identity" prop_c1011_identity ]
1189 edge_incidence_tests :: Test.Framework.Test
1190 edge_incidence_tests =
1191 testGroup "Edge Incidence Tests" [
1192 testProperty "t0 shares edge with t6" prop_t0_shares_edge_with_t6,
1193 testProperty "t0 shares edge with t1" prop_t0_shares_edge_with_t1,
1194 testProperty "t0 shares edge with t3" prop_t0_shares_edge_with_t3,
1195 testProperty "t1 shares edge with t2" prop_t1_shares_edge_with_t2,
1196 testProperty "t1 shares edge with t19" prop_t1_shares_edge_with_t19,
1197 testProperty "t2 shares edge with t3" prop_t2_shares_edge_with_t3,
1198 testProperty "t2 shares edge with t12" prop_t2_shares_edge_with_t12,
1199 testProperty "t3 shares edge with t21" prop_t3_shares_edge_with_t21,
1200 testProperty "t4 shares edge with t5" prop_t4_shares_edge_with_t5,
1201 testProperty "t4 shares edge with t7" prop_t4_shares_edge_with_t7,
1202 testProperty "t4 shares edge with t10" prop_t4_shares_edge_with_t10,
1203 testProperty "t5 shares edge with t6" prop_t5_shares_edge_with_t6,
1204 testProperty "t5 shares edge with t16" prop_t5_shares_edge_with_t16,
1205 testProperty "t6 shares edge with t7" prop_t6_shares_edge_with_t7,
1206 testProperty "t7 shares edge with t20" prop_t7_shares_edge_with_t20 ]
1208 cube_properties :: Test.Framework.Test
1210 testGroup "Cube Properties" [
1214 edge_incidence_tests,
1215 testProperty "opposite octant tetrahedra are disjoint (1)"
1216 prop_opposite_octant_tetrahedra_disjoint1,
1217 testProperty "opposite octant tetrahedra are disjoint (2)"
1218 prop_opposite_octant_tetrahedra_disjoint2,
1219 testProperty "opposite octant tetrahedra are disjoint (3)"
1220 prop_opposite_octant_tetrahedra_disjoint3,
1221 testProperty "opposite octant tetrahedra are disjoint (4)"
1222 prop_opposite_octant_tetrahedra_disjoint4,
1223 testProperty "opposite octant tetrahedra are disjoint (5)"
1224 prop_opposite_octant_tetrahedra_disjoint5,
1225 testProperty "opposite octant tetrahedra are disjoint (6)"
1226 prop_opposite_octant_tetrahedra_disjoint6,
1227 testProperty "all volumes positive" prop_all_volumes_positive,
1228 testProperty "all volumes exact" prop_all_volumes_exact,
1229 testProperty "v0 all equal" prop_v0_all_equal,
1230 testProperty "interior values all identical"
1231 prop_interior_values_all_identical,
1232 testProperty "c-tilde_2100 rotation correct"
1233 prop_c_tilde_2100_rotation_correct,
1234 testProperty "c-tilde_2100 correct"
1235 prop_c_tilde_2100_correct ]