]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Values.hs
Bump dependencies, and move some Arbitrary code from Values.hs to Grid.hs to avoid...
[spline3.git] / src / Values.hs
1 {-# LANGUAGE FlexibleInstances #-}
2
3 module Values (
4 Values,
5 Values2D,
6 Values3D,
7 dims,
8 empty3d,
9 idx,
10 zoom_shape
11 )
12 where
13
14 import Data.Array.Repa (
15 Array, U,
16 Z(..),
17 (:.)(..),
18 DIM2,
19 DIM3,
20 extent,
21 fromListUnboxed,
22 unsafeIndex,
23 )
24
25 import System.FilePath ()
26
27 import ScaleFactor (ScaleFactor)
28
29
30 type Values sh = Array U sh Double
31 type Values2D = Values DIM2
32 type Values3D = Values DIM3
33
34
35 empty3d :: Values3D
36 empty3d = Data.Array.Repa.fromListUnboxed (Z :. 0 :. 0 :. 0) []
37
38
39 dims :: Values3D -> (Int, Int, Int)
40 dims v3d =
41 let (Z :. x :. y :. z) = extent v3d
42 in
43 (x,y,z)
44
45
46 idx :: Values3D -> Int -> Int -> Int -> Double
47 idx v3d i j k =
48 unsafeIndex v3d shape
49 where
50 shape :: DIM3
51 shape = (Z :. i :. j :. k)
52
53
54 zoom_shape :: ScaleFactor -> DIM3 -> DIM3
55 zoom_shape (sfx, sfy, sfz) sh =
56 let (Z :. x :. y :. z) = sh
57 x' = x * sfx
58 y' = y * sfy
59 z' = z * sfz
60 in
61 (Z :. x' :. y' :. z')