aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeanne-Kamikaze <jeannekamikaze@gmail.com>2013-02-21 20:40:32 +0100
committerJeanne-Kamikaze <jeannekamikaze@gmail.com>2013-02-21 20:40:32 +0100
commita00285359a0d6712ee1d4a9ee82fd119345ff981 (patch)
treeb2d65ee318b1b387262b9ac5b3d30d90dfb14a61
parentfc802a58cff52083327b343ba04c9e67331d9d5a (diff)
Made Vector.Class functions inlinable
-rw-r--r--Spear/Math/Vector/Vector2.hs26
-rw-r--r--Spear/Math/Vector/Vector3.hs31
-rw-r--r--Spear/Math/Vector/Vector4.hs20
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
47 47
48 48
49instance VectorClass Vector2 where 49instance VectorClass Vector2 where
50 {-# INLINABLE fromList #-}
50 fromList (ax:ay:_) = Vector2 ax ay 51 fromList (ax:ay:_) = Vector2 ax ay
51 52
53 {-# INLINABLE x #-}
52 x (Vector2 ax _) = ax 54 x (Vector2 ax _) = ax
53 55
56 {-# INLINABLE y #-}
54 y (Vector2 _ ay) = ay 57 y (Vector2 _ ay) = ay
55 58
59 {-# INLINABLE (!) #-}
56 (Vector2 ax _) ! 0 = ax 60 (Vector2 ax _) ! 0 = ax
57 (Vector2 _ ay) ! 1 = ay 61 (Vector2 _ ay) ! 1 = ay
58 _ ! _ = 0 62 _ ! _ = 0
59 63
64 {-# INLINABLE dot #-}
60 Vector2 ax ay `dot` Vector2 bx by = ax*bx + ay*by 65 Vector2 ax ay `dot` Vector2 bx by = ax*bx + ay*by
61 66
67 {-# INLINABLE normSq #-}
62 normSq (Vector2 ax ay) = ax*ax + ay*ay 68 normSq (Vector2 ax ay) = ax*ax + ay*ay
63 69
70 {-# INLINABLE norm #-}
64 norm = sqrt . normSq 71 norm = sqrt . normSq
65 72
73 {-# INLINABLE scale #-}
66 scale s (Vector2 ax ay) = Vector2 (s*ax) (s*ay) 74 scale s (Vector2 ax ay) = Vector2 (s*ax) (s*ay)
67 75
76 {-# INLINABLE neg #-}
68 neg (Vector2 ax ay) = Vector2 (-ax) (-ay) 77 neg (Vector2 ax ay) = Vector2 (-ax) (-ay)
69 78
79 {-# INLINABLE normalise #-}
70 normalise v = 80 normalise v =
71 let n' = norm v 81 let n' = norm v
72 n = if n' == 0 then 1 else n' 82 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
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'
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
74 74
75 75
76instance VectorClass Vector4 where 76instance VectorClass Vector4 where
77 {-# INLINABLE fromList #-}
77 fromList (ax:ay:az:aw:_) = Vector4 ax ay az aw 78 fromList (ax:ay:az:aw:_) = Vector4 ax ay az aw
78 79
80 {-# INLINABLE x #-}
79 x (Vector4 ax _ _ _ ) = ax 81 x (Vector4 ax _ _ _ ) = ax
80 82
83 {-# INLINABLE y #-}
81 y (Vector4 _ ay _ _ ) = ay 84 y (Vector4 _ ay _ _ ) = ay
82 85
86 {-# INLINABLE z #-}
83 z (Vector4 _ _ az _ ) = az 87 z (Vector4 _ _ az _ ) = az
84
85 w (Vector4 _ _ _ aw) = aw
86 88
89 {-# INLINABLE w #-}
90 w (Vector4 _ _ _ aw) = aw
91
92 {-# INLINABLE (!) #-}
87 (Vector4 ax _ _ _) ! 0 = ax 93 (Vector4 ax _ _ _) ! 0 = ax
88 (Vector4 _ ay _ _) ! 1 = ay 94 (Vector4 _ ay _ _) ! 1 = ay
89 (Vector4 _ _ az _) ! 2 = az 95 (Vector4 _ _ az _) ! 2 = az
90 (Vector4 _ _ _ aw) ! 3 = aw 96 (Vector4 _ _ _ aw) ! 3 = aw
91 _ ! _ = 0 97 _ ! _ = 0
92 98
99 {-# INLINABLE dot #-}
93 Vector4 ax ay az aw `dot` Vector4 bx by bz bw = ax*bx + ay*by + az*bz + aw*bw 100 Vector4 ax ay az aw `dot` Vector4 bx by bz bw = ax*bx + ay*by + az*bz + aw*bw
94 101
102 {-# INLINABLE normSq #-}
95 normSq (Vector4 ax ay az aw) = ax*ax + ay*ay + az*az + aw*aw 103 normSq (Vector4 ax ay az aw) = ax*ax + ay*ay + az*az + aw*aw
96 104
105 {-# INLINABLE norm #-}
97 norm = sqrt . normSq 106 norm = sqrt . normSq
98 107
108 {-# INLINABLE scale #-}
99 scale s (Vector4 ax ay az aw) = Vector4 (s*ax) (s*ay) (s*az) (s*aw) 109 scale s (Vector4 ax ay az aw) = Vector4 (s*ax) (s*ay) (s*az) (s*aw)
100 110
111 {-# INLINABLE neg #-}
101 neg (Vector4 ax ay az aw) = Vector4 (-ax) (-ay) (-az) (-aw) 112 neg (Vector4 ax ay az aw) = Vector4 (-ax) (-ay) (-az) (-aw)
102 113
114 {-# INLINABLE normalise #-}
103 normalise v = 115 normalise v =
104 let n' = norm v 116 let n' = norm v
105 n = if n' == 0 then 1 else n' 117 n = if n' == 0 then 1 else n'