]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/Grid.hs
spline3.cabal: bump version to 1.0.2
[spline3.git] / src / Grid.hs
index f9a59729554a9f12d72d9e384f332e024e858bdc..d98bda1d0ce0e602bee9796c245dd10666d74176 100644 (file)
@@ -19,7 +19,7 @@ import Data.Array.Repa.Operators.Traversal ( unsafeTraverse )
 import Test.Tasty ( TestTree, testGroup )
 import Test.Tasty.HUnit ( Assertion, assertEqual, testCase )
 import Test.Tasty.QuickCheck (
-  Arbitrary(..),
+  Arbitrary( arbitrary ),
   Gen,
   Property,
   (==>),
@@ -36,7 +36,7 @@ import Cube (
   tetrahedron )
 import Examples ( trilinear, trilinear9x9x9, zeros )
 import FunctionValues ( make_values, value_at )
-import Point ( Point(..) )
+import Point ( Point(Point) )
 import ScaleFactor ( ScaleFactor )
 import Tetrahedron (
   Tetrahedron( v0, v1, v2, v3 ),
@@ -51,8 +51,8 @@ import Values ( Values3D, dims, empty3d, zoom_shape )
 --   values of the function at the grid points, which are distance h=1
 --   from one another in each direction (x,y,z).
 --
-data Grid = Grid { function_values :: Values3D }
-          deriving (Show)
+newtype Grid = Grid { function_values :: Values3D }
+                 deriving (Show)
 
 
 instance Arbitrary Grid where
@@ -77,7 +77,7 @@ cube_at !g !i !j !k =
    where
      fvs = function_values g
      fvs' = make_values fvs i j k
-     tet_vol = 1/24
+     tet_vol = (1 / 24) :: Double
 
 
 --   The first cube along any axis covers (-1/2, 1/2). The second
@@ -96,7 +96,7 @@ calculate_containing_cube_coordinate g coord
     | otherwise = (ceiling (coord + offset)) - 1
     where
       (xsize, ysize, zsize) = dims (function_values g)
-      offset = 1/2
+      offset = (1 / 2) :: Double
 
 
 -- | Takes a 'Grid', and returns a 'Cube' containing the given 'Point'.
@@ -121,7 +121,7 @@ zoom_result v3d (sfx, sfy, sfz) (Z :. m :. n :. o) =
   f p
   where
     g = Grid v3d
-    offset = 1/2
+    offset = (1 / 2) :: Double
     m' = (fromIntegral m) / (fromIntegral sfx) - offset
     n' = (fromIntegral n) / (fromIntegral sfy) - offset
     o' = (fromIntegral o) / (fromIntegral sfz) - offset
@@ -143,7 +143,7 @@ zoom v3d scale_factor
         where
           (xsize, ysize, zsize) = dims v3d
           transExtent = zoom_shape scale_factor
-          f = zoom_lookup v3d scale_factor
+          f = zoom_lookup v3d scale_factor :: (DIM3 -> Double) -> DIM3 -> Double
 
 
 -- | Check all coefficients of tetrahedron0 belonging to the cube
@@ -191,63 +191,63 @@ trilinear_c0_t0_tests =
 
     test_trilinear_c0030 :: Assertion
     test_trilinear_c0030 =
-      assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
+      assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17 / 8)
 
     test_trilinear_c0003 :: Assertion
     test_trilinear_c0003 =
-      assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
+      assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27 / 8)
 
     test_trilinear_c0021 :: Assertion
     test_trilinear_c0021 =
-      assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
+      assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61 / 24)
 
     test_trilinear_c0012 :: Assertion
     test_trilinear_c0012 =
-      assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
+      assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71 / 24)
 
     test_trilinear_c0120 :: Assertion
     test_trilinear_c0120 =
-      assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
+      assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55 / 24)
 
     test_trilinear_c0102 :: Assertion
     test_trilinear_c0102 =
-      assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
+      assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73 / 24)
 
     test_trilinear_c0111 :: Assertion
     test_trilinear_c0111 =
-      assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
+      assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8 / 3)
 
     test_trilinear_c0210 :: Assertion
     test_trilinear_c0210 =
-      assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
+      assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29 / 12)
 
     test_trilinear_c0201 :: Assertion
     test_trilinear_c0201 =
