X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FFunctionValues.hs;h=895f9253a42506398c5594a3bd8b864baa32099a;hb=b2e1c440b9b1bb99ae564d6600230bbd1f7d204c;hp=1d722b12b0f3132d028cbf53d01a9e584be977dd;hpb=883ce9d78072c492000de94478189095032b6615;p=spline3.git diff --git a/src/FunctionValues.hs b/src/FunctionValues.hs index 1d722b1..895f925 100644 --- a/src/FunctionValues.hs +++ b/src/FunctionValues.hs @@ -162,18 +162,34 @@ 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. +-- supplied list. If there is no such value, we choose a nearby +-- point and use its value. +-- +-- Examples: +-- +-- >>> value_at Examples.trilinear 0 0 0 +-- 1.0 +-- +-- >>> value_at Examples.trilinear (-1) 0 0 +-- 1.0 +-- +-- >>> value_at Examples.trilinear 0 0 4 +-- 1.0 +-- +-- >>> value_at Examples.trilinear 1 3 0 +-- 4.0 +-- value_at :: Values3D -> Int -> Int -> Int -> Double -value_at values i j k - | i < 0 = 0 - | j < 0 = 0 - | k < 0 = 0 - | xsize <= i = 0 - | ysize <= j = 0 - | zsize <= k = 0 - | otherwise = idx values i j k +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 - 1) j k + | ysize <= j = value_at v3d i (ysize - 1) k + | zsize <= k = value_at v3d i j (zsize - 1) + | otherwise = idx v3d i j k where - (xsize, ysize, zsize) = dims values + (xsize, ysize, zsize) = dims v3d -- | Given a three-dimensional list of 'Double' and a set of 3D