From c04291a3e476034467a86334ef99851b898264e5 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Wed, 1 Feb 2012 16:54:27 +0000 Subject: [PATCH] [Add] Adding a bunch of overloaded operators to vector stuff. --- src/libUnuk/System/Vec2.cpp | 42 +++++++++++++++++++++++++++++++++++-- src/libUnuk/System/Vec2.h | 1 + 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/libUnuk/System/Vec2.cpp b/src/libUnuk/System/Vec2.cpp index cabf65b..d8d7294 100644 --- a/src/libUnuk/System/Vec2.cpp +++ b/src/libUnuk/System/Vec2.cpp @@ -1,5 +1,3 @@ -#include - #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; +} diff --git a/src/libUnuk/System/Vec2.h b/src/libUnuk/System/Vec2.h index 893e2b0..208b34a 100644 --- a/src/libUnuk/System/Vec2.h +++ b/src/libUnuk/System/Vec2.h @@ -2,6 +2,7 @@ #pragma once #include +#include // A handy structure for passing around 2D integer coords. struct Vec2i {