]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Grid.hs
Rename the spline project to spline3.
[spline3.git] / src / Grid.hs
1 -- | The Grid module just contains the Grid type and two constructors
2 -- for it. We hide the main Grid constructor because we don't want
3 -- to allow instantiation of a grid with h <= 0.
4 module Grid (empty_grid,
5 function_values,
6 Grid,
7 h,
8 make_grid)
9 where
10
11 -- | Our problem is defined on a Grid. The grid size is given by the
12 -- positive number h. The function values are the values of the
13 -- function at the grid points, which are distance h from one
14 -- another in each direction (x,y,z).
15 data Grid = Grid { h :: Double, -- MUST BE GREATER THAN ZERO!
16 function_values :: [[[Double]]] }
17 deriving (Eq, Show)
18
19
20 -- | The constructor that we want people to use. If we're passed a
21 -- non-positive grid size, we throw an error.
22 make_grid :: Double -> [[[Double]]] -> Grid
23 make_grid grid_size values
24 | grid_size <= 0 = error "grid size must be positive"
25 | otherwise = Grid grid_size values
26
27
28 -- | Creates an empty grid with grid size 1.
29 empty_grid :: Grid
30 empty_grid = Grid 1 [[[]]]