]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/Cube.hs
Finish the precomputed_volume optimization.
[spline3.git] / src / Cube.hs
index 1e83a3e690d4a6b0f39cdc0b0025526650aa81db..ef2d9ce67ab29e52deae2928605951a1c3904185 100644 (file)
@@ -15,7 +15,8 @@ data Cube = Cube { h :: Double,
                    i :: Int,
                    j :: Int,
                    k :: Int,
-                   fv :: FunctionValues }
+                   fv :: FunctionValues,
+                   tetrahedra_volume :: Double }
             deriving (Eq)
 
 
@@ -26,7 +27,8 @@ instance Arbitrary Cube where
       j' <- choose (coordmin, coordmax)
       k' <- choose (coordmin, coordmax)
       fv' <- arbitrary :: Gen FunctionValues
-      return (Cube h' i' j' k' fv')
+      (Positive tet_vol) <- arbitrary :: Gen (Positive Double)
+      return (Cube h' i' j' k' fv' tet_vol)
         where
           coordmin = -268435456 -- -(2^29 / 2)
           coordmax = 268435456  -- +(2^29 / 2)
@@ -51,7 +53,7 @@ instance Show Cube where
 
 -- | Returns an empty 'Cube'.
 empty_cube :: Cube
-empty_cube = Cube 0 0 0 0 empty_values
+empty_cube = Cube 0 0 0 0 empty_values 0
 
 
 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
@@ -205,7 +207,7 @@ tetrahedron0 c =
       v1' = center (front_face c)
       v2' = Face.v0 (front_face c)
       v3' = Face.v1 (front_face c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron1 :: Cube -> Tetrahedron
 tetrahedron1 c =
@@ -216,7 +218,7 @@ tetrahedron1 c =
       v2' = Face.v1 (front_face c)
       v3' = Face.v2 (front_face c)
       fv' = rotate ccwx (Cube.fv c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron2 :: Cube -> Tetrahedron
 tetrahedron2 c =
@@ -227,7 +229,7 @@ tetrahedron2 c =
       v2' = Face.v2 (front_face c)
       v3' = Face.v3 (front_face c)
       fv' = rotate ccwx $ rotate ccwx $ Cube.fv c
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron3 :: Cube -> Tetrahedron
 tetrahedron3 c =
@@ -238,7 +240,7 @@ tetrahedron3 c =
       v2' = Face.v3 (front_face c)
       v3' = Face.v0 (front_face c)
       fv' = rotate cwx (Cube.fv c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron4 :: Cube -> Tetrahedron
 tetrahedron4 c =
@@ -249,7 +251,7 @@ tetrahedron4 c =
       v2' = Face.v0 (top_face c)
       v3' = Face.v1 (top_face c)
       fv' = rotate cwy (Cube.fv c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron5 :: Cube -> Tetrahedron
 tetrahedron5 c =
@@ -260,7 +262,7 @@ tetrahedron5 c =
       v2' = Face.v1 (top_face c)
       v3' = Face.v2 (top_face c)
       fv' = rotate cwy $ rotate cwz $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron6 :: Cube -> Tetrahedron
 tetrahedron6 c =
@@ -273,7 +275,7 @@ tetrahedron6 c =
       fv' = rotate cwy $ rotate cwz
                        $ rotate cwz
                        $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron7 :: Cube -> Tetrahedron
 tetrahedron7 c =
@@ -284,7 +286,7 @@ tetrahedron7 c =
       v2' = Face.v3 (top_face c)
       v3' = Face.v0 (top_face c)
       fv' = rotate cwy $ rotate ccwz $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron8 :: Cube -> Tetrahedron
 tetrahedron8 c =
@@ -295,7 +297,7 @@ tetrahedron8 c =
       v2' = Face.v0 (back_face c)
       v3' = Face.v1 (back_face c)
       fv' = rotate cwy $ rotate cwy $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron9 :: Cube -> Tetrahedron
 tetrahedron9 c =
@@ -308,7 +310,7 @@ tetrahedron9 c =
       fv' = rotate cwy $ rotate cwy
                        $ rotate cwx
                        $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron10 :: Cube -> Tetrahedron
 tetrahedron10 c =
@@ -323,7 +325,7 @@ tetrahedron10 c =
                        $ rotate cwx
                        $ Tetrahedron.fv (tetrahedron0 c)
 
-      vol = 0
+      vol = tetrahedra_volume c
 
 tetrahedron11 :: Cube -> Tetrahedron
 tetrahedron11 c =
@@ -336,7 +338,7 @@ tetrahedron11 c =
       fv' = rotate cwy $ rotate cwy
                        $ rotate ccwx
                        $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron12 :: Cube -> Tetrahedron
@@ -348,7 +350,7 @@ tetrahedron12 c =
       v2' = Face.v0 (down_face c)
       v3' = Face.v1 (down_face c)
       fv' = rotate ccwy (Tetrahedron.fv (tetrahedron0 c))
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron13 :: Cube -> Tetrahedron
@@ -360,7 +362,7 @@ tetrahedron13 c =
       v2' = Face.v1 (down_face c)
       v3' = Face.v2 (down_face c)
       fv' = rotate ccwy $ rotate ccwz $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron14 :: Cube -> Tetrahedron
@@ -374,7 +376,7 @@ tetrahedron14 c =
       fv' = rotate ccwy $ rotate ccwz
                         $ rotate ccwz
                         $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron15 :: Cube -> Tetrahedron
@@ -386,7 +388,7 @@ tetrahedron15 c =
       v2' = Face.v3 (down_face c)
       v3' = Face.v0 (down_face c)
       fv' = rotate ccwy $ rotate cwz $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron16 :: Cube -> Tetrahedron
@@ -398,7 +400,7 @@ tetrahedron16 c =
       v2' = Face.v0 (right_face c)
       v3' = Face.v1 (right_face c)
       fv' = rotate ccwz (Tetrahedron.fv (tetrahedron0 c))
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron17 :: Cube -> Tetrahedron
@@ -410,7 +412,7 @@ tetrahedron17 c =
       v2' = Face.v1 (right_face c)
       v3' = Face.v2 (right_face c)
       fv' = rotate ccwz $ rotate cwy $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron18 :: Cube -> Tetrahedron
@@ -424,7 +426,7 @@ tetrahedron18 c =
       fv' = rotate ccwz $ rotate cwy
                         $ rotate cwy
                         $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron19 :: Cube -> Tetrahedron
@@ -437,7 +439,7 @@ tetrahedron19 c =
       v3' = Face.v0 (right_face c)
       fv' = rotate ccwz $ rotate ccwy
                         $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron20 :: Cube -> Tetrahedron
@@ -449,7 +451,7 @@ tetrahedron20 c =
       v2' = Face.v0 (left_face c)
       v3' = Face.v1 (left_face c)
       fv' = rotate cwz (Tetrahedron.fv (tetrahedron0 c))
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron21 :: Cube -> Tetrahedron
@@ -461,7 +463,7 @@ tetrahedron21 c =
       v2' = Face.v1 (left_face c)
       v3' = Face.v2 (left_face c)
       fv' = rotate cwz $ rotate ccwy $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron22 :: Cube -> Tetrahedron
@@ -475,7 +477,7 @@ tetrahedron22 c =
       fv' = rotate cwz $ rotate ccwy
                        $ rotate ccwy
                        $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedron23 :: Cube -> Tetrahedron
@@ -488,7 +490,7 @@ tetrahedron23 c =
       v3' = Face.v0 (left_face c)
       fv' = rotate cwz $ rotate cwy
                        $ Tetrahedron.fv (tetrahedron0 c)
-      vol = 0
+      vol = tetrahedra_volume c
 
 
 tetrahedra :: Cube -> [Tetrahedron]