Kanzi 4.0.0-beta2
kanzi::Vector2 Class Reference

Vector with 2 floating point components: (x, y). More...

#include <kanzi/core/math/vector2.hpp>

Public Member Functions

constexpr float getX () const
 Returns the x element of the vector.
 
constexpr float getY () const
 Returns the y element of the vector.
 
bool hasNan () const
 Returns true if and only if at least one of the vector values is NaN.
 
float length () const
 Calculates the length a vectors.
 
KZ_NO_DISCARD Vector2 normalized () const
 Normalizes the vector and returns the resulting vector.
 
constexpr Vector2operator*= (float scalar)
 Multiplies each vector element with a scalar.
 
constexpr Vector2operator+= (float scalar)
 Adds a scalar to each vector element.
 
constexpr Vector2operator+= (Vector2 v)
 Modifies this vector by adding another vector.
 
constexpr Vector2operator-= (Vector2 v)
 Modifies this vector by subtracting another vector from this vector.
 
constexpr Vector2operator/= (float scalar)
 Divides each vector element with a scalar.
 
constexpr floatoperator[] (size_t index)
 Access to individual elements of the vector.
 
constexpr const floatoperator[] (size_t index) const
 Access to individual elements of a vector.
 
constexpr void setX (float value)
 Sets the x element of the vector.
 
constexpr void setY (float value)
 Sets the y element of the vector.
 
constexpr float squaredLength () const
 Calculates the squared length a vectors.
 
constexpr Vector2 ()
 Default constructor.
 
constexpr Vector2 (float v)
 Constructor.
 
constexpr Vector2 (float x, float y)
 Constructor.
 

Static Public Member Functions

static constexpr Vector2 createFromVector3 (Vector3 v)
 Creates a Vector2 from Vector3 by dropping the z-coordinate.
 
static constexpr Vector2 highestValue ()
 Returns the vector with each element having the most positive float value.
 
static constexpr Vector2 lowestValue ()
 Returns the vector with each element having the most negative float value.
 
static constexpr Vector2 nan ()
 Returns the vector with each element being NaN.
 
static constexpr Vector2 negativeInfinity ()
 Returns the vector with each element being the negative infinity.
 
static KZ_NO_DISCARD constexpr Vector2 one ()
 Returns the vector with each element being one.
 
static constexpr Vector2 positiveInfinity ()
 Returns the vector with each element being the positive infinity.
 
static KZ_NO_DISCARD constexpr Vector2 zero ()
 Returns the vector with each element being zero.
 

Detailed Description

Vector with 2 floating point components: (x, y).

Constructor & Destructor Documentation

◆ Vector2() [1/3]

constexpr kanzi::Vector2::Vector2 ( )
inlineexplicitconstexpr

Default constructor.

Initializes a vector to (0.0, 0.0).

◆ Vector2() [2/3]

constexpr kanzi::Vector2::Vector2 ( float x,
float y )
inlineexplicitconstexpr

Constructor.

Initializes a vector to (x, y).

Parameters
xX coefficient of a vector.
yY coefficient of a vector.

◆ Vector2() [3/3]

constexpr kanzi::Vector2::Vector2 ( float v)
inlineexplicitconstexpr

Constructor.

Initializes a vector to (v, v).

Parameters
vX and Y coefficients of a vector.

Member Function Documentation

◆ operator[]() [1/2]

constexpr const float & kanzi::Vector2::operator[] ( size_t index) const
inlineconstexpr

Access to individual elements of a vector.

Parameters
indexThe index of the accessed element. Either 0 or 1.
Returns
If index is 0, the x element. If index is 1, the y element.

◆ operator[]() [2/2]

constexpr float & kanzi::Vector2::operator[] ( size_t index)
inlineconstexpr

Access to individual elements of the vector.

Parameters
indexIndex of the accessed element. Either 0 or 1.
Returns
If index is 0, reference to x element. If index is 1, reference to y element.

◆ operator*=()

constexpr Vector2 & kanzi::Vector2::operator*= ( float scalar)
inlineconstexpr

Multiplies each vector element with a scalar.

