diff options
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.hs | 16 | ||||
| -rw-r--r-- | Spear/Math/Vector/Vector3.hs | 8 | ||||
| -rw-r--r-- | Spear/Math/Vector/Vector4.hs | 8 |
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 @@ | |||
| 1 | module Spear.Math.Vector.Class | 1 | module Spear.Math.Vector.Vector |
| 2 | where | 2 | where |
| 3 | 3 | ||
| 4 | class (Fractional a, Ord a) => VectorClass a where | 4 | class (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 | ) |
| 15 | where | 15 | where |
| 16 | 16 | ||
| 17 | import Spear.Math.Vector.Class | 17 | import Spear.Math.Vector.Vector |
| 18 | 18 | ||
| 19 | import Foreign.C.Types (CFloat) | 19 | import Foreign.C.Types (CFloat) |
| 20 | import Foreign.Storable | 20 | import Foreign.Storable |
| 21 | 21 | ||
| 22 | type Right2 = Vector2 | 22 | type Right2 = Vector2 |
| 23 | type Up2 = Vector2 | 23 | type 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 | ||
| 53 | instance VectorClass Vector2 where | 53 | instance 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. |
| 112 | unitx2 = Vector2 1 0 | 108 | unitx2 = Vector2 1 0 |
| 113 | 109 | ||
| 114 | |||
| 115 | -- | Unit vector along the Y axis. | 110 | -- | Unit vector along the Y axis. |
| 116 | unity2 = Vector2 0 1 | 111 | unity2 = Vector2 0 1 |
| 117 | 112 | ||
| 118 | |||
| 119 | -- | Zero vector. | 113 | -- | Zero vector. |
| 120 | zero2 = Vector2 0 0 | 114 | zero2 = Vector2 0 0 |
| 121 | 115 | ||
| 122 | |||
| 123 | -- | Create a vector from the given values. | 116 | -- | Create a vector from the given values. |
| 124 | vec2 :: Float -> Float -> Vector2 | 117 | vec2 :: Float -> Float -> Vector2 |
| 125 | vec2 ax ay = Vector2 ax ay | 118 | vec2 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 | |||
| 18 | where | 18 | where |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | import Spear.Math.Vector.Class | 21 | import Spear.Math.Vector.Vector |
| 22 | 22 | ||
| 23 | import Foreign.C.Types (CFloat) | 23 | import Foreign.C.Types (CFloat) |
| 24 | import Foreign.Storable | 24 | import Foreign.Storable |
| 25 | 25 | ||
| 26 | type Right3 = Vector3 | 26 | type Right3 = Vector3 |
| 27 | type Up3 = Vector3 | 27 | type 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 | ||
| 79 | instance VectorClass Vector3 where | 79 | instance 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 | |||
| 12 | where | 12 | where |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | import Spear.Math.Vector.Class | 15 | import Spear.Math.Vector.Vector |
| 16 | 16 | ||
| 17 | import Foreign.C.Types (CFloat) | 17 | import Foreign.C.Types (CFloat) |
| 18 | import Foreign.Storable | 18 | import 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 | ||
| 76 | instance VectorClass Vector4 where | 76 | instance 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 | ||
