-- | The FunctionValues module contains the 'FunctionValues' type and
-- the functions used to manipulate it.
-module FunctionValues
+module FunctionValues (
+ FunctionValues,
+ empty_values,
+ eval,
+ make_values,
+ rotate,
+ function_values_tests,
+ value_at
+ )
where
import Prelude hiding (LT)
+import Test.HUnit
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.HUnit (testCase)
import Test.QuickCheck (Arbitrary(..), choose)
-import Cardinal
+import Assertions (assertTrue)
+import Cardinal ( Cardinal(..) )
+import Examples (trilinear)
import Values (Values3D, dims, idx)
-- | The FunctionValues type represents the value of our function f at
-- | 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
back_right_down = eval fv (rotation BRD),
back_right_top = eval fv (rotation BRT),
interior = interior fv }
+
+
+
+-- | Ensure that the trilinear values wind up where we think they
+-- should.
+test_directions :: Assertion
+test_directions =
+ assertTrue "all direction functions work" (and equalities)
+ where
+ fvs = make_values trilinear 1 1 1
+ equalities = [ interior fvs == 4,
+ front fvs == 1,
+ back fvs == 7,
+ left fvs == 2,
+ right fvs == 6,
+ down fvs == 3,
+ top fvs == 5,
+ front_left fvs == 1,
+ front_right fvs == 1,
+ front_down fvs == 1,
+ front_top fvs == 1,
+ back_left fvs == 3,
+ back_right fvs == 11,
+ back_down fvs == 5,
+ back_top fvs == 9,
+ left_down fvs == 2,
+ left_top fvs == 2,
+ right_down fvs == 4,
+ right_top fvs == 8,
+ front_left_down fvs == 1,
+ front_left_top fvs == 1,
+ front_right_down fvs == 1,
+ front_right_top fvs == 1,
+ back_left_down fvs == 3,
+ back_left_top fvs == 3,
+ back_right_down fvs == 7,
+ back_right_top fvs == 15]
+
+
+function_values_tests :: Test.Framework.Test
+function_values_tests =
+ testGroup "FunctionValues Tests"
+ [ testCase "test directions" test_directions ]