[Add] Adding a bunch of overloaded operators to vector stuff.
This commit is contained in:
parent
2910f5cfd4
commit
c04291a3e4
@ -1,5 +1,3 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "Vec2.h"
|
||||
|
||||
Vec2 Vec2::Zero(0.0f, 0.0f);
|
||||
@ -38,6 +36,14 @@ float Vec2::Distance(const Vec2& value1, const Vec2& value2) {
|
||||
|
||||
|
||||
// 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 {
|
||||
return Vec2::Zero - *this;
|
||||
}
|
||||
@ -45,3 +51,35 @@ Vec2 Vec2::operator-(void) const {
|
||||
Vec2 Vec2::operator-(const Vec2& v) const {
|
||||
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;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
|
||||
// A handy structure for passing around 2D integer coords.
|
||||
struct Vec2i {
|
||||
|
Loading…
Reference in New Issue
Block a user