2017-10-31 17:12:50 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef ES_CORE_MATH_VECTOR2F_H
|
|
|
|
#define ES_CORE_MATH_VECTOR2F_H
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-13 22:16:38 +00:00
|
|
|
#include "math/Misc.h"
|
2017-10-28 20:24:35 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
class Vector3f;
|
|
|
|
class Vector4f;
|
|
|
|
|
|
|
|
class Vector2f
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-11-13 22:16:38 +00:00
|
|
|
Vector2f() { }
|
|
|
|
Vector2f(const float _f) : mX(_f), mY(_f) { }
|
|
|
|
Vector2f(const float _x, const float _y) : mX(_x), mY(_y) { }
|
|
|
|
explicit Vector2f(const Vector3f& _v) : mX(((Vector2f&)_v).mX), mY(((Vector2f&)_v).mY) { }
|
|
|
|
explicit Vector2f(const Vector4f& _v) : mX(((Vector2f&)_v).mX), mY(((Vector2f&)_v).mY) { }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
const bool operator==(const Vector2f& _other) const { return ((mX == _other.mX) && (mY == _other.mY)); }
|
|
|
|
const bool operator!=(const Vector2f& _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 Vector2f operator+ (const Vector2f& _other) const { return { mX + _other.mX, mY + _other.mY }; }
|
|
|
|
const Vector2f operator- (const Vector2f& _other) const { return { mX - _other.mX, mY - _other.mY }; }
|
|
|
|
const Vector2f operator* (const Vector2f& _other) const { return { mX * _other.mX, mY * _other.mY }; }
|
|
|
|
const Vector2f operator/ (const Vector2f& _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 Vector2f operator+ (const float& _other) const { return { mX + _other, mY + _other }; }
|
|
|
|
const Vector2f operator- (const float& _other) const { return { mX - _other, mY - _other }; }
|
|
|
|
const Vector2f operator* (const float& _other) const { return { mX * _other, mY * _other }; }
|
|
|
|
const Vector2f operator/ (const float& _other) const { return { mX / _other, mY / _other }; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
const Vector2f operator- () const { return { -mX , -mY }; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
Vector2f& operator+=(const Vector2f& _other) { *this = *this + _other; return *this; }
|
|
|
|
Vector2f& operator-=(const Vector2f& _other) { *this = *this - _other; return *this; }
|
|
|
|
Vector2f& operator*=(const Vector2f& _other) { *this = *this * _other; return *this; }
|
|
|
|
Vector2f& operator/=(const Vector2f& _other) { *this = *this / _other; return *this; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
Vector2f& operator+=(const float& _other) { *this = *this + _other; return *this; }
|
|
|
|
Vector2f& operator-=(const float& _other) { *this = *this - _other; return *this; }
|
|
|
|
Vector2f& operator*=(const float& _other) { *this = *this * _other; return *this; }
|
|
|
|
Vector2f& operator/=(const float& _other) { *this = *this / _other; return *this; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
float& operator[](const int _index) { assert(_index < 2 && "index out of range"); return (&mX)[_index]; }
|
|
|
|
const float& operator[](const int _index) const { assert(_index < 2 && "index out of range"); return (&mX)[_index]; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2018-02-15 14:05:47 +00:00
|
|
|
inline float& x() { return mX; }
|
|
|
|
inline float& y() { return mY; }
|
|
|
|
inline const float& x() const { return mX; }
|
|
|
|
inline const float& y() const { return mY; }
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-13 22:16:38 +00:00
|
|
|
Vector2f& round();
|
2017-11-22 21:29:52 +00:00
|
|
|
Vector2f& lerp (const Vector2f& _start, const Vector2f& _end, const float _fraction);
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-11-22 21:29:52 +00:00
|
|
|
static const Vector2f Zero () { return { 0, 0 }; }
|
2017-10-28 20:24:35 +00:00
|
|
|
static const Vector2f UnitX() { return { 1, 0 }; }
|
|
|
|
static const Vector2f UnitY() { return { 0, 1 }; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
float mX;
|
|
|
|
float mY;
|
|
|
|
|
2017-11-13 22:16:38 +00:00
|
|
|
}; // Vector2f
|
2017-10-28 20:24:35 +00:00
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_MATH_VECTOR2F_H
|