|
Infinity Engine v0.6.20
C++ API Documentation
|
Template structure representing a 2-component vector. More...
#include <Vector2.hpp>
Public Member Functions | |
| constexpr | t_Vector2 () |
| Default constructor. | |
| constexpr | t_Vector2 (const t_Vector2 &v) |
| Copy constructor. | |
| constexpr t_Vector2 & | operator= (const t_Vector2 &)=default |
| Copy assignment operator. | |
| constexpr | t_Vector2 (T x, T y) |
| Constructs a vector from component values. | |
| template<typename R > | |
| constexpr | t_Vector2 (const t_Vector2< R > &v) |
| Explicit type-converting constructor. | |
| T & | operator[] (size_t i) |
| Array subscript operator (mutable). | |
| T | operator[] (size_t i) const |
| Array subscript operator (const). | |
| void | set (T in_x, T in_y) |
| Sets both components simultaneously. | |
| T * | data () |
| Gets a mutable pointer to the underlying data. | |
| const T * | data () const |
| Gets a const pointer to the underlying data. | |
| template<typename R > | |
| t_Vector2 & | operator= (const t_Vector2< R > &rhs) |
| Type-converting assignment operator. | |
| t_Vector2 & | operator+= (const t_Vector2 &rhs) |
| Component-wise addition assignment. | |
| t_Vector2 & | operator-= (const t_Vector2 &rhs) |
| Component-wise subtraction assignment. | |
| t_Vector2 & | operator*= (T rhs) |
| Scalar multiplication assignment. | |
| t_Vector2 & | operator*= (const t_Vector2 &rhs) |
| Component-wise multiplication assignment. | |
| t_Vector2 & | operator/= (T rhs) |
| Scalar division assignment. | |
| operator bool () const noexcept | |
| Boolean conversion operator. | |
| t_Vector2< T > | normalized () const |
| Computes the normalized version of this vector. | |
| t_Vector2< T > | cross (const t_Vector2< T > &other) const |
| Computes the 2D cross product with another vector. | |
| float | length () const |
| Computes the length (magnitude) of this vector. | |
| float | magnitude () const |
| Computes the magnitude of this vector. | |
| float | squaredMagnitude () const |
| Computes the squared magnitude of this vector. | |
| float | distance (const t_Vector2< T > &other) const |
| Computes the Euclidean distance to another vector. | |
| float | dot (const t_Vector2< T > &other) const |
| Computes the dot product with another vector. | |
| float | angle (const t_Vector2< T > &other) const |
| Computes the angle between this vector and another. | |
| t_Vector2< T > | abs () const |
| Computes the component-wise absolute value. | |
Public Attributes | ||
| union { | ||
| T value [2] | ||
| Array access to components. More... | ||
| struct { | ||
| T x | ||
| T y | ||
| Cartesian coordinate interpretation. More... | ||
| } | ||
| struct { | ||
| T r | ||
| T g | ||
| Color component interpretation. More... | ||
| } | ||
| struct { | ||
| T s | ||
| T t | ||
| Texture coordinate interpretation. More... | ||
| } | ||
| }; | ||
| Union providing multiple interpretations of the same data. | ||
Template structure representing a 2-component vector.
t_Vector2 provides a versatile 2D vector implementation with support for multiple interpretations of the same underlying data through union members:
This flexibility makes it suitable for various use cases in procedural generation:
The template parameter allows instantiation with different numeric types (float, double, int, etc.) to match precision and performance requirements. Common specializations are provided via type aliases (Vector2, Vector2i, etc.).
Vector operations include:
Example usage:
| T | The numeric type for vector components (float, double, int, etc.). |
|
inlineconstexpr |
Default constructor.
Initializes all components to zero (or default value of T).
|
inlineconstexpr |
Copy constructor.
| v | Vector to copy from. |
|
inlineconstexpr |
|
inlineexplicitconstexpr |
Explicit type-converting constructor.
Constructs a vector from another vector with a different component type, performing static_cast on each component.
| R | The source component type. |
| v | Vector to convert from. |
Computes the component-wise absolute value.
Returns a vector where each component is the absolute value of the corresponding component in this vector.
Computes the angle between this vector and another.
Returns the angle in radians between the two vectors.
| other | The other vector. |
|
inline |
Computes the 2D cross product with another vector.
In 2D, the cross product returns a vector perpendicular to both inputs. The magnitude equals the area of the parallelogram formed by the vectors.
| other | The other vector. |
|
inline |
Gets a const pointer to the underlying data.
Computes the dot product with another vector.
The dot product measures how much two vectors point in the same direction. Returns positive if vectors point in similar directions, negative if opposite, and zero if perpendicular.
| other | The other vector. |
|
inline |
|
inline |
Computes the magnitude of this vector.
Alias for length().
|
inline |
Computes the normalized version of this vector.
Returns a unit vector pointing in the same direction. If the vector is zero-length, returns a zero vector.
|
inlineexplicitnoexcept |
|
inline |
Component-wise multiplication assignment.
| rhs | Vector to multiply by component-wise. |
|
inline |
Scalar multiplication assignment.
| rhs | Scalar to multiply by. |
|
inline |
Component-wise addition assignment.
| rhs | Vector to add. |
|
inline |
Component-wise subtraction assignment.
| rhs | Vector to subtract. |
|
inline |
Scalar division assignment.
For floating-point types, multiplies by reciprocal for better performance. For integer types, performs standard division.
| rhs | Scalar to divide by. |
|
constexprdefault |
Copy assignment operator.
|
inline |
Type-converting assignment operator.
Assigns from a vector with a different component type, performing static_cast on each component.
| R | The source component type. |
| rhs | Vector to assign from. |
|
inline |
Array subscript operator (mutable).
| i | Component index (0 or 1). |
|
inline |
Array subscript operator (const).
| i | Component index (0 or 1). |
Sets both components simultaneously.
| in_x | New x component value. |
| in_y | New y component value. |
|
inline |
Computes the squared magnitude of this vector.
More efficient than length() when you only need to compare lengths or don't need the actual distance value, as it avoids the sqrt operation.
| union { ... } Infinity::Types::Math::t_Vector2< T > |
Union providing multiple interpretations of the same data.
Allows accessing the two components as:
Color component interpretation.
Texture coordinate interpretation.
| T Infinity::Types::Math::t_Vector2< T >::value[2] |
Array access to components.
| T Infinity::Types::Math::t_Vector2< T >::x |
Cartesian coordinate interpretation.