]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/Face.hs
Import cleanup in Face.
[spline3.git] / src / Face.hs
index bc1dfeee1b8067ccda3ccff433cb5107a862c9a1..f4bc1580882e6c8ba9050462948d794dc65a13d2 100644 (file)
@@ -1,83 +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"
-
-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
-
-
--- tetrahedron0 :: Face -> Tetrahedron
--- tetrahedron0 f =
---     Tetrahedron c v0' v1' v2' v3'
---     where
---       c = cube f
---       v0' = v0 f
---       v1' = v1 f
---       v2' = center f
---       v3' = center c
-
--- tetrahedron1 :: Face -> Tetrahedron
--- tetrahedron1 f =
---     Tetrahedron c v0' v1' v2' v3'
---     where
---       c = cube f
---       v0' = v1 f
---       v1' = v2 f
---       v2' = center f
---       v3' = center c
-
-
--- tetrahedron2 :: Face -> Tetrahedron
--- tetrahedron2 f =
---     Tetrahedron c v0' v1' v2' v3'
---     where
---       c = cube f
---       v0' = v2 f
---       v1' = v3 f
---       v2' = center f
---       v3' = center c
-
-
--- tetrahedron3 :: Face -> Tetrahedron
--- tetrahedron3 f =
---     Tetrahedron c v0' v1' v2' v3'
---     where
---       c = cube f
---       v0' = v3 f
---       v1' = v0 f
---       v2' = center f
---       v3' = center c
-
--- tetrahedrons :: Cube -> [Tetrahedron]
--- tetrahedrons c =
---     concat [
---  [tetrahedron0 f0, tetrahedron1 f0, tetrahedron2 f0, tetrahedron3 f0],
---  [tetrahedron0 f1, tetrahedron1 f1, tetrahedron2 f1, tetrahedron3 f2],
---  [tetrahedron0 f2, tetrahedron1 f2, tetrahedron2 f2, tetrahedron3 f2],
---  [tetrahedron0 f3, tetrahedron1 f3, tetrahedron2 f3, tetrahedron3 f3],
---  [tetrahedron0 f4, tetrahedron1 f4, tetrahedron2 f4, tetrahedron3 f4],
---  [tetrahedron0 f5, tetrahedron1 f5, tetrahedron2 f5, tetrahedron3 f5] ]
---     where
---       f0 = face0 c
---       f1 = face1 c
---       f2 = face2 c
---       f3 = face3 c
---       f4 = face4 c
---       f5 = face5 c
+    show (Face v0' v1' v2' v3') =
+      "Face:\n" ++
+        "  v0: " ++ (show v0') ++ "\n" ++
+        "  v1: " ++ (show v1') ++ "\n" ++
+        "  v2: " ++ (show v2') ++ "\n" ++
+        "  v3: " ++ (show v3') ++ "\n"
+
+-- | 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)