X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FFace.hs;h=f4bc1580882e6c8ba9050462948d794dc65a13d2;hb=539486a032dbd760bf01c37d6d8e063aaf4a59bc;hp=3f1c223e10b3d28516c1c052fe4532f96633adf0;hpb=3cba7ca0c0b39cfd132a3b6ee255c377041cefb5;p=spline3.git diff --git a/src/Face.hs b/src/Face.hs index 3f1c223..f4bc158 100644 --- a/src/Face.hs +++ b/src/Face.hs @@ -1,23 +1,31 @@ -module Face +-- | The Face module just contains the definition of the 'Face' data +-- type and its two typeclass instances. +-- +module Face ( + Face(..), + center ) where -import Point -import ThreeDimensional +import Point ( Point(..), scale ) -data Face = Face { v0 :: Point, - v1 :: Point, - v2 :: Point, - v3 :: Point } +data Face = Face { v0 :: !Point, + v1 :: !Point, + v2 :: !Point, + v3 :: !Point } deriving (Eq) instance Show Face where - show f = "Face:\n" ++ - " v0: " ++ (show (v0 f)) ++ "\n" ++ - " v1: " ++ (show (v1 f)) ++ "\n" ++ - " v2: " ++ (show (v2 f)) ++ "\n" ++ - " v3: " ++ (show (v3 f)) ++ "\n" + show (Face v0' v1' v2' v3') = + "Face:\n" ++ + " v0: " ++ (show v0') ++ "\n" ++ + " v1: " ++ (show v1') ++ "\n" ++ + " v2: " ++ (show v2') ++ "\n" ++ + " v3: " ++ (show v3') ++ "\n" -instance ThreeDimensional Face where - center f = ((v0 f) + (v1 f) + (v2 f) + (v3 f)) `scale` (1/4) - -- Too lazy to implement this right now. - contains_point _ _ = False +-- | Returns the center of the given face. Since a face is just +-- square, we can average the four vertices to find its center. This +-- is useful because the center of a face is always a vertex of a +-- tetrahedron. +center :: Face -> Point +center (Face v0' v1' v2' v3') = + (v0' + v1' + v2' + v3') `scale` (1/4)