X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FFunctionValues.hs;h=8eb5bdb0d375ffdfe72eabb81097cc99c121e563;hb=178804214397f6bc04370192aa3006b93d6fa0ef;hp=1fbc044909d4ba28de0b74fcc1c494e754a6829d;hpb=ecb77f944fcba8c8cfe60ca782bc5d9c8ab68cf9;p=spline3.git diff --git a/src/FunctionValues.hs b/src/FunctionValues.hs index 1fbc044..8eb5bdb 100644 --- a/src/FunctionValues.hs +++ b/src/FunctionValues.hs @@ -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 @@ -161,22 +162,25 @@ 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 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 +-- supplied list. If there is no such value, we choose a nearby +-- point and use its value. +value_at :: Values3D -> Int -> Int -> Int -> Double +value_at v3d i j k + | i < 0 = value_at v3d 0 j k + | j < 0 = value_at v3d i 0 k + | k < 0 = value_at v3d i j 0 + | xsize <= i = value_at v3d xsize j k + | ysize <= j = value_at v3d i ysize k + | zsize <= k = value_at v3d i j zsize + | otherwise = idx v3d i j k + where + (xsize, ysize, zsize) = dims v3d -- | 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,