vec2 Struct Template
Represents a 2-dimensional vector of the generic type <T>. More...
Declaration
Public Constructors Index
template <helios::math::Numeric T> | |
| constexpr | vec2 () noexcept |
|
Creates a new vec2 with its values initialized to (0, 0). More... | |
template <helios::math::Numeric T> | |
| constexpr | vec2 (const T x, const T y) noexcept |
|
Constructs a new vec2 with the specified x, y components. More... | |
Public Operators Index
template <helios::math::Numeric T> | |
| constexpr const T & | operator[] (const size_t i) const noexcept |
|
Provides read only access to the vector components. Bounds checking is performed via `assert` in debug builds. More... | |
template <helios::math::Numeric T> | |
| constexpr T & | operator[] (const size_t i) noexcept |
|
Provides read-write access to the vector components. Bounds checking is performed via `assert` in debug builds. More... | |
template <helios::math::Numeric T> | |
| constexpr bool | operator== (const vec2< T > &rgt) const |
|
Strictly compares the elements of this vector with the elements of the rgt vector. More... | |
Public Member Functions Index
template <helios::math::Numeric T> | |
| constexpr auto | toVec3 () const -> helios::math::vec3< T > |
|
Converts the current vec2<T> into a 3D vector representation. More... | |
template <helios::math::Numeric T> | |
| auto | length () const noexcept -> FloatingPointType< T > |
|
Returns the magnitude of this vec2<T>. More... | |
template <helios::math::Numeric T> | |
| constexpr bool | isNormalized () const noexcept |
|
Checks if this vector is normalized (unit length). More... | |
template <helios::math::Numeric T> | |
| auto | normalize () const noexcept -> vec2< FloatingPointType< T > > |
|
Normalizes this vec2<T>. More... | |
template <helios::math::Numeric T> | |
| constexpr bool | same (const vec2< T > &rgt, T epsilon=0.0001) const |
|
Compares this vector's elements with the rgt vector considering an epsilon value. Returns true if for all elements the equation |a-b| <= epsilon holds. More... | |
Private Member Attributes Index
template <helios::math::Numeric T> | |
| T | v[2] |
|
Internal array storing the vector components. More... | |
Description
Represents a 2-dimensional vector of the generic type <T>.
The `vec2` struct provides a lightweight and efficient way to handle 2D vector mathematics for the numeric types float, int, double. For convenient access, the shorthands `vec2f`, `vec2d` and `vec2i` are available.
- Template Parameters
-
T The numeric type of the vector components.
Definition at line 33 of file vec2.ixx.
Public Constructors
vec2()
| inline constexpr noexcept |
vec2()
| inline constexpr noexcept |
Public Operators
operator[]()
| inline constexpr noexcept |
Provides read only access to the vector components. Bounds checking is performed via `assert` in debug builds.
- Parameters
-
i The index to query
- Returns
A const ref to the requested component.
Definition at line 74 of file vec2.ixx.
operator[]()
| inline constexpr noexcept |
Provides read-write access to the vector components. Bounds checking is performed via `assert` in debug builds.
- Parameters
-
i The index to query
- Returns
A ref to the requested component.
Definition at line 87 of file vec2.ixx.
operator==()
| inline constexpr |
Strictly compares the elements of this vector with the elements of the rgt vector.
- Parameters
-
rgt The right vector to compare for equal values
- Returns
True if all elements are equal (==), false otherwise.
Definition at line 147 of file vec2.ixx.
Public Member Functions
isNormalized()
| inline constexpr noexcept |
Checks if this vector is normalized (unit length).
A vector is considered normalized if its squared length equals 1 within the tolerance defined by EPSILON_LENGTH.
- Returns
true if the vector is approximately unit length, false otherwise.
Definition at line 113 of file vec2.ixx.
length()
| inline noexcept |
Returns the magnitude of this vec2<T>.
- Returns
The magnitude of this vector as type FloatingPointType<T>.
Definition at line 97 of file vec2.ixx.
Referenced by helios::math::vec2< float >::normalize.
normalize()
| inline noexcept |
Normalizes this vec2<T>.
- Returns
The normalized FloatingPointType<T> vector.
Definition at line 126 of file vec2.ixx.
same()
| inline constexpr |
Compares this vector's elements with the rgt vector considering an epsilon value. Returns true if for all elements the equation |a-b| <= epsilon holds.
- Parameters
-
rgt The other vector to compare with this vector for equality.
epsilon The epsilon value to use for comparison. If omitted, the default epsilon (0.0001) is used.
- Returns
True if the elements of the vectors are considered equal, otherwise false.
- Todo
-
account for abs (values close to zero) and rel (larger values), move epsilon to global constant?
toVec3()
| inline constexpr |
Converts the current vec2<T> into a 3D vector representation.
- Returns
A 3D vector corresponding to the converted representation of the object or input.
Definition at line 62 of file vec2.ixx.
The documentation for this struct was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.