template class EE::Math::Vector2

Overview

Utility template class for manipulating 2-dimensional vectors. More…

#include <vector2.hpp>

template <typename T>
class Vector2 {
public:
    // fields

    static const Vector2<T> Zero = Vector2<T>(0, 0);
    static const Vector2<T> One = Vector2<T>(1, 1);
    T x;
    T y;

    // construction

    Vector2();
    Vector2(T X, T Y);
    Vector2(const Vector2<T>& copy);

    // methods

    Vector2<T> copy();
    T dot(const Vector2<T>& V2) const;
    T cross(const Vector2<T>& V2) const;
    Vector2<T> perp() const;
    Vector2<T> rPerp() const;
    Vector2<T> rotate(const Vector2<T>& V2) const;
    Vector2<T> unrotate(const Vector2<T>& V2) const;
    T length() const;
    T lengthSq() const;
    void normalize();
    void clamp(T len);
    Vector2<T> forAngle(const T& a) const;
    T toAngle();
    void rotate(const T& Angle);
    void rotate(const T& Angle, const Vector2<T>& RotationCenter);
    T distance(const Vector2<T>& Vec) const;
    T distanceSq(const Vector2<T>& Vec) const;
    bool nearDist(const Vector2<T>& Vec, T Dist) const;
    Vector2<T> sphericalLerp(const Vector2<T>& Vec, T Time) const;
    Vector2<T> sphericalLerpConst(const Vector2<T>& Vec, T Angle) const;
    Vector2<T> lerp(const Vector2<T>& Vec, T Time) const;
    Vector2<T> lerpConst(const Vector2<T>& Vec, T Dist) const;
    void scale(const Vector2<T>& scale, const Vector2<T>& Center);
    void scale(const T& scale, const Vector2<T>& Center);
    Vector2<T> ceil() const;
    Vector2<T> floor() const;
    Vector2<T> round() const;
    Vector2<T> roundUp() const;
    Vector2<T> roundDown() const;
    Vector2<T> abs() const;
    Vector2<Float> asFloat() const;
    Vector2<int> asInt() const;
    Vector2<T>& operator=(const Vector2<T>& right);
};

Detailed Documentation

Utility template class for manipulating 2-dimensional vectors.

Construction

Vector2()

Default constructor creates Vector2(0,0)

Vector2(T X, T Y)

Creates a vector from its coordinates

Methods

Vector2<T> copy()

Returns:

A copy of the Vector2

T dot(const Vector2<T>& V2) const

Returns:

The Dot product of the 2D vectors.

T cross(const Vector2<T>& V2) const

Returns:

The Cross product of the 2D vectors.

Vector2<T> perp() const

Returns:

The perpendicular vector

Vector2<T> rPerp() const

Returns:

The reveser perpendicular vector

Vector2<T> rotate(const Vector2<T>& V2) const

Uses complex multiplication to rotate self by vec. Scaling will occur if self is not a unit vector.

Vector2<T> unrotate(const Vector2<T>& V2) const

Inverse of Vector2::rotate

T length() const

Returns:

The vector Length

T lengthSq() const

Returns:

The square of the length of the 2D vector.

void normalize()

Normalize the vector

void clamp(T len)

Returns:

Clamp the vector to a magnitude length.

Vector2<T> forAngle(const T& a) const

Returns:

The unit length vector for the given angle (radians)

T toAngle()

Returns:

The angular direction vector is pointing in (radians).

void rotate(const T& Angle)

Rotates the vector

void rotate(const T& Angle, const Vector2<T>& RotationCenter)

Rotates the vector against a defined rotation center

T distance(const Vector2<T>& Vec) const

Returns:

The distance between two vectors

T distanceSq(const Vector2<T>& Vec) const

Returns:

The square of the distance between two vectors

bool nearDist(const Vector2<T>& Vec, T Dist) const

Returns:

True if the distance between the two vectors is less than Dist

Vector2<T> sphericalLerp(const Vector2<T>& Vec, T Time) const

Returns:

The spherical linear interpolation between two 2D vectors.

Vector2<T> sphericalLerpConst(const Vector2<T>& Vec, T Angle) const

Spherical linear interpolation between two vectors

Vector2<T> lerp(const Vector2<T>& Vec, T Time) const

Performs a linear interpolation between two 2D vectors.

Vector2<T> lerpConst(const Vector2<T>& Vec, T Dist) const

Returns:

A vector interpolated from self towards Vec with length Dist.

void scale(const Vector2<T>& scale, const Vector2<T>& Center)

Scales the vector position against another vector

void scale(const T& scale, const Vector2<T>& Center)

Scales the vector position against another vector