DirectZ
|
Template struct representing an N-dimensional vector of type T. More...
#include <math.hpp>
Public Member Functions | |
template<typename... Args> | |
vec (Args... args) | |
Variadic constructor to initialize vector components. | |
template<typename OT, size_t ON> | |
vec (const vec< OT, ON > &other) | |
Copy constructor to convert from vectors of different types and/or sizes. | |
vec & | operator= (const vec &other) |
Assignment operator for component-wise copy. | |
T & | operator[] (size_t i) |
Index operator for non-const access to vector components. | |
const T & | operator[] (size_t i) const |
Index operator for const access to vector components. | |
template<typename O> | |
vec & | operator*= (const O &other) |
Compound multiplication-assignment operator. | |
template<typename O> | |
vec & | operator/= (const O &other) |
Compound division-assignment operator. | |
template<typename O> | |
vec & | operator+= (const O &other) |
Compound addition-assignment operator. | |
template<typename O> | |
vec & | operator-= (const O &other) |
Compound subtraction-assignment operator. | |
template<typename O> | |
vec | operator* (const O &other) const |
Multiplication operator returning a new vector. | |
template<typename O> | |
vec | operator/ (const O &other) const |
Division operator returning a new vector. | |
template<typename O> | |
vec | operator+ (const O &other) const |
Addition operator returning a new vector. | |
template<typename O> | |
vec | operator- (const O &other) const |
Subtraction operator returning a new vector. | |
vec | operator- () const |
Unary negation operator. | |
T | length () const |
Computes the Euclidean length (magnitude) of the vector. | |
vec | normalize () const |
Returns a normalized (unit length) copy of the vector. |
Public Attributes | |
T | data [N] |
Underlying array storing vector components. |
Template struct representing an N-dimensional vector of type T.
This class supports construction from multiple arguments or a single scalar to fill all components, copy construction from vectors of different types and sizes, element access, and arithmetic operations (component-wise or scalar). It also supports vector length computation and normalization.
T | The scalar type of the vector components. |
N | The dimensionality of the vector. |
|
inline |
Variadic constructor to initialize vector components.
Behaves differently depending on the number of arguments passed:
Args | Variadic template arguments representing component values. |
args | Values used to initialize vector components. |
|
inline |
Copy constructor to convert from vectors of different types and/or sizes.
Copies component-wise up to the minimum of source and destination size, zero-initializes remaining components if destination vector is larger.
OT | The source vector component type. |
ON | The source vector dimension. |
other | The vector to copy from. |
Computes the Euclidean length (magnitude) of the vector.
Calculates the square root of the sum of squares of all components.
Returns a normalized (unit length) copy of the vector.
Divides all components by the vector length.
|
inline |
Multiplication operator returning a new vector.
Supports multiplication by a scalar or component-wise multiplication by another vector.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to multiply by. |
|
inline |
Compound multiplication-assignment operator.
Supports multiplication by a scalar or component-wise multiplication by another vector. Throws std::runtime_error if the operand type is unsupported.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to multiply by. |
std::runtime_error | if unsupported operand type is used. |
|
inline |
Addition operator returning a new vector.
Supports addition by a scalar or component-wise addition by another vector.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to add. |
|
inline |
Compound addition-assignment operator.
Supports addition by a scalar or component-wise addition by another vector. Throws std::runtime_error if the operand type is unsupported.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to add. |
std::runtime_error | if unsupported operand type is used. |
Unary negation operator.
Returns a new vector with all components negated.
|
inline |
Subtraction operator returning a new vector.
Supports subtraction by a scalar or component-wise subtraction by another vector.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to subtract. |
|
inline |
Compound subtraction-assignment operator.
Supports subtraction by a scalar or component-wise subtraction by another vector. Throws std::runtime_error if the operand type is unsupported.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to subtract. |
std::runtime_error | if unsupported operand type is used. |
|
inline |
Division operator returning a new vector.
Supports division by a scalar or component-wise division by another vector.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to divide by. |
|
inline |
Compound division-assignment operator.
Supports division by a scalar or component-wise division by another vector. Throws std::runtime_error if the operand type is unsupported.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to divide by. |
std::runtime_error | if unsupported operand type is used. |
Assignment operator for component-wise copy.
Copies all components from the other vector using memcpy for efficiency.
other | The vector to copy from. |
Index operator for non-const access to vector components.
No bounds checking is performed.
i | The component index to access. |
Index operator for const access to vector components.
No bounds checking is performed.
i | The component index to access. |
Underlying array storing vector components.