Vector2
Vector2 stores an (x, y) pair and is used for positions, directions, UV coordinates, and general 2D math. It provides basic arithmetic, normalization, and utility helpers.
Construction
Constructors
Vector2() constexpr
Constructs a vector with both components set to the same value.
Vector2::Vector2(float value);| Parameter | Description |
|---|---|
| value | Value to assign to both components. |
Vector2() constexpr
Constructs a vector from individual components.
Vector2::Vector2(float x, float y);| Parameter | Description |
|---|---|
| x | X component. |
| y | Y component. |
Properties
x float
X component.
float x {};y float
Y component.
float y {};Functions
Length() float
Returns the vector length.
float Vector2::Length() const;LengthSquared() float
Returns the squared vector length.
float Vector2::LengthSquared() const;Applies a component-wise maximum with another vector.
Vector2& Vector2::Max(const Vector2& v);| Parameter | Description |
|---|---|
| v | Vector to compare against. |
Applies a component-wise minimum with another vector.
Vector2& Vector2::Min(const Vector2& v);| Parameter | Description |
|---|---|
| v | Vector to compare against. |
Normalizes the vector in-place.
If the length is zero, the vector is left unchanged.
Vector2& Vector2::Normalize();Multiplies the vector component-wise by another vector in-place.
Vector2& Vector2::operator* =(const Vector2& v);| Parameter | Description |
|---|---|
| v | Vector to multiply. |
Multiplies the vector by a scalar in-place.
Vector2& Vector2::operator* =(float n);| Parameter | Description |
|---|---|
| n | Scalar value. |
Adds another vector in-place.
Vector2& Vector2::operator+=(const Vector2& v);| Parameter | Description |
|---|---|
| v | Vector to add. |
Subtracts another vector in-place.
Vector2& Vector2::operator-=(const Vector2& v);| Parameter | Description |
|---|---|
| v | Vector to subtract. |
operator[]() float &
Accesses a component by index.
float& Vector2::operator[](int i);| Parameter | Description |
|---|---|
| i | Index: 0 → x, 1 → y. |
operator[]() const float
Accesses a component by index.
const float Vector2::operator[](int i) const;| Parameter | Description |
|---|---|
| i | Index: 0 → x, 1 → y. |
Returns a unit vector pointing to the right.
static constexpr Vector2 Vector2::Right();Dot() float
Computes the dot product of two 2D vectors.
Computes the scalar product (), which measures how aligned two vectors are.
float Dot(const Vector2& a, const Vector2& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Linearly interpolates between two vectors.
Vector2 Lerp(const Vector2& v1, const Vector2& v2, float f);| Parameter | Description |
|---|---|
| v1 | Start vector. |
| v2 | End vector. |
| f | Interpolation factor in . |
Returns a normalized copy of a vector.
If the input has zero length, the zero vector is returned.
Vector2 Normalize(const Vector2& v);| Parameter | Description |
|---|---|
| v | Input vector. |
Multiplies two vectors component-wise.
Vector2 operator* (const Vector2& a, const Vector2& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Multiplies a vector by a scalar.
Vector2 operator* (const Vector2& v, float n);| Parameter | Description |
|---|---|
| v | Input vector. |
| n | Scalar value. |
Multiplies a scalar by a vector.
Vector2 operator* (float n, const Vector2& v);| Parameter | Description |
|---|---|
| n | Scalar value. |
| v | Input vector. |
Adds two 2D vectors.
Vector2 operator+(const Vector2& a, const Vector2& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |
Subtracts one 2D vector from another.
Vector2 operator-(const Vector2& a, const Vector2& b);| Parameter | Description |
|---|---|
| a | First vector. |
| b | Second vector. |