]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/Cube.hs
Eta reduce the reverse_cube function.
[spline3.git] / src / Cube.hs
index d0276c8277062ee3c0a360e6a228dbb32bd1b40d..d741f490c6e7499a309b991c0e5d3ba0a9c6cd55 100644 (file)
@@ -105,9 +105,9 @@ instance ThreeDimensional Cube where
              i' = fromIntegral (i c) :: Double
              j' = fromIntegral (j c) :: Double
              k' = fromIntegral (k c) :: Double
-             x = (delta * i')
-             y = (delta * j')
-             z = (delta * k')
+             x = delta * i'
+             y = delta * j'
+             z = delta * k'
 
     contains_point c p
         | (x_coord p) < (xmin c) = False
@@ -146,8 +146,9 @@ instance Fractional Cube where
 
     fromRational q = empty_cube { datum = fromRational q }
 
+-- | Constructs a cube, switching the i and k axes.
 reverse_cube :: Grid -> Int -> Int -> Int -> Double -> Cube
-reverse_cube g k' j' i' datum' = Cube g i' j' k' datum'
+reverse_cube g k' j' i' = Cube g i' j' k'
 
 
 cube_at :: Grid -> Int -> Int -> Int -> Cube
@@ -163,13 +164,24 @@ cube_at g i' j' k'
 
 -- These next three functions basically form a 'for' loop, looping
 -- through the xs, ys, and zs in that order.
-cubes_from_values :: Grid -> Int -> Int -> [Double] -> [Cube]
-cubes_from_values g i' j' vals =
-    zipWith (reverse_cube g i' j') [0..] vals
-
-cubes_from_planes :: Grid -> Int -> [[Double]] -> [[Cube]]
-cubes_from_planes g i' planes =
-    zipWith (cubes_from_values g i') [0..] planes
 
+-- | The cubes_from_values function will return a function that takes
+--   a list of values and returns a list of cubes. It could just as
+--   well be written to take the values as a parameter; the omission
+--   of the last parameter is known as an eta reduce.
+cubes_from_values :: Grid -> Int -> Int -> ([Double] -> [Cube])
+cubes_from_values g i' j' =
+    zipWith (reverse_cube g i' j') [0..]
+
+-- | The cubes_from_planes function will return a function that takes
+--   a list of planes and returns a list of cubes. It could just as
+--   well be written to take the planes as a parameter; the omission
+--   of the last parameter is known as an eta reduce.
+cubes_from_planes :: Grid -> Int -> ([[Double]] -> [[Cube]])
+cubes_from_planes g i' =
+    zipWith (cubes_from_values g i') [0..]
+
+-- | Takes a grid as an argument, and returns a three-dimensional list
+--   of cubes centered on its grid points.
 cubes :: Grid -> [[[Cube]]]
 cubes g = zipWith (cubes_from_planes g) [0..] (function_values g)