Parameters
scalarMultiplier for each vector element.
Returns
This vector.

◆ operator/=()

constexpr Vector2 & kanzi::Vector2::operator/= ( float scalar)
inlineconstexpr

Divides each vector element with a scalar.

Parameters
scalarDivider for each vector element.
Returns
This vector.

◆ operator+=() [1/2]

constexpr Vector2 & kanzi::Vector2::operator+= ( float scalar)
inlineconstexpr

Adds a scalar to each vector element.

Parameters
scalarAddition to each vector element.
Returns
This vector.

◆ operator+=() [2/2]

constexpr Vector2 & kanzi::Vector2::operator+= ( Vector2 v)
inlineconstexpr

Modifies this vector by adding another vector.

Parameters
vAnother vector.
Returns
This vector.

◆ operator-=()

constexpr Vector2 & kanzi::Vector2::operator-= ( Vector2 v)
inlineconstexpr

Modifies this vector by subtracting another vector from this vector.

Parameters
vAnother vector.
Returns
This vector.

◆ zero()

static KZ_NO_DISCARD constexpr Vector2 kanzi::Vector2::zero ( )
inlinestaticconstexpr

Returns the vector with each element being zero.

Returns
Vector with zeroed elements.

◆ one()

static KZ_NO_DISCARD constexpr Vector2 kanzi::Vector2::one ( )
inlinestaticconstexpr

Returns the vector with each element being one.

Returns
Vector with unit element values.

◆ getX()

constexpr float kanzi::Vector2::getX ( ) const
inlineconstexpr

Returns the x element of the vector.

Returns
The x element.

◆ getY()

constexpr float kanzi::Vector2::getY ( ) const
inlineconstexpr

Returns the y element of the vector.

Returns
The y element.

◆ setX()

constexpr void kanzi::Vector2::setX ( float value)
inlineconstexpr

Sets the x element of the vector.

Parameters
valueThe new value of the x element.

◆ setY()

constexpr void kanzi::Vector2::setY ( float value)
inlineconstexpr

Sets the y element of the vector.

Parameters
valueThe new value of the y element.

◆ length()

float kanzi::Vector2::length ( ) const
inline

Calculates the length a vectors.

Returns
sqrt(x*x + y*y)

◆ squaredLength()

constexpr float kanzi::Vector2::squaredLength ( ) const
constexpr

Calculates the squared length a vectors.

Returns
x*x + y*y

◆ normalized()

KZ_NO_DISCARD Vector2 kanzi::Vector2::normalized ( ) const
inline

Normalizes the vector and returns the resulting vector.

Returns
The normalized vector.

◆ lowestValue()

constexpr Vector2 kanzi::Vector2::lowestValue ( )
staticconstexpr

Returns the vector with each element having the most negative float value.

Returns
Vector with the lowest possible value.

◆ highestValue()

constexpr Vector2 kanzi::Vector2::highestValue ( )
staticconstexpr

Returns the vector with each element having the most positive float value.

Returns
Vector with the highest possible value.

◆ nan()

constexpr Vector2 kanzi::Vector2::nan ( )
staticconstexpr

Returns the vector with each element being NaN.

Returns
Vector with NaN elements.

◆ hasNan()

bool kanzi::Vector2::hasNan ( ) const
inline

Returns true if and only if at least one of the vector values is NaN.

◆ positiveInfinity()

constexpr Vector2 kanzi::Vector2::positiveInfinity ( )
staticconstexpr

Returns the vector with each element being the positive infinity.

Returns
Vector with positive infinity elements.

◆ negativeInfinity()

constexpr Vector2 kanzi::Vector2::negativeInfinity ( )
staticconstexpr

Returns the vector with each element being the negative infinity.

Returns
Vector with negative infinity elements.

◆ createFromVector3()

static constexpr Vector2 kanzi::Vector2::createFromVector3 ( Vector3 v)
inlinestaticconstexpr

Creates a Vector2 from Vector3 by dropping the z-coordinate.

Parameters
vInput vector.
Returns
The input vector without z-coordinate.

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