]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/Grid.hs
One-line cleanup.
[spline3.git] / src / Grid.hs
index 2cf56ba3f437461e2112dd9f2d5c6db206a2f6fb..e4f3d62b9a661df068ec80e837fc9d7289734ea4 100644 (file)
@@ -2,6 +2,7 @@
 --   for it. We hide the main Grid constructor because we don't want
 --   to allow instantiation of a grid with h <= 0.
 module Grid (
+  cube_at,
   grid_tests,
   make_grid,
   slow_tests,
@@ -22,13 +23,12 @@ import Comparisons
 import Cube (Cube(Cube),
              find_containing_tetrahedron,
              tetrahedra,
-             tetrahedron0,
-             tetrahedron15)
+             tetrahedron)
 import Examples
 import FunctionValues
 import Point (Point)
 import ScaleFactor
-import Tetrahedron (c, polynomial, v0, v1, v2, v3)
+import Tetrahedron (Tetrahedron, c, polynomial, v0, v1, v2, v3)
 import ThreeDimensional
 import Values (Values3D, dims, empty3d, zoom_shape)
 
@@ -71,8 +71,9 @@ cubes delta fvs
                    j <- [0..ymax],
                    k <- [0..zmax],
                    let tet_vol = (1/24)*(delta^(3::Int)),
+                   let fvs' = make_values fvs i j k,
                    let cube_ijk =
-                         Cube delta i j k (make_values fvs i j k) tet_vol]
+                         Cube delta i j k fvs' tet_vol]
      where
        xmax = xsize - 1
        ymax = ysize - 1
@@ -133,29 +134,29 @@ find_containing_cube g p =
 
 {-# INLINE zoom_lookup #-}
 zoom_lookup :: Grid -> ScaleFactor -> a -> (R.DIM3 -> Double)
-zoom_lookup g scale_factor _ = zoom_result g scale_factor
+zoom_lookup g scale_factor _ =
+    zoom_result g scale_factor
 
 
 {-# INLINE zoom_result #-}
 zoom_result :: Grid -> ScaleFactor -> R.DIM3 -> Double
-zoom_result g (sfx, sfy, sfz) (R.Z R.:. i R.:. j R.:. k) =
+zoom_result g (sfx, sfy, sfz) (R.Z R.:. m R.:. n R.:. o) =
   f p
   where
     offset = (h g)/2
-    i' = (fromIntegral i) / (fromIntegral sfx) - offset
-    j' = (fromIntegral j) / (fromIntegral sfy) - offset
-    k' = (fromIntegral k) / (fromIntegral sfz) - offset
-    p  = (i', j', k') :: Point
+    m' = (fromIntegral m) / (fromIntegral sfx) - offset
+    n' = (fromIntegral n) / (fromIntegral sfy) - offset
+    o' = (fromIntegral o) / (fromIntegral sfz) - offset
+    p  = (m', n', o') :: Point
     cube = find_containing_cube g p
     t = find_containing_tetrahedron cube p
     f = polynomial t
-
-
+    
 zoom :: Grid -> ScaleFactor -> Values3D
 zoom g scale_factor
     | xsize == 0 || ysize == 0 || zsize == 0 = empty3d
     | otherwise =
-        R.force $ R.traverse arr transExtent (zoom_lookup g scale_factor)
+        R.force $ R.unsafeTraverse arr transExtent (zoom_lookup g scale_factor)
           where
             arr = function_values g
             (xsize, ysize, zsize) = dims arr
@@ -205,7 +206,7 @@ trilinear_c0_t0_tests =
   where
     g = make_grid 1 trilinear
     cube = cube_at g 1 1 1
-    t = tetrahedron0 cube
+    t = tetrahedron cube 0
 
     test_trilinear_c0030 :: Assertion
     test_trilinear_c0030 =
@@ -334,7 +335,7 @@ test_zeros_reproduced =
     where
       g = make_grid 1 zeros
       c0 = cube_at g 1 1 1
-      t0 = tetrahedron0 c0
+      t0 = tetrahedron c0 0
       p = polynomial t0
 
 
@@ -362,18 +363,18 @@ test_trilinear9x9x9_reproduced =
 --
 --   Example from before the fix:
 --
---   > b0 (tetrahedron15 c) p
---   -3.4694469519536365e-18
+--   b1 (tetrahedron c 20) (0, 17.5, 0.5)
+--   -0.0
 --
 test_tetrahedra_collision_sensitivity :: Assertion
 test_tetrahedra_collision_sensitivity =
   assertTrue "tetrahedron collision tests isn't too sensitive" $
-             contains_point t15 p
+             contains_point t20 p
   where
     g = make_grid 1 naturals_1d
-    cube = cube_at g 0 17 1
-    p = (0, 16.75, 0.5) :: Point
-    t15 = tetrahedron15 cube
+    cube = cube_at g 0 18 0
+    p = (0, 17.5, 0.5) :: Point
+    t20 = tetrahedron cube 20
 
 
 prop_cube_indices_never_go_out_of_bounds :: Grid -> Gen Bool