Vector2.h
Go to the documentation of this file.
#pragma once
#include <cstdlib>
#include <sstream>
namespace Eule
{
template <typename T> class Vector3;
template <typename T> class Vector4;
template <typename T>
class Vector2
{
public:
Vector2() : x{ 0 }, y{ 0 } {}
Vector2(T _x, T _y) : x{ _x }, y{ _y } {}
Vector2(const Vector2<T>& other) = default;
Vector2(Vector2<T>&& other) noexcept = default;
double DotProduct(const Vector2<T>& other) const;
double CrossProduct(const Vector2<T>& other) const;
double SqrMagnitude() const;
double Magnitude() const;
[[nodiscard]] Vector2<double> Normalize() const;
void NormalizeSelf();
Vector2<T> VectorScale(const Vector2<T>& scalar) const;
void LerpSelf(const Vector2<T>& other, double t);
[[nodiscard]] Vector2<double> Lerp(const Vector2<T>& other, double t) const;
[[nodiscard]] bool Similar(const Vector2<T>& other, double epsilon = 0.00001) const;
[[nodiscard]] Vector2<int> ToInt() const;
[[nodiscard]] Vector2<double> ToDouble() const;
T& operator[](std::size_t idx);
const T& operator[](std::size_t idx) const;
Vector2<T> operator+(const Vector2<T>& other) const;
void operator+=(const Vector2<T>& other);
Vector2<T> operator-(const Vector2<T>& other) const;
void operator-=(const Vector2<T>& other);
Vector2<T> operator*(const T scale) const;
void operator*=(const T scale);
Vector2<T> operator/(const T scale) const;
void operator/=(const T scale);
Vector2<T> operator-() const;
operator Vector3<T>() const;
operator Vector4<T>() const;
void operator=(const Vector2<T>& other);
void operator=(Vector2<T>&& other) noexcept;
bool operator==(const Vector2<T>& other) const;
bool operator!=(const Vector2<T>& other) const;
friend std::ostream& operator<< (std::ostream& os, const Vector2<T>& v)
{
return os << "[x: " << v.x << " y: " << v.y << "]";
}
friend std::wostream& operator<< (std::wostream& os, const Vector2<T>& v)
{
return os << L"[x: " << v.x << L" y: " << v.y << L"]";
}
T x;
T y;
// Some handy predefines
static const Vector2<double> up;
static const Vector2<double> down;
static const Vector2<double> right;
static const Vector2<double> left;
static const Vector2<double> one;
static const Vector2<double> zero;
};
typedef Vector2<int> Vector2i;
typedef Vector2<double> Vector2d;
}
Eule::Vector2::Normalize
Vector2< double > Normalize() const
Will return the normalization of this vector.
Definition: Vector2.cpp:137
Eule::Vector2::operator!=
bool operator!=(const Vector2< T > &other) const
Definition: Vector2.cpp:656
Eule::Vector2::Vector2
Vector2()
Definition: Vector2.h:17
Eule::Vector2::operator+
Vector2< T > operator+(const Vector2< T > &other) const
Definition: Vector2.cpp:346
Eule::Vector2::operator+=
void operator+=(const Vector2< T > &other)
Definition: Vector2.cpp:385
Eule::Vector2::DotProduct
double DotProduct(const Vector2< T > &other) const
Will compute the dot product to another Vector2.
Definition: Vector2.cpp:47
Eule::Vector2::left
static const Vector2< double > left
Definition: Vector2.h:96
Eule::Vector2::up
static const Vector2< double > up
Definition: Vector2.h:93
Eule::Vector2::Magnitude
double Magnitude() const
Will compute the magnitude.
Definition: Vector2.cpp:90
Eule::Vector2::operator*=
void operator*=(const T scale)
Definition: Vector2.cpp:542
Eule::Vector2::operator/
Vector2< T > operator/(const T scale) const
Definition: Vector2.cpp:582
Eule::Vector2::zero
static const Vector2< double > zero
Definition: Vector2.h:98
Eule::Vector2::VectorScale
Vector2< T > VectorScale(const Vector2< T > &scalar) const
Will scale self.n by scalar.n.
Definition: Vector2.cpp:127
Eule::Vector2::ToInt
Vector2< int > ToInt() const
Will convert this vector to a Vector2i.
Definition: Vector2.cpp:304
Eule::Vector2::Vector2
Vector2(T _x, T _y)
Definition: Vector2.h:18
Eule::Vector2::operator[]
T & operator[](std::size_t idx)
Definition: Vector2.cpp:267
Eule::Vector2::one
static const Vector2< double > one
Definition: Vector2.h:97
Eule::Vector2::operator*
Vector2< T > operator*(const T scale) const
Definition: Vector2.cpp:503
Eule::Vector2::operator/=
void operator/=(const T scale)
Definition: Vector2.cpp:620
Eule::Vector2::SqrMagnitude
double SqrMagnitude() const
Will compute the square magnitude.
Definition: Vector2.cpp:83
Eule::Vector2::Lerp
Vector2< double > Lerp(const Vector2< T > &other, double t) const
Will return a lerp result between this and another vector.
Definition: Vector2.cpp:256
Eule::Vector2::CrossProduct
double CrossProduct(const Vector2< T > &other) const
Will compute the cross product to another Vector2.
Definition: Vector2.cpp:65
Eule::Vector2::ToDouble
Vector2< double > ToDouble() const
Will convert this vector to a Vector2d.
Definition: Vector2.cpp:310
Eule::Vector2::NormalizeSelf
void NormalizeSelf()
Will normalize this vector.
Definition: Vector2.cpp:187
Eule::Vector2::operator-
Vector2< T > operator-() const
Definition: Vector2.cpp:662
Eule::Vector2::operator<<
friend std::ostream & operator<<(std::ostream &os, const Vector2< T > &v)
Definition: Vector2.h:80
Eule::Vector2
Representation of a 2d vector.
Definition: Vector2.h:14
Eule::Vector2d
Vector2< double > Vector2d
Definition: Vector2.h:102
Eule::Vector2::operator=
void operator=(const Vector2< T > &other)
Conversion method.
Definition: Vector2.cpp:630
Eule::Vector2::x
T x
Definition: Vector2.h:89
Eule::Vector2::y
T y
Definition: Vector2.h:90
Eule::Vector2::Similar
bool Similar(const Vector2< T > &other, double epsilon=0.00001) const
Will compare if two vectors are similar to a certain epsilon value.
Definition: Vector2.cpp:295
Eule::Vector2::right
static const Vector2< double > right
Definition: Vector2.h:95
Eule::Vector2::operator-=
void operator-=(const Vector2< T > &other)
Definition: Vector2.cpp:463
Eule::Vector2::down
static const Vector2< double > down
Definition: Vector2.h:94
Eule::Vector2::operator==
bool operator==(const Vector2< T > &other) const
Definition: Vector2.cpp:648
Eule
Definition: Collider.h:4
Eule::Vector2::LerpSelf
void LerpSelf(const Vector2< T > &other, double t)
Will lerp itself towards other by t.
Definition: Vector2.cpp:238
Eule::Vector4
Representation of a 4d vector.
Definition: Vector2.h:8
Eule::Vector2i
Vector2< int > Vector2i
Definition: Vector2.h:101