diff options
author | 3gg <3gg@shellblade.net> | 2025-01-04 16:25:14 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-01-04 16:25:14 -0800 |
commit | 548e40add0fd3ebea18510f7c16a464680aed63c (patch) | |
tree | c4bd5b59f4d45ea0fc13467beb33317c7dff326f | |
parent | 86e9a91e2af9541bebea9afa5697450443a3d10c (diff) |
Add vector scale.
-rw-r--r-- | Spear/Math/Vector/Vector.hs | 3 | ||||
-rw-r--r-- | Spear/Math/Vector/Vector2.hs | 8 | ||||
-rw-r--r-- | Spear/Math/Vector/Vector3.hs | 3 | ||||
-rw-r--r-- | Spear/Math/Vector/Vector4.hs | 3 |
4 files changed, 16 insertions, 1 deletions
diff --git a/Spear/Math/Vector/Vector.hs b/Spear/Math/Vector/Vector.hs index e7f6d53..d9cd64f 100644 --- a/Spear/Math/Vector/Vector.hs +++ b/Spear/Math/Vector/Vector.hs | |||
@@ -48,3 +48,6 @@ class | |||
48 | 48 | ||
49 | -- | Normalise the given vector. | 49 | -- | Normalise the given vector. |
50 | normalise :: v -> v | 50 | normalise :: v -> v |
51 | |||
52 | -- | Scale the vector. | ||
53 | scale :: Float -> v -> v | ||
diff --git a/Spear/Math/Vector/Vector2.hs b/Spear/Math/Vector/Vector2.hs index 1ede3a9..b74cfef 100644 --- a/Spear/Math/Vector/Vector2.hs +++ b/Spear/Math/Vector/Vector2.hs | |||
@@ -33,7 +33,10 @@ type Position2 = Vector2 | |||
33 | 33 | ||
34 | 34 | ||
35 | -- | Represents a vector in 2D. | 35 | -- | Represents a vector in 2D. |
36 | data Vector2 = Vector2 {-# UNPACK #-} !Float {-# UNPACK #-} !Float deriving (Eq, Show) | 36 | data Vector2 = Vector2 |
37 | {-# UNPACK #-} !Float | ||
38 | {-# UNPACK #-} !Float | ||
39 | deriving (Eq, Show) | ||
37 | 40 | ||
38 | 41 | ||
39 | instance Addition Vector2 Vector2 where | 42 | instance Addition Vector2 Vector2 where |
@@ -129,6 +132,9 @@ instance Vector Vector2 where | |||
129 | n = if n' == 0 then 1 else n' | 132 | n = if n' == 0 then 1 else n' |
130 | in ((1.0::Float) / n) * v | 133 | in ((1.0::Float) / n) * v |
131 | 134 | ||
135 | {-# INLINABLE scale #-} | ||
136 | scale s (Vector2 x y) = Vector2 (s*x) (s*y) | ||
137 | |||
132 | 138 | ||
133 | sizeFloat = sizeOf (undefined :: CFloat) | 139 | sizeFloat = sizeOf (undefined :: CFloat) |
134 | 140 | ||
diff --git a/Spear/Math/Vector/Vector3.hs b/Spear/Math/Vector/Vector3.hs index db5dc45..6ad4fe1 100644 --- a/Spear/Math/Vector/Vector3.hs +++ b/Spear/Math/Vector/Vector3.hs | |||
@@ -163,6 +163,9 @@ instance Vector Vector3 where | |||
163 | n = if n' == 0 then 1 else n' | 163 | n = if n' == 0 then 1 else n' |
164 | in ((1.0::Float) / n) * v | 164 | in ((1.0::Float) / n) * v |
165 | 165 | ||
166 | {-# INLINABLE scale #-} | ||
167 | scale s (Vector3 x y z) = Vector3 (s*x) (s*y) (s*z) | ||
168 | |||
166 | 169 | ||
167 | sizeFloat = sizeOf (undefined :: CFloat) | 170 | sizeFloat = sizeOf (undefined :: CFloat) |
168 | 171 | ||
diff --git a/Spear/Math/Vector/Vector4.hs b/Spear/Math/Vector/Vector4.hs index 907295e..3ca27c9 100644 --- a/Spear/Math/Vector/Vector4.hs +++ b/Spear/Math/Vector/Vector4.hs | |||
@@ -161,6 +161,9 @@ instance Vector Vector4 where | |||
161 | n = if n' == 0 then 1 else n' | 161 | n = if n' == 0 then 1 else n' |
162 | in ((1.0::Float) / n) * v | 162 | in ((1.0::Float) / n) * v |
163 | 163 | ||
164 | {-# INLINABLE scale #-} | ||
165 | scale s (Vector4 x y z w) = Vector4 (s*x) (s*y) (s*z) (s*w) | ||
166 | |||
164 | 167 | ||
165 | sizeFloat = sizeOf (undefined :: CFloat) | 168 | sizeFloat = sizeOf (undefined :: CFloat) |
166 | 169 | ||