aboutsummaryrefslogtreecommitdiff
path: root/Spear/Math/Vector
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Math/Vector')
-rw-r--r--Spear/Math/Vector/Vector.hs (renamed from Spear/Math/Vector/Class.hs)20
-rw-r--r--Spear/Math/Vector/Vector2.hs16
-rw-r--r--Spear/Math/Vector/Vector3.hs8
-rw-r--r--Spear/Math/Vector/Vector4.hs8
4 files changed, 22 insertions, 30 deletions
diff --git a/Spear/Math/Vector/Class.hs b/Spear/Math/Vector/Vector.hs
index 19ddfac..35b04e2 100644
--- a/Spear/Math/Vector/Class.hs
+++ b/Spear/Math/Vector/Vector.hs
@@ -1,10 +1,10 @@
1module Spear.Math.Vector.Class 1module Spear.Math.Vector.Vector
2where 2where
3 3
4class (Fractional a, Ord a) => VectorClass a where 4class (Fractional a, Ord a) => Vector a where
5 -- | Create a vector from the given list. 5 -- | Create a vector from the given list.
6 fromList :: [Float] -> a 6 fromList :: [Float] -> a
7 7
8 -- | Return the vector's x coordinate. 8 -- | Return the vector's x coordinate.
9 x :: a -> Float 9 x :: a -> Float
10 x _ = 0 10 x _ = 0
@@ -23,21 +23,21 @@ class (Fractional a, Ord a) => VectorClass a where
23 23
24 -- | Return the vector's ith coordinate. 24 -- | Return the vector's ith coordinate.
25 (!) :: a -> Int -> Float 25 (!) :: a -> Int -> Float
26 26
27 -- | Compute the given vectors' dot product. 27 -- | Compute the given vectors' dot product.
28 dot :: a -> a -> Float 28 dot :: a -> a -> Float
29 29
30 -- | Compute the given vector's squared norm. 30 -- | Compute the given vector's squared norm.
31 normSq :: a -> Float 31 normSq :: a -> Float
32 32
33 -- | Compute the given vector's norm. 33 -- | Compute the given vector's norm.
34 norm :: a -> Float 34 norm :: a -> Float
35 35
36 -- | Multiply the given vector with the given scalar. 36 -- | Multiply the given vector with the given scalar.
37 scale :: Float -> a -> a 37 scale :: Float -> a -> a
38 38
39 -- | Negate the given vector. 39 -- | Negate the given vector.
40 neg :: a -> a 40 neg :: a -> a
41 41
42 -- | Normalise the given vector. 42 -- | Normalise the given vector.
43 normalise :: a -> a \ No newline at end of file 43 normalise :: a -> a
diff --git a/Spear/Math/Vector/Vector2.hs b/Spear/Math/Vector/Vector2.hs
index dfb4fb9..5bbb632 100644
--- a/Spear/Math/Vector/Vector2.hs
+++ b/Spear/Math/Vector/Vector2.hs
@@ -14,10 +14,10 @@ module Spear.Math.Vector.Vector2
14) 14)
15where 15where
16 16
17import Spear.Math.Vector.Class 17import Spear.Math.Vector.Vector
18 18
19import Foreign.C.Types (CFloat) 19import Foreign.C.Types (CFloat)
20import Foreign.Storable 20import Foreign.Storable
21 21
22type Right2 = Vector2 22type Right2 = Vector2
23type Up2 = Vector2 23type Up2 = Vector2
@@ -50,7 +50,7 @@ instance Ord Vector2 where
50 min (Vector2 ax ay) (Vector2 bx by) = Vector2 (Prelude.min ax bx) (Prelude.min ay by) 50 min (Vector2 ax ay) (Vector2 bx by) = Vector2 (Prelude.min ax bx) (Prelude.min ay by)
51 51
52 52
53instance VectorClass Vector2 where 53instance Vector Vector2 where
54 {-# INLINABLE fromList #-} 54 {-# INLINABLE fromList #-}
55 fromList (ax:ay:_) = Vector2 ax ay 55 fromList (ax:ay:_) = Vector2 ax ay
56 56
@@ -104,27 +104,19 @@ instance Storable Vector2 where
104 pokeByteOff ptr sizeFloat ay 104 pokeByteOff ptr sizeFloat ay
105 105
106 106
107-- | Get the vector's x coordinate.
108
109
110
111-- | Unit vector along the X axis. 107-- | Unit vector along the X axis.
112unitx2 = Vector2 1 0 108unitx2 = Vector2 1 0
113 109
114
115-- | Unit vector along the Y axis. 110-- | Unit vector along the Y axis.
116unity2 = Vector2 0 1 111unity2 = Vector2 0 1
117 112
118
119-- | Zero vector. 113-- | Zero vector.
120zero2 = Vector2 0 0 114zero2 = Vector2 0 0
121 115
122
123-- | Create a vector from the given values. 116-- | Create a vector from the given values.
124vec2 :: Float -> Float -> Vector2 117vec2 :: Float -> Float -> Vector2
125vec2 ax ay = Vector2 ax ay 118vec2 ax ay = Vector2 ax ay
126 119
127
128-- | Compute a vector perpendicular to the given one, satisfying: 120-- | Compute a vector perpendicular to the given one, satisfying:
129-- 121--
130-- perp (Vector2 0 1) = Vector2 1 0 122-- perp (Vector2 0 1) = Vector2 1 0
diff --git a/Spear/Math/Vector/Vector3.hs b/Spear/Math/Vector/Vector3.hs
index 429df0f..82deba2 100644
--- a/Spear/Math/Vector/Vector3.hs
+++ b/Spear/Math/Vector/Vector3.hs
@@ -18,10 +18,10 @@ module Spear.Math.Vector.Vector3
18where 18where
19 19
20 20
21import Spear.Math.Vector.Class 21import Spear.Math.Vector.Vector
22 22
23import Foreign.C.Types (CFloat) 23import Foreign.C.Types (CFloat)
24import Foreign.Storable 24import Foreign.Storable
25 25
26type Right3 = Vector3 26type Right3 = Vector3
27type Up3 = Vector3 27type Up3 = Vector3
@@ -76,7 +76,7 @@ instance Ord Vector3 where
76 min (Vector3 ax ay az) (Vector3 bx by bz) = Vector3 (Prelude.min ax bx) (Prelude.min ay by) (Prelude.min az bz) 76 min (Vector3 ax ay az) (Vector3 bx by bz) = Vector3 (Prelude.min ax bx) (Prelude.min ay by) (Prelude.min az bz)
77 77
78 78
79instance VectorClass Vector3 where 79instance Vector Vector3 where
80 {-# INLINABLE fromList #-} 80 {-# INLINABLE fromList #-}
81 fromList (ax:ay:az:_) = Vector3 ax ay az 81 fromList (ax:ay:az:_) = Vector3 ax ay az
82 82
diff --git a/Spear/Math/Vector/Vector4.hs b/Spear/Math/Vector/Vector4.hs
index 4314b51..325eefc 100644
--- a/Spear/Math/Vector/Vector4.hs
+++ b/Spear/Math/Vector/Vector4.hs
@@ -12,10 +12,10 @@ module Spear.Math.Vector.Vector4
12where 12where
13 13
14 14
15import Spear.Math.Vector.Class 15import Spear.Math.Vector.Vector
16 16
17import Foreign.C.Types (CFloat) 17import Foreign.C.Types (CFloat)
18import Foreign.Storable 18import Foreign.Storable
19 19
20 20
21-- | Represents a vector in 3D. 21-- | Represents a vector in 3D.
@@ -73,7 +73,7 @@ instance Ord Vector4 where
73 Vector4 (Prelude.max ax bx) (Prelude.max ay by) (Prelude.max az bz) (Prelude.min aw bw) 73 Vector4 (Prelude.max ax bx) (Prelude.max ay by) (Prelude.max az bz) (Prelude.min aw bw)
74 74
75 75
76instance VectorClass Vector4 where 76instance Vector Vector4 where
77 {-# INLINABLE fromList #-} 77 {-# INLINABLE fromList #-}
78 fromList (ax:ay:az:aw:_) = Vector4 ax ay az aw 78 fromList (ax:ay:az:aw:_) = Vector4 ax ay az aw
79 79