]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Face.hs
96848cd9f8c669b1045b40e45f1d0ee754e7e53c
[spline3.git] / src / Face.hs
1 -- | The Face module just contains the definition of the 'Face' data
2 -- type and its two typeclass instances.
3 module Face
4 where
5
6 import Point
7 import ThreeDimensional
8
9 data Face = Face { v0 :: Point,
10 v1 :: Point,
11 v2 :: Point,
12 v3 :: Point }
13 deriving (Eq)
14
15 instance Show Face where
16 show f = "Face:\n" ++
17 " v0: " ++ (show (v0 f)) ++ "\n" ++
18 " v1: " ++ (show (v1 f)) ++ "\n" ++
19 " v2: " ++ (show (v2 f)) ++ "\n" ++
20 " v3: " ++ (show (v3 f)) ++ "\n"
21
22 -- | The 'Face' type is an instance of 'ThreeDimensional' so that we
23 -- can call the 'center' function on it. This is useful because the
24 -- center of a face is always a vertex of a tetrahedron.
25 instance ThreeDimensional Face where
26 -- | Since a face is square, we can just average the four vertices
27 -- to find the center.
28 center f = ((v0 f) + (v1 f) + (v2 f) + (v3 f)) `scale` (1/4)
29
30 -- | It's possible to implement this, but it hasn't been done
31 -- yet. A face will contain a point if the point lies in the same
32 -- plane as the vertices of the face, and if it falls on the
33 -- correct side of the four sides of the face.
34 contains_point _ _ = False