X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FGrid.hs;h=a1058d07f2fa4c89d5bcab914e05a428dccb52f8;hb=1bf996325008f79215a607d765adb042026f7444;hp=dc52482b0eb3cc2bc88656df24681759b8a4d346;hpb=715be016934300f596a11e4fc5b8ca2ec42d6c34;p=spline3.git diff --git a/src/Grid.hs b/src/Grid.hs index dc52482..a1058d0 100644 --- a/src/Grid.hs +++ b/src/Grid.hs @@ -53,33 +53,27 @@ instance Arbitrary Grid where return (make_grid h' fvs) --- | The constructor that we want people to use. If we're passed a --- non-positive grid size, we throw an error. +-- | The constructor that we want people to use. +-- Ignore non-positive grid sizes for performance. make_grid :: Double -> Values3D -> Grid -make_grid grid_size values - | grid_size <= 0 = error "grid size must be positive" - | otherwise = Grid grid_size values +make_grid grid_size values = + Grid grid_size values -- | Takes a grid and a position as an argument and returns the cube --- centered on that position. If there is no cube there (i.e. the --- position is outside of the grid), it will throw an error. +-- centered on that position. If there is no cube there, well, you +-- shouldn't have done that. The omitted "otherwise" case actually +-- does improve performance. cube_at :: Grid -> Int -> Int -> Int -> Cube -cube_at !g !i !j !k - | i < 0 = error "i < 0 in cube_at" - | i >= xsize = error "i >= xsize in cube_at" - | j < 0 = error "j < 0 in cube_at" - | j >= ysize = error "j >= ysize in cube_at" - | k < 0 = error "k < 0 in cube_at" - | k >= zsize = error "k >= zsize in cube_at" - | otherwise = Cube delta i j k fvs' tet_vol - where - fvs = function_values g - (xsize, ysize, zsize) = dims fvs - fvs' = make_values fvs i j k - delta = h g - tet_vol = (1/24)*(delta^(3::Int)) +cube_at !g !i !j !k = + Cube delta i j k fvs' tet_vol + where + fvs = function_values g + fvs' = make_values fvs i j k + delta = h g + tet_vol = (1/24)*(delta^(3::Int)) + -- The first cube along any axis covers (-h/2, h/2). The second -- covers (h/2, 3h/2). The third, (3h/2, 5h/2), and so on.