Eule::Vector2< T > Class Template Reference

Representation of a 2d vector. More...

`#include <Vector2.h>`

## Public Member Functions

| Vector2 ()
| Vector2 (T _x, T _y)
| Vector2 (const Vector2< T > &other)=default
| Vector2 (Vector2< T > &&other) noexcept=default
double | DotProduct (const Vector2< T > &other) const
| Will compute the dot product to another Vector2. More...
double | CrossProduct (const Vector2< T > &other) const
| Will compute the cross product to another Vector2. More...
double | SqrMagnitude () const
| Will compute the square magnitude. More...
double | Magnitude () const
| Will compute the magnitude. More...
Vector2< double > | Normalize () const
| Will return the normalization of this vector. More...
void | NormalizeSelf ()
| Will normalize this vector. More...
Vector2< T > | VectorScale (const Vector2< T > &scalar) const
| Will scale self.n by scalar.n. More...
void | LerpSelf (const Vector2< T > &other, double t)
| Will lerp itself towards other by t. More...
Vector2< double > | Lerp (const Vector2< T > &other, double t) const
| Will return a lerp result between this and another vector. More...
bool | Similar (const Vector2< T > &other, double epsilon=0.00001) const
| Will compare if two vectors are similar to a certain epsilon value. More...
Vector2< int > | ToInt () const
| Will convert this vector to a Vector2i. More...
Vector2< double > | ToDouble () const
| Will convert this vector to a Vector2d. More...
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
| Conversion method. More...
void | operator= (const Vector2< T > &other)
| Conversion method. More...
void | operator= (Vector2< T > &&other) noexcept
bool | operator== (const Vector2< T > &other) const
bool | operator!= (const Vector2< T > &other) const

## Public Attributes

T | x
T | y

## Static Public Attributes

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

## Friends

std::ostream & | operator<< (std::ostream &os, const Vector2< T > &v)
std::wostream & | operator<< (std::wostream &os, const Vector2< T > &v)

## Detailed Description

### template<typename T>
class Eule::Vector2< T >

Representation of a 2d vector.

Contains a lot of utility methods.

Definition at line 14 of file Vector2.h.

## Constructor & Destructor Documentation

## Vector2() [1/4]

template<typename T >

Eule::Vector2< T >::Vector2 | ( |  | ) |

inline

Definition at line 17 of file Vector2.h.

: x{ 0 }, y{ 0 } {}

## Vector2() [2/4]

template<typename T >

Eule::Vector2< T >::Vector2 | ( | T | _x,
|  | T | _y
| ) |  |

inline

Definition at line 18 of file Vector2.h.

: x{ _x }, y{ _y } {}

## Vector2() [3/4]

template<typename T >

Eule::Vector2< T >::Vector2 | ( | const Vector2< T > & | other | ) |

default

## Vector2() [4/4]

template<typename T >

Eule::Vector2< T >::Vector2 | ( | Vector2< T > && | other | ) |

defaultnoexcept

## Member Function Documentation

## CrossProduct()

template<typename T >

double Vector2::CrossProduct | ( | const Vector2< T > & | other | ) | const

Will compute the cross product to another Vector2.

Definition at line 65 of file Vector2.cpp.

{
int iCross = (x * other.y) -
(y * other.x);
return (double)iCross;
}

## DotProduct()

template<typename T >

double Vector2::DotProduct | ( | const Vector2< T > & | other | ) | const

Will compute the dot product to another Vector2.

Definition at line 47 of file Vector2.cpp.

{
int iDot = (x * other.x) +
(y * other.y);
return (double)iDot;
}

## Lerp()

template<typename T >

Vector2< double > Vector2::Lerp | ( | const Vector2< T > & | other,
|  | double | t
| ) |  | const

Will return a lerp result between this and another vector.

Definition at line 256 of file Vector2.cpp.

{
Vector2d copy(this->ToDouble());
copy.LerpSelf(other.ToDouble(), t);
return copy;
}

## LerpSelf()

template<typename T >

void Vector2::LerpSelf | ( | const Vector2< T > & | other,
|  | double | t
| ) |  |

Will lerp itself towards other by t.

Definition at line 238 of file Vector2.cpp.

{
const double it = 1.0 - t; // Inverse t
x = (int)(it * (double)x + t * (double)other.x);
y = (int)(it * (double)y + t * (double)other.y);
return;
}

