X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FFace.hs;h=de24a43e6c1cd72afb2c88b79507a38c7a48640e;hb=b6f84e979fd6c5a5e62b53143e737a28d8ed64a7;hp=96848cd9f8c669b1045b40e45f1d0ee754e7e53c;hpb=58cf11569acb270995d2de924dda03ef526647e2;p=spline3.git diff --git a/src/Face.hs b/src/Face.hs index 96848cd..de24a43 100644 --- a/src/Face.hs +++ b/src/Face.hs @@ -1,34 +1,31 @@ -- | The Face module just contains the definition of the 'Face' data -- type and its two typeclass instances. -module Face +-- +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" --- | The 'Face' type is an instance of 'ThreeDimensional' so that we --- can call the 'center' function on it. This is useful because the --- center of a face is always a vertex of a tetrahedron. -instance ThreeDimensional Face where - -- | Since a face is square, we can just average the four vertices - -- to find the center. - center f = ((v0 f) + (v1 f) + (v2 f) + (v3 f)) `scale` (1/4) - - -- | It's possible to implement this, but it hasn't been done - -- yet. A face will contain a point if the point lies in the same - -- plane as the vertices of the face, and if it falls on the - -- correct side of the four sides of the face. - 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)