diff mbox

[Branch,~jesse-barker/libmatrix/trunk] Rev 25: Add component-wise multiplication and division operators for vectors. Add

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

Commit Message

Jesse Barker Sept. 13, 2011, 6:10 p.m. UTC
------------------------------------------------------------
revno: 25
committer: Jesse Barker <jesse.barker@linaro.org>
branch nick: trunk
timestamp: Tue 2011-09-13 11:04:53 -0700
message:
  Add component-wise multiplication and division operators for vectors.  Add
  appropriate cases to the const vector test.
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 16:33:49 +0000
+++ test/const_vec_test.cc	2011-09-13 18:04:53 +0000
@@ -27,6 +27,8 @@ 
     const vec2 b(2.0, 2.0);
     vec2 aplusb(a + b);
     vec2 aminusb(a - b);
+    vec2 atimesb(a * b);
+    vec2 adivb(a / b);
 }
 
 void
@@ -36,6 +38,8 @@ 
     const vec3 b(2.0, 2.0, 2.0);
     vec3 aplusb(a + b);
     vec3 aminusb(a - b);
+    vec3 atimesb(a * b);
+    vec3 adivb(a / b);
 }
 
 void
@@ -45,4 +49,6 @@ 
     const vec4 b(2.0, 2.0, 2.0, 2.0);
     vec4 aplusb(a + b);
     vec4 aminusb(a - b);
+    vec4 atimesb(a * b);
+    vec4 adivb(a / b);
 }

=== modified file 'vec.h'
--- vec.h	2011-09-13 16:33:49 +0000
+++ vec.h	2011-09-13 18:04:53 +0000
@@ -1,5 +1,5 @@ 
 //
-// Copyright (c) 2010 Linaro Limited
+// Copyright (c) 2010-2011 Linaro Limited
 //
 // All rights reserved. This program and the accompanying materials
 // are made available under the terms of the MIT License which accompanies
@@ -69,6 +69,18 @@ 
         return tvec2(*this) /= rhs;
     }
 
+    tvec2& operator/=(const tvec2& rhs)
+    {
+        x_ /= rhs.x_;
+        y_ /= rhs.y_;
+        return *this;
+    }
+
+    const tvec2 operator/(const tvec2& rhs) const
+    {
+        return tvec2(*this) /= rhs;
+    }
+
     tvec2& operator*=(const T& rhs)
     {
         x_ *= rhs;
@@ -81,6 +93,18 @@ 
         return tvec2(*this) *= rhs;
     }
 
+    tvec2& operator*=(const tvec2& rhs)
+    {
+        x_ *= rhs.x_;
+        y_ *= rhs.y_;
+        return *this;
+    }
+
+    const tvec2 operator*(const tvec2& rhs) const
+    {
+        return tvec2(*this) *= rhs;
+    }
+
     tvec2& operator+=(const T& rhs)
     {
         x_ += rhs;
@@ -211,6 +235,19 @@ 
         return tvec3(*this) /= rhs;
     }
 
+    tvec3& operator/=(const tvec3& rhs)
+    {
+        x_ /= rhs.x_;
+        y_ /= rhs.y_;
+        z_ /= rhs.z_;
+        return *this;
+    }
+
+    const tvec3 operator/(const tvec3& rhs) const
+    {
+        return tvec3(*this) /= rhs;
+    }
+
     tvec3& operator*=(const T& rhs)
     {
         x_ *= rhs;
@@ -224,6 +261,19 @@ 
         return tvec3(*this) *= rhs;
     }
 
+    tvec3& operator*=(const tvec3& rhs)
+    {
+        x_ *= rhs.x_;
+        y_ *= rhs.y_;
+        z_ *= rhs.z_;
+        return *this;
+    }
+
+    const tvec3 operator*(const tvec3& rhs) const
+    {
+        return tvec3(*this) *= rhs;
+    }
+
     tvec3& operator+=(const T& rhs)
     {
         x_ += rhs;
@@ -375,6 +425,20 @@ 
         return tvec4(*this) /= rhs;
     }
 
+    tvec4& operator/=(const tvec4& rhs)
+    {
+        x_ /= rhs.x_;
+        y_ /= rhs.y_;
+        z_ /= rhs.z_;
+        w_ /= rhs.w_;
+        return *this;
+    }
+
+    const tvec4 operator/(const tvec4& rhs) const
+    {
+        return tvec4(*this) /= rhs;
+    }
+
     tvec4& operator*=(const T& rhs)
     {
         x_ *= rhs;
@@ -389,6 +453,20 @@ 
         return tvec4(*this) *= rhs;
     }
 
+    tvec4& operator*=(const tvec4& rhs)
+    {
+        x_ *= rhs.x_;
+        y_ *= rhs.y_;
+        z_ *= rhs.z_;
+        w_ *= rhs.w_;
+        return *this;
+    }
+
+    const tvec4 operator*(const tvec4& rhs) const
+    {
+        return tvec4(*this) *= rhs;
+    }
+
     tvec4& operator+=(const T& rhs)
     {
         x_ += rhs;