## Magnitude()

template<typename T >

double Vector2::Magnitude

Will compute the magnitude.

Definition at line 90 of file Vector2.cpp.

{
return sqrt(SqrMagnitude());
}

## Normalize()

template<typename T >

Vector2< double > Vector2::Normalize

Will return the normalization of this vector.

Definition at line 137 of file Vector2.cpp.

{
Vector2<double> norm(x, y);
norm.NormalizeSelf();
return norm;
}

## NormalizeSelf()

template<typename T >

void Vector2::NormalizeSelf | ( |  | ) |

Will normalize this vector.

Definition at line 187 of file Vector2.cpp.

{
std::cerr << "Stop normalizing int-vectors!!" << std::endl;
x = 0;
y = 0;
return;
}

## operator Vector3< T >()

template<typename T >

Vector2::operator Vector3< T >

Definition at line 674 of file Vector2.cpp.

{
return Vector3<T>(x, y, 0);
}

## operator Vector4< T >()

template<typename T >

Vector2::operator Vector4< T >

Conversion method.

Definition at line 680 of file Vector2.cpp.

{
return Vector4<T>(x, y, 0, 0);
}

## operator!=()

template<typename T >

bool Vector2::operator!= | ( | const Vector2< T > & | other | ) | const

Definition at line 656 of file Vector2.cpp.

{
return !operator==(other);
}

## operator*()

template<typename T >

Vector2< T > Vector2::operator* | ( | const T | scale | ) | const

Definition at line 503 of file Vector2.cpp.

{
return Vector2<T>(
x * scale,
y * scale
);
}

## operator*=()

template<typename T >

void Vector2::operator*= | ( | const T | scale | ) |

Definition at line 542 of file Vector2.cpp.

{
x *= scale;
y *= scale;
return;
}

## operator+()

template<typename T >

Vector2< T > Vector2::operator+ | ( | const Vector2< T > & | other | ) | const

Definition at line 346 of file Vector2.cpp.

{
return Vector2<T>(
x + other.x,
y + other.y
);
}

## operator+=()

template<typename T >

void Vector2::operator+= | ( | const Vector2< T > & | other | ) |

Definition at line 385 of file Vector2.cpp.

{
x += other.x;
y += other.y;
return;
}

## operator-() [1/2]

template<typename T >

Vector2< T > Vector2::operator-

Definition at line 662 of file Vector2.cpp.

{
return Vector2<T>(
-x,
-y
);
}

## operator-() [2/2]

template<typename T >

Vector2< T > Vector2::operator- | ( | const Vector2< T > & | other | ) | const

Definition at line 424 of file Vector2.cpp.

{
return Vector2<T>(
x - other.x,
y - other.y
);
}

## operator-=()

template<typename T >

void Vector2::operator-= | ( | const Vector2< T > & | other | ) |

Definition at line 463 of file Vector2.cpp.

{
x -= other.x;
y -= other.y;
return;
}

## operator/()

template<typename T >

Vector2< T > Vector2::operator/ | ( | const T | scale | ) | const

Definition at line 582 of file Vector2.cpp.

{
return Vector2<T>(
x / scale,
y / scale
);
}

## operator/=()

template<typename T >

void Vector2::operator/= | ( | const T | scale | ) |

Definition at line 620 of file Vector2.cpp.

{
x /= scale;
y /= scale;
return;
}

## operator=() [1/2]

template<typename T >

void Vector2::operator= | ( | const Vector2< T > & | other | ) |

Conversion method.

Definition at line 630 of file Vector2.cpp.

{
x = other.x;
y = other.y;
return;
}

## operator=() [2/2]

template<typename T >

void Vector2::operator= | ( | Vector2< T > && | other | ) |

noexcept

Definition at line 639 of file Vector2.cpp.

{
x = std::move(other.x);
y = std::move(other.y);
return;
}

## operator==()

template<typename T >

bool Vector2::operator== | ( | const Vector2< T > & | other | ) | const

Definition at line 648 of file Vector2.cpp.

{
return
(x == other.x) &&
(y == other.y);
}

## operator[]() [1/2]

template<typename T >

T & Vector2::operator[] | ( | std::size_t | idx | ) |

Definition at line 267 of file Vector2.cpp.

{
switch (idx)
{
case 0:
return x;
case 1:
return y;
default:
throw std::out_of_range("Array descriptor on Vector2<T> out of range!");
}
}

