X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FGrid.hs;h=893fe5c360d3f39c73a99ebab26d1320fd798815;hb=89a8f8f3728c6e8730a37304708312b67bc23274;hp=2cf56ba3f437461e2112dd9f2d5c6db206a2f6fb;hpb=bb8ee1121501e86c1971c83dd749da78f9b7abf5;p=spline3.git diff --git a/src/Grid.hs b/src/Grid.hs index 2cf56ba..893fe5c 100644 --- a/src/Grid.hs +++ b/src/Grid.hs @@ -2,6 +2,7 @@ -- for it. We hide the main Grid constructor because we don't want -- to allow instantiation of a grid with h <= 0. module Grid ( + cube_at, grid_tests, make_grid, slow_tests, @@ -22,13 +23,13 @@ import Comparisons import Cube (Cube(Cube), find_containing_tetrahedron, tetrahedra, - tetrahedron0, - tetrahedron15) + tetrahedron) import Examples import FunctionValues import Point (Point) +import PolynomialArray (PolynomialArray) import ScaleFactor -import Tetrahedron (c, polynomial, v0, v1, v2, v3) +import Tetrahedron (Tetrahedron, c, number, polynomial, v0, v1, v2, v3) import ThreeDimensional import Values (Values3D, dims, empty3d, zoom_shape) @@ -132,30 +133,32 @@ find_containing_cube g p = {-# INLINE zoom_lookup #-} -zoom_lookup :: Grid -> ScaleFactor -> a -> (R.DIM3 -> Double) -zoom_lookup g scale_factor _ = zoom_result g scale_factor +zoom_lookup :: Grid -> PolynomialArray -> ScaleFactor -> a -> (R.DIM3 -> Double) +zoom_lookup g polynomials scale_factor _ = + zoom_result g polynomials scale_factor {-# INLINE zoom_result #-} -zoom_result :: Grid -> ScaleFactor -> R.DIM3 -> Double -zoom_result g (sfx, sfy, sfz) (R.Z R.:. i R.:. j R.:. k) = - f p +zoom_result :: Grid -> PolynomialArray -> ScaleFactor -> R.DIM3 -> Double +zoom_result g polynomials (sfx, sfy, sfz) (R.Z R.:. m R.:. n R.:. o) = + (polynomials ! (i, j, k, (number t))) p where offset = (h g)/2 - i' = (fromIntegral i) / (fromIntegral sfx) - offset - j' = (fromIntegral j) / (fromIntegral sfy) - offset - k' = (fromIntegral k) / (fromIntegral sfz) - offset - p = (i', j', k') :: Point + m' = (fromIntegral m) / (fromIntegral sfx) - offset + n' = (fromIntegral n) / (fromIntegral sfy) - offset + o' = (fromIntegral o) / (fromIntegral sfz) - offset + p = (m', n', o') :: Point cube = find_containing_cube g p + -- Figure out i,j,k without importing those functions. + Cube _ i j k _ _ = cube t = find_containing_tetrahedron cube p - f = polynomial t - -zoom :: Grid -> ScaleFactor -> Values3D -zoom g scale_factor + +zoom :: Grid -> PolynomialArray -> ScaleFactor -> Values3D +zoom g polynomials scale_factor | xsize == 0 || ysize == 0 || zsize == 0 = empty3d | otherwise = - R.force $ R.traverse arr transExtent (zoom_lookup g scale_factor) + R.force $ R.traverse arr transExtent (zoom_lookup g polynomials scale_factor) where arr = function_values g (xsize, ysize, zsize) = dims arr @@ -205,7 +208,7 @@ trilinear_c0_t0_tests = where g = make_grid 1 trilinear cube = cube_at g 1 1 1 - t = tetrahedron0 cube + t = tetrahedron cube 0 test_trilinear_c0030 :: Assertion test_trilinear_c0030 = @@ -334,7 +337,7 @@ test_zeros_reproduced = where g = make_grid 1 zeros c0 = cube_at g 1 1 1 - t0 = tetrahedron0 c0 + t0 = tetrahedron c0 0 p = polynomial t0 @@ -362,18 +365,18 @@ test_trilinear9x9x9_reproduced = -- -- Example from before the fix: -- --- > b0 (tetrahedron15 c) p --- -3.4694469519536365e-18 +-- b1 (tetrahedron c 20) (0, 17.5, 0.5) +-- -0.0 -- test_tetrahedra_collision_sensitivity :: Assertion test_tetrahedra_collision_sensitivity = assertTrue "tetrahedron collision tests isn't too sensitive" $ - contains_point t15 p + contains_point t20 p where g = make_grid 1 naturals_1d - cube = cube_at g 0 17 1 - p = (0, 16.75, 0.5) :: Point - t15 = tetrahedron15 cube + cube = cube_at g 0 18 0 + p = (0, 17.5, 0.5) :: Point + t20 = tetrahedron cube 20 prop_cube_indices_never_go_out_of_bounds :: Grid -> Gen Bool