aboutsummaryrefslogtreecommitdiff
path: root/Spear/Math/Vector/Vector3.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Math/Vector/Vector3.hs')
-rw-r--r--Spear/Math/Vector/Vector3.hs31
1 files changed, 21 insertions, 10 deletions
diff --git a/Spear/Math/Vector/Vector3.hs b/Spear/Math/Vector/Vector3.hs
index c19b7c7..eeab486 100644
--- a/Spear/Math/Vector/Vector3.hs
+++ b/Spear/Math/Vector/Vector3.hs
@@ -69,29 +69,40 @@ instance Ord Vector3 where
69 69
70 70
71instance VectorClass Vector3 where 71instance VectorClass Vector3 where
72 {-# INLINABLE fromList #-}
72 fromList (ax:ay:az:_) = Vector3 ax ay az 73 fromList (ax:ay:az:_) = Vector3 ax ay az
73 74
75 {-# INLINABLE x #-}
74 x (Vector3 ax _ _ ) = ax 76 x (Vector3 ax _ _ ) = ax
75 77
78 {-# INLINABLE y #-}
76 y (Vector3 _ ay _ ) = ay 79 y (Vector3 _ ay _ ) = ay
77
78 z (Vector3 _ _ az) = az
79 80
81 {-# INLINABLE z #-}
82 z (Vector3 _ _ az) = az
83
84 {-# INLINABLE (!) #-}
80 (Vector3 ax _ _) ! 0 = ax 85 (Vector3 ax _ _) ! 0 = ax
81 (Vector3 _ ay _) ! 1 = ay 86 (Vector3 _ ay _) ! 1 = ay
82 (Vector3 _ _ az) ! 2 = az 87 (Vector3 _ _ az) ! 2 = az
83 _ ! _ = 0 88 _ ! _ = 0
84 89
90 {-# INLINABLE dot #-}
85 Vector3 ax ay az `dot` Vector3 bx by bz = ax*bx + ay*by + az*bz 91 Vector3 ax ay az `dot` Vector3 bx by bz = ax*bx + ay*by + az*bz
86 92
93 {-# INLINABLE normSq #-}
87 normSq (Vector3 ax ay az) = ax*ax + ay*ay + az*az 94 normSq (Vector3 ax ay az) = ax*ax + ay*ay + az*az
88 95
96 {-# INLINABLE norm #-}
89 norm = sqrt . normSq 97 norm = sqrt . normSq
90 98
99 {-# INLINABLE scale #-}
91 scale s (Vector3 ax ay az) = Vector3 (s*ax) (s*ay) (s*az) 100 scale s (Vector3 ax ay az) = Vector3 (s*ax) (s*ay) (s*az)
92 101
102 {-# INLINABLE neg #-}
93 neg (Vector3 ax ay az) = Vector3 (-ax) (-ay) (-az) 103 neg (Vector3 ax ay az) = Vector3 (-ax) (-ay) (-az)
94 104
105 {-# INLINABLE normalise #-}
95 normalise v = 106 normalise v =
96 let n' = norm v 107 let n' = norm v
97 n = if n' == 0 then 1 else n' 108 n = if n' == 0 then 1 else n'