[Add] Adding a bunch of overloaded operators to vector stuff.

This commit is contained in:
Rtch90 2012-02-01 16:54:27 +00:00
parent 2910f5cfd4
commit c04291a3e4
2 changed files with 41 additions and 2 deletions

View File

@ -1,5 +1,3 @@
#include <math.h>
#include "Vec2.h" #include "Vec2.h"
Vec2 Vec2::Zero(0.0f, 0.0f); Vec2 Vec2::Zero(0.0f, 0.0f);
@ -38,6 +36,14 @@ float Vec2::Distance(const Vec2& value1, const Vec2& value2) {
// Overload some operators.. // Overload some operators..
bool Vec2::operator==(const Vec2& v) const {
return x == v.x && y == v.y;
}
bool Vec2::operator!=(const Vec2& v) const {
return !(*this == v);
}
Vec2 Vec2::operator-(void) const { Vec2 Vec2::operator-(void) const {
return Vec2::Zero - *this; return Vec2::Zero - *this;
} }
@ -45,3 +51,35 @@ Vec2 Vec2::operator-(void) const {
Vec2 Vec2::operator-(const Vec2& v) const { Vec2 Vec2::operator-(const Vec2& v) const {
return Vec2(x - v.x, y - v.y); return Vec2(x - v.x, y - v.y);
} }
Vec2 Vec2::operator+(const Vec2& v) const {
return Vec2(x + v.x, y + v.y);
}
Vec2 Vec2::operator/(float divider) const {
return Vec2(x / divider, y / divider);
}
Vec2 Vec2::operator*(float scaleFactor) const {
return Vec2(x * scaleFactor, y * scaleFactor);
}
Vec2& Vec2::operator+=(const Vec2& v) {
x += v.x, y += v.y;
return *this;
}
Vec2& Vec2::operator-=(const Vec2& v) {
x -= v.x, y -= v.y;
return *this;
}
Vec2& Vec2::operator*=(float scaleFactor) {
x *= scaleFactor, y *= scaleFactor;
return *this;
}
Vec2& Vec2::operator/=(float scaleFactor) {
x /= scaleFactor, y /= scaleFactor;
return *this;
}

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <math.h>
// A handy structure for passing around 2D integer coords. // A handy structure for passing around 2D integer coords.
struct Vec2i { struct Vec2i {