-- 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