X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCube.hs;h=6263d2e32a331ffe971b61ba78eed466fd71c04d;hb=603d9155a29bfbc353b42a6c880edce224626a16;hp=2ec9e4848318fb12135309900e5505df20f3614e;hpb=574a15e7ccfa3109f06fa05ed09e2282a03a7dad;p=spline3.git diff --git a/src/Cube.hs b/src/Cube.hs index 2ec9e48..6263d2e 100644 --- a/src/Cube.hs +++ b/src/Cube.hs @@ -1,6 +1,8 @@ module Cube where +import Test.QuickCheck (Arbitrary(..), Gen, Positive(..), choose) + import Cardinal import qualified Face (Face(Face, v0, v1, v2, v3)) import FunctionValues @@ -16,6 +18,19 @@ data Cube = Cube { h :: Double, deriving (Eq) +instance Arbitrary Cube where + arbitrary = do + (Positive h') <- arbitrary :: Gen (Positive Double) + i' <- choose (coordmin, coordmax) + j' <- choose (coordmin, coordmax) + k' <- choose (coordmin, coordmax) + fv' <- arbitrary :: Gen FunctionValues + return (Cube h' i' j' k' fv') + where + coordmin = -268435456 -- -(2^29 / 2) + coordmax = 268435456 -- +(2^29 / 2) + + instance Show Cube where show c = "Cube_" ++ subscript ++ "\n" ++ @@ -101,13 +116,13 @@ instance ThreeDimensional Cube where -- | It's easy to tell if a point is within a cube; just make sure -- that it falls on the proper side of each of the cube's faces. - contains_point c p - | (x_coord p) < (xmin c) = False - | (x_coord p) > (xmax c) = False - | (y_coord p) < (ymin c) = False - | (y_coord p) > (ymax c) = False - | (z_coord p) < (zmin c) = False - | (z_coord p) > (zmax c) = False + contains_point c (x, y, z) + | x < (xmin c) = False + | x > (xmax c) = False + | y < (ymin c) = False + | y > (ymax c) = False + | z < (zmin c) = False + | z > (zmax c) = False | otherwise = True @@ -447,8 +462,8 @@ tetrahedron23 c = $ Tetrahedron.fv (tetrahedron0 c) -tetrahedrons :: Cube -> [Tetrahedron] -tetrahedrons c = +tetrahedra :: Cube -> [Tetrahedron] +tetrahedra c = [tetrahedron0 c, tetrahedron1 c, tetrahedron2 c, @@ -482,4 +497,4 @@ find_containing_tetrahedra c p = filter contains_our_point all_tetrahedra where contains_our_point = flip contains_point p - all_tetrahedra = tetrahedrons c + all_tetrahedra = tetrahedra c