## operator[]() [2/2]

template<typename T >

const T & Vector2::operator[] | ( | std::size_t | idx | ) | const

Definition at line 281 of file Vector2.cpp.

{
switch (idx)
{
case 0:
return x;
case 1:
return y;
default:
throw std::out_of_range("Array descriptor on Vector2<T> out of range!");
}
}

## Similar()

template<typename T >

bool Vector2::Similar | ( | const Vector2< T > & | other,
|  | double | epsilon = `0.00001`
| ) |  | const

Will compare if two vectors are similar to a certain epsilon value.

Definition at line 295 of file Vector2.cpp.

{
return
(::Math::Similar(x, other.x, epsilon)) &&
(::Math::Similar(y, other.y, epsilon))
;
}

## SqrMagnitude()

template<typename T >

double Vector2::SqrMagnitude | ( |  | ) | const

Will compute the square magnitude.

Definition at line 83 of file Vector2.cpp.

{
int iSqrMag = x*x + y*y;
return (double)iSqrMag;
}

## ToDouble()

template<typename T >

Vector2< double > Vector2::ToDouble

Will convert this vector to a Vector2d.

Definition at line 310 of file Vector2.cpp.

{
return Vector2<double>((double)x, (double)y);
}

## ToInt()

template<typename T >

Vector2< int > Vector2::ToInt

Will convert this vector to a Vector2i.

Definition at line 304 of file Vector2.cpp.

{
return Vector2<int>((int)x, (int)y);
}

## VectorScale()

template<typename T >

Vector2< int > Vector2::VectorScale | ( | const Vector2< T > & | scalar | ) | const

Will scale self.n by scalar.n.

Definition at line 127 of file Vector2.cpp.

{
return Vector2<int>(
x * scalar.x,
y * scalar.y
);
}

## Friends And Related Function Documentation

## operator<< [1/2]

template<typename T >

std::ostream& operator<< | ( | std::ostream & | os,
|  | const Vector2< T > & | v
| ) |  |

friend

Definition at line 80 of file Vector2.h.

{
return os << "[x: " << v.x << " y: " << v.y << "]";
}

## operator<< [2/2]

template<typename T >

std::wostream& operator<< | ( | std::wostream & | os,
|  | const Vector2< T > & | v
| ) |  |

friend

Definition at line 84 of file Vector2.h.

{
return os << L"[x: " << v.x << L" y: " << v.y << L"]";
}

## Member Data Documentation

## down

template<typename T >

const Vector2< double > Vector2::down

static

Definition at line 94 of file Vector2.h.

## left

template<typename T >

const Vector2< double > Vector2::left

static

Definition at line 96 of file Vector2.h.

## one

template<typename T >

const Vector2< double > Vector2::one

static

Definition at line 97 of file Vector2.h.

## right

template<typename T >

const Vector2< double > Vector2::right

static

Definition at line 95 of file Vector2.h.

## up

template<typename T >

const Vector2< double > Vector2::up

static

Definition at line 93 of file Vector2.h.

## x

template<typename T >

T Eule::Vector2< T >::x

Definition at line 89 of file Vector2.h.

## y

template<typename T >

T Eule::Vector2< T >::y

Definition at line 90 of file Vector2.h.

## zero

template<typename T >

const Vector2< double > Vector2::zero

static

Definition at line 98 of file Vector2.h.

The documentation for this class was generated from the following files:

- Eule/Vector2.h
- Eule/Vector2.cpp

Eule::Vector3
Representation of a 3d vector.
Definition: Matrix4x4.h:9
Eule::Vector2::SqrMagnitude
double SqrMagnitude() const
Will compute the square magnitude.
Definition: Vector2.cpp:83
Eule::Vector2::ToDouble
Vector2< double > ToDouble() const
Will convert this vector to a Vector2d.
Definition: Vector2.cpp:310
Eule::Vector2< double >
Eule::Vector2::x
T x
Definition: Vector2.h:89
Eule::Vector2::y
T y
Definition: Vector2.h:90
Eule::Math::Similar
static constexpr bool Similar(const double a, const double b, const double epsilon=0.00001)
Compares two double values with a given accuracy.
Eule::Vector2::operator==
bool operator==(const Vector2< T > &other) const
Definition: Vector2.cpp:648
Eule::Vector4
Representation of a 4d vector.
Definition: Vector2.h:8