aboutsummaryrefslogtreecommitdiff
path: root/Spear/Math/Plane.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Math/Plane.hs')
-rw-r--r--Spear/Math/Plane.hs29
1 files changed, 15 insertions, 14 deletions
diff --git a/Spear/Math/Plane.hs b/Spear/Math/Plane.hs
index 0f5829b..8772a42 100644
--- a/Spear/Math/Plane.hs
+++ b/Spear/Math/Plane.hs
@@ -1,8 +1,8 @@
1module Spear.Math.Plane 1module Spear.Math.Plane
2( 2(
3 Plane 3 Plane
4, plane 4, plane
5, classify 5, classify
6) 6)
7where 7where
8 8
@@ -13,21 +13,22 @@ import Spear.Math.Vector3 as Vector
13data PointPlanePos = Front | Back | Contained deriving (Eq, Ord, Show) 13data PointPlanePos = Front | Back | Contained deriving (Eq, Ord, Show)
14 14
15 15
16data Plane = Plane { 16data Plane = Plane
17 n :: !Vector3, 17 { n :: {-# UNPACK #-} !Vector3,
18 d :: !Float 18 d :: {-# UNPACK #-} !Float
19} deriving(Eq, Show) 19 }
20 deriving(Eq, Show)
20 21
21 22
22-- | Create a plane given a normal vector and a distance from the origin. 23-- | Create a plane given a normal vector and a distance from the origin.
23plane :: Vector3 -> Float -> Plane 24plane :: Vector3 -> Float -> Plane
24plane n d = Plane (normalise n) d 25plane n d = Plane (normalise n) d
25 26
26 27
27-- | Classify the given point's relative position with respect to the given plane. 28-- | Classify the given point's relative position with respect to the given plane.
28classify :: Plane -> Vector3 -> PointPlanePos 29classify :: Plane -> Vector3 -> PointPlanePos
29classify (Plane n d) pt = case (n `dot` pt - d) `compare` 0 of 30classify (Plane n d) pt =
30 GT -> Front 31 case (n `dot` pt - d) `compare` 0 of
31 LT -> Back 32 GT -> Front
32 EQ -> Contained 33 LT -> Back
33 \ No newline at end of file 34 EQ -> Contained