2017-10-31 17:12:50 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef ES_CORE_MATH_VECTOR2I_H
|
|
|
|
#define ES_CORE_MATH_VECTOR2I_H
|
2017-10-28 20:24:35 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
class Vector2i
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-11-13 22:16:38 +00:00
|
|
|
Vector2i() { }
|
|
|
|
Vector2i(const int _i) : mX(_i), mY(_i) { }
|
|
|
|
Vector2i(const int _x, const int _y) : mX(_x), mY(_y) { }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
const bool operator==(const Vector2i& _other) const { return ((mX == _other.mX) && (mY == _other.mY)); }
|
|
|
|
const bool operator!=(const Vector2i& _other) const { return ((mX != _other.mX) || (mY != _other.mY)); }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
const Vector2i operator+ (const Vector2i& _other) const { return { mX + _other.mX, mY + _other.mY }; }
|
|
|
|
const Vector2i operator- (const Vector2i& _other) const { return { mX - _other.mX, mY - _other.mY }; }
|
|
|
|
const Vector2i operator* (const Vector2i& _other) const { return { mX * _other.mX, mY * _other.mY }; }
|
|
|
|
const Vector2i operator/ (const Vector2i& _other) const { return { mX / _other.mX, mY / _other.mY }; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
const Vector2i operator+ (const int& _other) const { return { mX + _other, mY + _other }; }
|
|
|
|
const Vector2i operator- (const int& _other) const { return { mX - _other, mY - _other }; }
|
|
|
|
const Vector2i operator* (const int& _other) const { return { mX * _other, mY * _other }; }
|
|
|
|
const Vector2i operator/ (const int& _other) const { return { mX / _other, mY / _other }; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
const Vector2i operator- () const { return { -mX , -mY }; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
Vector2i& operator+=(const Vector2i& _other) { *this = *this + _other; return *this; }
|
|
|
|
Vector2i& operator-=(const Vector2i& _other) { *this = *this - _other; return *this; }
|
|
|
|
Vector2i& operator*=(const Vector2i& _other) { *this = *this * _other; return *this; }
|
|
|
|
Vector2i& operator/=(const Vector2i& _other) { *this = *this / _other; return *this; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
Vector2i& operator+=(const int& _other) { *this = *this + _other; return *this; }
|
|
|
|
Vector2i& operator-=(const int& _other) { *this = *this - _other; return *this; }
|
|
|
|
Vector2i& operator*=(const int& _other) { *this = *this * _other; return *this; }
|
|
|
|
Vector2i& operator/=(const int& _other) { *this = *this / _other; return *this; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
int& operator[](const int _index) { assert(_index < 2 && "index out of range"); return (&mX)[_index]; }
|
|
|
|
const int& operator[](const int _index) const { assert(_index < 2 && "index out of range"); return (&mX)[_index]; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
|
|
|
int& x() { return mX; }
|
|
|
|
int& y() { return mY; }
|
|
|
|
const int& x() const { return mX; }
|
|
|
|
const int& y() const { return mY; }
|
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
static const Vector2i Zero () { return { 0, 0 }; }
|
2017-10-28 20:24:35 +00:00
|
|
|
static const Vector2i UnitX() { return { 1, 0 }; }
|
|
|
|
static const Vector2i UnitY() { return { 0, 1 }; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
int mX;
|
|
|
|
int mY;
|
|
|
|
|
2017-11-13 22:16:38 +00:00
|
|
|
}; // Vector2i
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_MATH_VECTOR2I_H
|