diff mbox

[Branch,~jesse-barker/libmatrix/trunk] Rev 26: Add global "operator*" to handle the case where the scalar is the left-hand

Message ID 20110922153713.11480.57949.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Jesse Barker Sept. 22, 2011, 3:37 p.m. UTC
------------------------------------------------------------
revno: 26
committer: Jesse Barker <jesse.barker@linaro.org>
branch nick: trunk
timestamp: Tue 2011-09-20 13:43:03 -0700
message:
  Add global "operator*" to handle the case where the scalar is the left-hand
  value when multiplying a scalar by a vector.
modified:
  test/const_vec_test.cc
  vec.h


--
lp:libmatrix
https://code.launchpad.net/~jesse-barker/libmatrix/trunk

You are subscribed to branch lp:libmatrix.
To unsubscribe from this branch go to https://code.launchpad.net/~jesse-barker/libmatrix/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'test/const_vec_test.cc'
--- test/const_vec_test.cc	2011-09-13 18:04:53 +0000
+++ test/const_vec_test.cc	2011-09-20 20:43:03 +0000
@@ -29,6 +29,8 @@ 
     vec2 aminusb(a - b);
     vec2 atimesb(a * b);
     vec2 adivb(a / b);
+    const float s(2.5);
+    vec2 stimesb(s * b);
 }
 
 void
@@ -40,6 +42,8 @@ 
     vec3 aminusb(a - b);
     vec3 atimesb(a * b);
     vec3 adivb(a / b);
+    const float s(2.5);
+    vec3 stimesb(s * b);
 }
 
 void
@@ -51,4 +55,6 @@ 
     vec4 aminusb(a - b);
     vec4 atimesb(a * b);
     vec4 adivb(a / b);
+    const float s(2.5);
+    vec4 stimesb(s * b);
 }

=== modified file 'vec.h'
--- vec.h	2011-09-13 18:04:53 +0000
+++ vec.h	2011-09-20 20:43:03 +0000
@@ -24,10 +24,10 @@ 
     tvec2() :
         x_(0),
         y_(0) {}
-    tvec2(T t) :
+    tvec2(const T t) :
         x_(t),
         y_(t) {}
-    tvec2(T x, T y) :
+    tvec2(const T x, const T y) :
         x_(x),
         y_(y) {}
     tvec2(const tvec2& v) :
@@ -183,11 +183,11 @@ 
         x_(0),
         y_(0),
         z_(0) {}
-    tvec3(T t) :
+    tvec3(const T t) :
         x_(t),
         y_(t),
         z_(t) {}
-    tvec3(T x, T y, T z) :
+    tvec3(const T x, const T y, const T z) :
         x_(x),
         y_(y),
         z_(z) {}
@@ -366,12 +366,12 @@ 
         y_(0),
         z_(0),
         w_(0) {}
-    tvec4(T t) :
+    tvec4(const T t) :
         x_(t),
         y_(t),
         z_(t),
         w_(t) {}
-    tvec4(T x, T y, T z, T w) :
+    tvec4(const T x, const T y, const T z, const T w) :
         x_(x),
         y_(y),
         z_(z),
@@ -575,4 +575,24 @@ 
 
 } // namespace LibMatrix
 
+// Global operators to allow for things like defining a new vector in terms of
+// a product of a scalar and a vector
+template<typename T>
+const LibMatrix::tvec2<T> operator*(const T t, const LibMatrix::tvec2<T>& v)
+{
+    return v * t;
+}
+
+template<typename T>
+const LibMatrix::tvec3<T> operator*(const T t, const LibMatrix::tvec3<T>& v)
+{
+    return v * t;
+}
+
+template<typename T>
+const LibMatrix::tvec4<T> operator*(const T t, const LibMatrix::tvec4<T>& v)
+{
+    return v * t;
+}
+
 #endif // VEC_H_