]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/FunctionValues.hs
Begin updating everything to use Repa arrays (Values3D).
[spline3.git] / src / FunctionValues.hs
index 1fbc044909d4ba28de0b74fcc1c494e754a6829d..1d722b12b0f3132d028cbf53d01a9e584be977dd 100644 (file)
@@ -7,6 +7,7 @@ import Prelude hiding (LT)
 import Test.QuickCheck (Arbitrary(..), choose)
 
 import Cardinal
+import Values (Values3D, dims, idx)
 
 -- | The FunctionValues type represents the value of our function f at
 --   the 27 points surrounding (and including) the center of a
@@ -162,21 +163,23 @@ eval f (Quotient x y) = (eval f x) / (eval f y)
 -- | Takes a three-dimensional list of 'Double' and a set of 3D
 --   coordinates (i,j,k), and returns the value at (i,j,k) in the
 --   supplied list. If there is no such value, zero is returned.
-value_at :: [[[Double]]] -> Int -> Int -> Int -> Double
+value_at :: Values3D -> Int -> Int -> Int -> Double
 value_at values i j k
          | i < 0 = 0
          | j < 0 = 0
          | k < 0 = 0
-         | length values <= k = 0
-         | length (values !! k) <= j = 0
-         | length ((values !! k) !! j) <= i = 0
-         | otherwise = ((values !! k) !! j) !! i
+         | xsize <= i = 0
+         | ysize <= j = 0
+         | zsize <= k = 0
+         | otherwise = idx values i j k
+  where
+    (xsize, ysize, zsize) = dims values
 
 
 -- | Given a three-dimensional list of 'Double' and a set of 3D
 --   coordinates (i,j,k), constructs and returns the 'FunctionValues'
 --   object centered at (i,j,k)
-make_values :: [[[Double]]] -> Int -> Int -> Int -> FunctionValues
+make_values :: Values3D -> Int -> Int -> Int -> FunctionValues
 make_values values i j k =
     empty_values { front  = value_at values (i-1) j k,
                    back   = value_at values (i+1) j k,