RML::Vector2D struct

A vector in 2D.

Constructors, destructors, conversion operators

Vector2D()
Default constructor Initialises a Vector2D with (0,0)
Vector2D(const float& x, const float& y)
Constructor.

Public functions

auto roundTo(const float& pivotX, const float& errorX, const float& pivotY, const float& errorY) -> Vector2D&
Rounds the coordinates to the pivot values for X and Y within the ranges of the error values.
auto getLength(Vector2D& vector) const -> float
Gets length of vector.
auto getLength() const -> float
Gets length of this vector.
auto toUnitVector() -> Vector2D
Convert this to a unit vector.
auto maxVector(const Vector2D& other) -> Vector2D
Returns a Vector2D with only the maximum coordinates on each axes as compared to the given other.
auto abs() -> Vector2D&
Take modulus of all coordinates.
auto multiplyCross(const Vector2D& other) -> float
Multiplies the given other (Cross product).
auto add(const Vector2D& other) -> Vector2D&
Adds other.
auto subtract(const Vector2D& other) -> Vector2D
Subtracts the given other.
auto multiply(const Vector2D& other) -> Vector2D&
Multiplies the given other.
auto multiplyDot(const Vector2D& other) -> float
Multiplies the given other vector (Dot product)
auto multiplyFloat(const float& other) -> Vector2D&
Scale all values of this vector by a float.
auto divide(const Vector2D& other) -> Vector2D&
Divides each element of this vector one by one by the corresponding vector of the other vector. Returns [a/x , b/y] if [a , b] is divided by [x , y].
auto operator==(const Vector2D& other) -> bool
Equality operator.
auto operator!=(const Vector2D& other) -> bool
Inequality operator.
auto operator+=(const Vector2D& other) -> Vector2D&
Addition assignment operator.
auto operator-=(const Vector2D& other) -> Vector2D
Subtraction assignment operator.
auto operator*=(const Vector2D& other) -> Vector2D&
Multiplication assignment operator.
auto operator/=(const Vector2D& other) -> Vector2D&
Division assignment operator.

Public variables

float x
The x coordinate.
float y
The y coordinate.

Friends

auto operator<<(std::ostream& stream, const Vector2D& vector) -> std::ostream&
Put to operator.
auto operator+(Vector2D left, const Vector2D& right) -> Vector2D&
Addition operator.
auto operator-(Vector2D left, const Vector2D& right) -> Vector2D
Subtraction operator.
auto operator*(Vector2D left, const Vector2D& right) -> Vector2D&
Multiplication operator.
auto operator*(Vector2D left, const float& right) -> Vector2D&
Float multiplication operator.
auto operator*(Vector2D& left, const Vector2D& right) -> float
Dot multiplication operator.
auto operator/(Vector2D left, const Vector2D& right) -> Vector2D&
Division operator.

Function documentation

RML::Vector2D::Vector2D(const float& x, const float& y)

Constructor.

Parameters
x The x coordinate.
y The y coordinate.

Vector2D& RML::Vector2D::roundTo(const float& pivotX, const float& errorX, const float& pivotY, const float& errorY)

Rounds the coordinates to the pivot values for X and Y within the ranges of the error values.

Parameters
pivotX The X pivot.
errorX The X error for pivot.
pivotY The Y pivot.
errorY The Y error for pivot.

float RML::Vector2D::getLength(Vector2D& vector) const

Gets length of vector.

Parameters
vector in/out The vector.
Returns The length.

float RML::Vector2D::getLength() const

Gets length of this vector.

Returns The length.

Vector2D RML::Vector2D::toUnitVector()

Convert this to a unit vector.

Returns The normalised vector.

Vector2D RML::Vector2D::maxVector(const Vector2D& other)

Returns a Vector2D with only the maximum coordinates on each axes as compared to the given other.

Parameters
other The other.
Returns A reference to a Vector2D.

Vector2D& RML::Vector2D::abs()

Take modulus of all coordinates.

Returns The abs vector.

float RML::Vector2D::multiplyCross(const Vector2D& other)

Multiplies the given other (Cross product).

Parameters
other The other.
Returns A result of the operation.

Vector2D& RML::Vector2D::add(const Vector2D& other)

Adds other.

Parameters
other The other to add.
Returns A reference to a Vector2D.

Vector2D RML::Vector2D::subtract(const Vector2D& other)

Subtracts the given other.

Parameters
other The other.
Returns A reference to a Vector2D.

Vector2D& RML::Vector2D::multiply(const Vector2D& other)

Multiplies the given other.

Parameters
other The other.
Returns A reference to a Vector2D.

float RML::Vector2D::multiplyDot(const Vector2D& other)

Multiplies the given other vector (Dot product)

Parameters
other The other.
Returns A dot product result.

Vector2D& RML::Vector2D::multiplyFloat(const float& other)

Scale all values of this vector by a float.

Parameters
other The other.
Returns Scaled version of this vector.

Vector2D& RML::Vector2D::divide(const Vector2D& other)

Divides each element of this vector one by one by the corresponding vector of the other vector. Returns [a/x , b/y] if [a , b] is divided by [x , y].

Parameters
other The other.
Returns A reference to a Vector2D.

bool RML::Vector2D::operator==(const Vector2D& other)

Equality operator.

Parameters
other The other.
Returns True if the parameters are considered equivalent.

bool RML::Vector2D::operator!=(const Vector2D& other)

Inequality operator.

Parameters
other The other.
Returns True if the parameters are not considered equivalent.

Vector2D& RML::Vector2D::operator+=(const Vector2D& other)

Addition assignment operator.

Parameters
other The other.
Returns The result of the operation.

Vector2D RML::Vector2D::operator-=(const Vector2D& other)

Subtraction assignment operator.

Parameters
other The other.
Returns The result of the operation.

Vector2D& RML::Vector2D::operator*=(const Vector2D& other)

Multiplication assignment operator.

Parameters
other The other.
Returns The result of the operation.

Vector2D& RML::Vector2D::operator/=(const Vector2D& other)

Division assignment operator.

Parameters
other The other.
Returns The result of the operation.

std::ostream& operator<<(std::ostream& stream, const Vector2D& vector)

Put to operator.

Parameters
stream The output stream.
vector The vector to be put to stream.
Returns The result of the operation.

Vector2D& operator+(Vector2D left, const Vector2D& right)

Addition operator.

Parameters
left The left operand.
right The right operand.
Returns The result of the operation.

Vector2D operator-(Vector2D left, const Vector2D& right)

Subtraction operator.

Parameters
left The left operand.
right The right operand.
Returns The result of the operation.

Vector2D& operator*(Vector2D left, const Vector2D& right)

Multiplication operator.

Parameters
left The left operand.
right The right operand.
Returns The result of the operation.

Vector2D& operator*(Vector2D left, const float& right)

Float multiplication operator.

Parameters
left The left operand.
right The right operand.
Returns The result of the operation.

float operator*(Vector2D& left, const Vector2D& right)

Dot multiplication operator.

Parameters
left The left operand.
right The right operand.
Returns The result of the dot operation.

Vector2D& operator/(Vector2D left, const Vector2D& right)

Division operator.

Parameters
left The left operand.
right The right operand.
Returns The result of the operation.