Permalink
Browse files

Add zero and negate for individual components

  • Loading branch information...
1 parent b0a5eef commit ce371872bed7c967b54a45be8abdfc5b47a79d45 @mightcouldb1 committed Feb 21, 2012
Showing with 26 additions and 2 deletions.
  1. +26 −2 solver/Vector2.h
View
@@ -13,7 +13,11 @@ class Vector2 {
// Vector math operators
Vector2& zero();
- Vector2 negate();
+ Vector2& zeroX();
+ Vector2& zeroY();
+ Vector2 negate() const;
+ Vector2 negateX() const;
+ Vector2 negateY() const;
float magnitude() const;
Vector2 unit() const;
Vector2& normalize();
@@ -43,11 +47,31 @@ Vector2& Vector2::zero()
x = y = 0.0f;
}
-Vector2 Vector2::negate()
+Vector2& Vector2::zeroX()
+{
+ x = 0.0f;
+}
+
+Vector2& Vector2::zeroY()
+{
+ y = 0.0f;
+}
+
+Vector2 Vector2::negate() const
{
return Vector2(x, y) * -1.0f;
}
+Vector2 Vector2::negateX() const
+{
+ return Vector2(x * -1.0f, y);
+}
+
+Vector2 Vector2::negateY() const
+{
+ return Vector2(x, y * -1.0f);
+}
+
float Vector2::magnitude() const
{
return sqrt(x * x + y * y);

0 comments on commit ce37187

Please sign in to comment.