From a00285359a0d6712ee1d4a9ee82fd119345ff981 Mon Sep 17 00:00:00 2001 From: Jeanne-Kamikaze Date: Thu, 21 Feb 2013 20:40:32 +0100 Subject: Made Vector.Class functions inlinable --- Spear/Math/Vector/Vector2.hs | 26 ++++++++++++++++++-------- Spear/Math/Vector/Vector3.hs | 31 +++++++++++++++++++++---------- Spear/Math/Vector/Vector4.hs | 20 ++++++++++++++++---- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/Spear/Math/Vector/Vector2.hs b/Spear/Math/Vector/Vector2.hs index 7aaece5..616d9dd 100644 --- a/Spear/Math/Vector/Vector2.hs +++ b/Spear/Math/Vector/Vector2.hs @@ -47,26 +47,36 @@ instance Ord Vector2 where instance VectorClass Vector2 where + {-# INLINABLE fromList #-} fromList (ax:ay:_) = Vector2 ax ay - + + {-# INLINABLE x #-} x (Vector2 ax _) = ax - + + {-# INLINABLE y #-} y (Vector2 _ ay) = ay + {-# INLINABLE (!) #-} (Vector2 ax _) ! 0 = ax (Vector2 _ ay) ! 1 = ay _ ! _ = 0 - + + {-# INLINABLE dot #-} Vector2 ax ay `dot` Vector2 bx by = ax*bx + ay*by - + + {-# INLINABLE normSq #-} normSq (Vector2 ax ay) = ax*ax + ay*ay - + + {-# INLINABLE norm #-} norm = sqrt . normSq - + + {-# INLINABLE scale #-} scale s (Vector2 ax ay) = Vector2 (s*ax) (s*ay) - + + {-# INLINABLE neg #-} neg (Vector2 ax ay) = Vector2 (-ax) (-ay) - + + {-# INLINABLE normalise #-} normalise v = let n' = norm v n = if n' == 0 then 1 else n' 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 instance VectorClass Vector3 where + {-# INLINABLE fromList #-} fromList (ax:ay:az:_) = Vector3 ax ay az - + + {-# INLINABLE x #-} x (Vector3 ax _ _ ) = ax - + + {-# INLINABLE y #-} y (Vector3 _ ay _ ) = ay - - z (Vector3 _ _ az) = az + {-# INLINABLE z #-} + z (Vector3 _ _ az) = az + + {-# INLINABLE (!) #-} (Vector3 ax _ _) ! 0 = ax (Vector3 _ ay _) ! 1 = ay (Vector3 _ _ az) ! 2 = az _ ! _ = 0 - + + {-# INLINABLE dot #-} Vector3 ax ay az `dot` Vector3 bx by bz = ax*bx + ay*by + az*bz - + + {-# INLINABLE normSq #-} normSq (Vector3 ax ay az) = ax*ax + ay*ay + az*az - + + {-# INLINABLE norm #-} norm = sqrt . normSq - + + {-# INLINABLE scale #-} scale s (Vector3 ax ay az) = Vector3 (s*ax) (s*ay) (s*az) - + + {-# INLINABLE neg #-} neg (Vector3 ax ay az) = Vector3 (-ax) (-ay) (-az) - + + {-# INLINABLE normalise #-} normalise v = let n' = norm v n = if n' == 0 then 1 else n' diff --git a/Spear/Math/Vector/Vector4.hs b/Spear/Math/Vector/Vector4.hs index 1f5494d..5185763 100644 --- a/Spear/Math/Vector/Vector4.hs +++ b/Spear/Math/Vector/Vector4.hs @@ -74,32 +74,44 @@ instance Ord Vector4 where instance VectorClass Vector4 where + {-# INLINABLE fromList #-} fromList (ax:ay:az:aw:_) = Vector4 ax ay az aw + {-# INLINABLE x #-} x (Vector4 ax _ _ _ ) = ax - + + {-# INLINABLE y #-} y (Vector4 _ ay _ _ ) = ay - + + {-# INLINABLE z #-} z (Vector4 _ _ az _ ) = az - - w (Vector4 _ _ _ aw) = aw + {-# INLINABLE w #-} + w (Vector4 _ _ _ aw) = aw + + {-# INLINABLE (!) #-} (Vector4 ax _ _ _) ! 0 = ax (Vector4 _ ay _ _) ! 1 = ay (Vector4 _ _ az _) ! 2 = az (Vector4 _ _ _ aw) ! 3 = aw _ ! _ = 0 + {-# INLINABLE dot #-} Vector4 ax ay az aw `dot` Vector4 bx by bz bw = ax*bx + ay*by + az*bz + aw*bw + {-# INLINABLE normSq #-} normSq (Vector4 ax ay az aw) = ax*ax + ay*ay + az*az + aw*aw + {-# INLINABLE norm #-} norm = sqrt . normSq + {-# INLINABLE scale #-} scale s (Vector4 ax ay az aw) = Vector4 (s*ax) (s*ay) (s*az) (s*aw) + {-# INLINABLE neg #-} neg (Vector4 ax ay az aw) = Vector4 (-ax) (-ay) (-az) (-aw) + {-# INLINABLE normalise #-} normalise v = let n' = norm v n = if n' == 0 then 1 else n' -- cgit v1.2.3