From: Michael Orlitzky Date: Fri, 26 Aug 2011 14:30:38 +0000 (-0400) Subject: Correct an error in the value_at function. X-Git-Tag: 0.0.1~217 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=7cb11540c2b74991a117ee0b30b878b4411acb67;p=spline3.git Correct an error in the value_at function. Add some doctests for the value_at function. --- diff --git a/src/FunctionValues.hs b/src/FunctionValues.hs index 8eb5bdb..895f925 100644 --- a/src/FunctionValues.hs +++ b/src/FunctionValues.hs @@ -164,14 +164,29 @@ eval f (Quotient x y) = (eval f x) / (eval f y) -- coordinates (i,j,k), and returns the value at (i,j,k) in the -- 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 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 + | 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 v3d