-      assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
+      assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11 / 4)
 
     test_trilinear_c0300 :: Assertion
     test_trilinear_c0300 =
-      assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
+      assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5 / 2)
 
     test_trilinear_c1020 :: Assertion
     test_trilinear_c1020 =
-      assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
+      assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8 / 3)
 
     test_trilinear_c1002 :: Assertion
     test_trilinear_c1002 =
-      assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
+      assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23 / 6)
 
     test_trilinear_c1011 :: Assertion
     test_trilinear_c1011 =
-      assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
+      assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13 / 4)
 
     test_trilinear_c1110 :: Assertion
     test_trilinear_c1110 =
-      assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
+      assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23 / 8)
 
     test_trilinear_c1101 :: Assertion
     test_trilinear_c1101 =
-      assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
+      assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27 / 8)
 
     test_trilinear_c1200 :: Assertion
     test_trilinear_c1200 =
@@ -255,7 +255,7 @@ trilinear_c0_t0_tests =
 
     test_trilinear_c2010 :: Assertion
     test_trilinear_c2010 =
-      assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
+      assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10 / 3)
 
     test_trilinear_c2001 :: Assertion
     test_trilinear_c2001 =
@@ -263,7 +263,7 @@ trilinear_c0_t0_tests =
 
     test_trilinear_c2100 :: Assertion
     test_trilinear_c2100 =
-      assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
+      assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7 / 2)
 
     test_trilinear_c3000 :: Assertion
     test_trilinear_c3000 =
@@ -296,9 +296,9 @@ test_trilinear_reproduced =
                       c0 <- cs,
                       t <- tetrahedra c0,
                       let p = polynomial t,
-                      let i' = fromIntegral i,
-                      let j' = fromIntegral j,
-                      let k' = fromIntegral k]
+                      let i' = fromIntegral i :: Double,
+                      let j' = fromIntegral j :: Double,
+                      let k' = fromIntegral k :: Double]
     where
       g = Grid trilinear
       cs = [ cube_at g ci cj ck | ci <- [0..2], cj <- [0..2], ck <- [0..2] ]
@@ -311,9 +311,9 @@ test_zeros_reproduced =
                     | i <- [0..2],
                       j <- [0..2],
                       k <- [0..2],
-                      let i' = fromIntegral i,
-                      let j' = fromIntegral j,
-                      let k' = fromIntegral k,
+                      let i' = fromIntegral i :: Double,
+                      let j' = fromIntegral j :: Double,
+                      let k' = fromIntegral k :: Double,
                       c0 <- cs,
                       t0 <- tetrahedra c0,
                       let p = polynomial t0 ]
@@ -332,9 +332,9 @@ test_trilinear9x9x9_reproduced =
               k <- [0..8],
               t <- tetrahedra c0,
               let p = polynomial t,
-              let i' = (fromIntegral i) * 0.5,
-              let j' = (fromIntegral j) * 0.5,
-              let k' = (fromIntegral k) * 0.5]
+              let i' = (fromIntegral i) * 0.5 :: Double,
+              let j' = (fromIntegral j) * 0.5 :: Double,
+              let k' = (fromIntegral k) * 0.5 :: Double]
     where
       g = Grid trilinear
       c0 = cube_at g 1 1 1
@@ -344,12 +344,12 @@ test_trilinear9x9x9_reproduced =
 prop_cube_indices_never_go_out_of_bounds :: Grid -> Gen Bool
 prop_cube_indices_never_go_out_of_bounds g =
   do
-    let coordmin = negate (1/2)
+    let coordmin = negate (1 / 2) :: Double
 
     let (xsize, ysize, zsize) = dims $ function_values g
-    let xmax = (fromIntegral xsize) - (1/2)
-    let ymax = (fromIntegral ysize) - (1/2)
-    let zmax = (fromIntegral zsize) - (1/2)
+    let xmax = (fromIntegral xsize) - (1 / 2) :: Double
+    let ymax = (fromIntegral ysize) - (1 / 2) :: Double
+    let zmax = (fromIntegral zsize) - (1 / 2) :: Double
 
     x <- choose (coordmin, xmax)
     y <- choose (coordmin, ymax)