From b5877592035d59d1137a6469ed821e549058474d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 19 May 2013 22:02:55 +1000 Subject: [PATCH] Adjusted Vector2 --- common/vector2.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/vector2.hpp b/common/vector2.hpp index 1cd36aa..36c6186 100644 --- a/common/vector2.hpp +++ b/common/vector2.hpp @@ -27,10 +27,8 @@ class Vector2 { public: - double x, y; - Vector2() { - x = y = 0; - } + double x = 0, y = 0; + Vector2() = default; Vector2(double i, double j) { x = i; y = j; } @@ -40,11 +38,13 @@ public: double SquaredLength() const { return x*x+y*y; } + double operator[](size_t i) { if (i >= 2) throw(std::runtime_error("Out of range")); return *(&x+i); } + //Arithmetic operators Vector2 operator+(Vector2 v) const { return Vector2(x + v.x, y + v.y); } Vector2 operator-(Vector2 v) const { return Vector2(x - v.x, y - v.y); } @@ -65,6 +65,7 @@ public: bool operator==(Vector2 v) { return (x == v.x && y == v.y); } bool operator!=(Vector2 v) { return (x != v.x || y != v.y); } + //templates template Vector2 operator+=(T t) { return *this = *this + t; } template Vector2 operator-=(T t) { return *this = *this - t; } template Vector2 operator*=(T t) { return *this = *this * t; }