Raven Engine v0.1
Loading...
Searching...
No Matches
Vector

Vector types and operations. More...

Classes

struct  Crux::Vector< T, 2 >
 2-dimensional vector. More...
struct  Crux::Vector< T, 3 >
 3-dimensional vector. More...
struct  Crux::Vector< T, 4 >
 4-dimensional vector. More...
struct  Crux::Vector< T, N >
 General N-dimensional fixed-size vector container. More...

Typedefs

using Crux::ivec3 = Vector<int, 3>
 2D integer vector
using Crux::ivec4 = Vector<int, 4>
 3D integer vector
using Crux::uvec2 = Vector<unsigned, 2>
 4D integer vector
using Crux::uvec3 = Vector<unsigned, 3>
 2D unsigned vector
using Crux::uvec4 = Vector<unsigned, 4>
 3D unsigned vector
using Crux::vec2 = Vector<float, 2>
 4D unsigned vector
using Crux::vec3 = Vector<float, 3>
 2D float vector
using Crux::vec4 = Vector<float, 4>
 3D float vector
using Crux::dvec2 = Vector<double, 2>
 4D float vector
using Crux::dvec3 = Vector<double, 3>
 2D double vector
using Crux::dvec4 = Vector<double, 4>
 3D double vector

Functions

template<typename T, size_t N>
constexpr Vector< T, N > Crux::operator+ (const Vector< T, N > &a, const Vector< T, N > &b)
 Component-wise addition of two vectors.
template<typename T, size_t N>
constexpr Vector< T, N > Crux::operator- (const Vector< T, N > &a, const Vector< T, N > &b)
 Component-wise subtraction of two vectors.
template<typename T, size_t N>
constexpr Vector< T, N > Crux::operator* (const Vector< T, N > &a, const T &scalar)
 Scalar multiplication (vector * scalar).
template<typename T, size_t N>
constexpr Vector< T, N > Crux::operator* (const T &scalar, const Vector< T, N > &a)
 Scalar multiplication (scalar * vector).
template<typename T, size_t N>
constexpr Vector< T, N > Crux::operator/ (const Vector< T, N > &a, const T &scalar)
 Scalar division of a vector.
template<typename T, size_t N>
constexpr Vector< T, N > & Crux::operator+= (Vector< T, N > &a, const Vector< T, N > &b)
 Compound addition assignment (vector += vector).
template<typename T, size_t N>
constexpr Vector< T, N > & Crux::operator-= (Vector< T, N > &a, const Vector< T, N > &b)
 Compound subtraction assignment (vector -= vector).
template<typename T, size_t N>
constexpr Vector< T, N > & Crux::operator*= (Vector< T, N > &a, const T &scalar)
 Compound scalar multiplication assignment (vector *= scalar).
template<typename T, size_t N>
constexpr Vector< T, N > & Crux::operator/= (Vector< T, N > &a, const T &scalar)
 Compound scalar division assignment (vector /= scalar).
template<typename T, size_t N>
constexpr T Crux::Dot (const Vector< T, N > &a, const Vector< T, N > &b)
 Dot product of two vectors.
template<typename T>
constexpr Vector< T, 3 > Crux::Cross (const Vector< T, 3 > &a, const Vector< T, 3 > &b)
 Cross product for 3D vectors.
template<typename T, size_t N>
constexpr T Crux::LengthSq (const Vector< T, N > &a)
 Squared length (magnitude) of a vector.
template<typename T, size_t N>
Crux::Length (const Vector< T, N > &a)
 Length (magnitude) of a vector.
template<typename T, size_t N>
Vector< T, N > Crux::Normalize (const Vector< T, N > &a)
 Normalizes a vector to unit length.
template<typename T, size_t N>
constexpr Vector< T, N > Crux::Project (const Vector< T, N > &a, const Vector< T, N > &b)
 Projects vector a onto vector b.
template<typename T, size_t N>
constexpr Vector< T, N > Crux::Reflect (const Vector< T, N > &a, const Vector< T, N > &normal)
 Reflects vector a around the given normal.
template<typename T, size_t N>
constexpr Vector< T, N > Crux::MinComponent (const Vector< T, N > &a, const Vector< T, N > &b)
 Element-wise minimum of two vectors.
template<typename T, size_t N>
constexpr Vector< T, N > Crux::MaxComponent (const Vector< T, N > &a, const Vector< T, N > &b)
 Element-wise maximum of two vectors.
template<typename T, size_t N>
constexpr Vector< T, N > Crux::Abs (const Vector< T, N > &a)
 Element-wise absolute value of a vector.
template<typename T, size_t N>
constexpr bool Crux::operator== (const Vector< T, N > &a, const Vector< T, N > &b)
 Approximate equality comparison with tolerance.
template<typename T, size_t N>
constexpr bool Crux::operator!= (const Vector< T, N > &a, const Vector< T, N > &b)
 Inequality comparison.
template<typename T, size_t N>
Crux::AngleBetween (const Vector< T, N > &a, const Vector< T, N > &b)
 Angle between two vectors in radians.
template<typename T, size_t N>
constexpr Vector< T, N > Crux::Lerp (const Vector< T, N > &a, const Vector< T, N > &b, T t)
 Linear interpolation between two vectors.

Detailed Description

Vector types and operations.

Contains all functionality related to vector math and operations on vector types.

Typedef Documentation

◆ dvec2

using Crux::dvec2 = Vector<double, 2>

4D float vector

◆ dvec3

using Crux::dvec3 = Vector<double, 3>

2D double vector

◆ dvec4

using Crux::dvec4 = Vector<double, 4>

3D double vector

◆ ivec3

using Crux::ivec3 = Vector<int, 3>

2D integer vector

◆ ivec4

using Crux::ivec4 = Vector<int, 4>

3D integer vector

◆ uvec2

using Crux::uvec2 = Vector<unsigned, 2>

4D integer vector

◆ uvec3

using Crux::uvec3 = Vector<unsigned, 3>

2D unsigned vector

◆ uvec4

using Crux::uvec4 = Vector<unsigned, 4>

3D unsigned vector

◆ vec2

using Crux::vec2 = Vector<float, 2>

4D unsigned vector

◆ vec3

using Crux::vec3 = Vector<float, 3>

2D float vector

◆ vec4

using Crux::vec4 = Vector<float, 4>

3D float vector

Function Documentation

◆ Abs()

template<typename T, size_t N>
Vector< T, N > Crux::Abs ( const Vector< T, N > & a)
constexpr

Element-wise absolute value of a vector.

Returns a new vector where each component is the absolute value of the corresponding component of the input vector.

Parameters
aInput vector.
Returns
A new vector containing the absolute values of each component.

◆ AngleBetween()

template<typename T, size_t N>
T Crux::AngleBetween ( const Vector< T, N > & a,
const Vector< T, N > & b )
inline

Angle between two vectors in radians.

Computes the angle between two vectors using the dot product formula.

Parameters
aFirst vector.
bSecond vector.
Returns
Angle in radians, clamped to the range [-Pi, Pi].

◆ Cross()

template<typename T>
Vector< T, 3 > Crux::Cross ( const Vector< T, 3 > & a,
const Vector< T, 3 > & b )
constexpr

Cross product for 3D vectors.

Computes the cross product of two 3D vectors, resulting in a vector orthogonal to both.

Parameters
aFirst vector.
bSecond vector.
Returns
Cross product vector.

◆ Dot()

template<typename T, size_t N>
T Crux::Dot ( const Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Dot product of two vectors.

Computes the dot product (scalar product) of two vectors, which is the sum of the products of their corresponding components.

Parameters
aFirst vector.
bSecond vector.
Returns
Sum of component-wise products.

◆ Length()

template<typename T, size_t N>
T Crux::Length ( const Vector< T, N > & a)
inline

Length (magnitude) of a vector.

Parameters
aInput vector.
Returns
Length of the vector.

◆ LengthSq()

template<typename T, size_t N>
T Crux::LengthSq ( const Vector< T, N > & a)
constexpr

Squared length (magnitude) of a vector.

Computes the squared length without taking the square root, which is more efficient.

Parameters
aInput vector.
Returns
Squared length of the vector.

◆ Lerp()

template<typename T, size_t N>
Vector< T, N > Crux::Lerp ( const Vector< T, N > & a,
const Vector< T, N > & b,
T t )
constexpr

Linear interpolation between two vectors.

Performs linear interpolation between two vectors based on a factor t.

Parameters
aFirst vector.
bSecond vector.
tInterpolation factor (0.0 to 1.0).

◆ MaxComponent()

template<typename T, size_t N>
Vector< T, N > Crux::MaxComponent ( const Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Element-wise maximum of two vectors.

Returns a vector where each component is the maximum of the corresponding components of the input vectors.

Parameters
aFirst vector.
bSecond vector.
Returns
Vector containing the maximum components.

◆ MinComponent()

template<typename T, size_t N>
Vector< T, N > Crux::MinComponent ( const Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Element-wise minimum of two vectors.

Returns a vector where each component is the minimum of the corresponding components of a and b.

Parameters
aFirst vector.
bSecond vector.
Returns
A vector containing the minimum components.

◆ Normalize()

template<typename T, size_t N>
Vector< T, N > Crux::Normalize ( const Vector< T, N > & a)
inline

Normalizes a vector to unit length.

Normalization scales the vector to have a length of 1, preserving its direction.

Note
If the vector's length is below Epsilon<T>, returns the original vector.
Parameters
aInput vector to normalize.
Returns
Normalized vector.

◆ operator!=()

template<typename T, size_t N>
bool Crux::operator!= ( const Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Inequality comparison.

Returns
True if any component differs by more than Epsilon<T>.

◆ operator*() [1/2]

template<typename T, size_t N>
Vector< T, N > Crux::operator* ( const T & scalar,
const Vector< T, N > & a )
constexpr

Scalar multiplication (scalar * vector).

Multiplies each component of the vector by the scalar value.

Parameters
scalarScalar value to multiply by.
aInput vector.
Returns
A new vector containing the scaled components.

◆ operator*() [2/2]

template<typename T, size_t N>
Vector< T, N > Crux::operator* ( const Vector< T, N > & a,
const T & scalar )
constexpr

Scalar multiplication (vector * scalar).

Multiplies each component of the vector by the scalar value.

Parameters
aInput vector.
scalarScalar value to multiply by.
Returns
A new vector containing the scaled components.

◆ operator*=()

template<typename T, size_t N>
Vector< T, N > & Crux::operator*= ( Vector< T, N > & a,
const T & scalar )
constexpr

Compound scalar multiplication assignment (vector *= scalar).

Multiplies each component of the vector by the scalar.

Parameters
aVector to be multiplied.
scalarScalar value to multiply by.
Returns
Reference to the modified vector.

◆ operator+()

template<typename T, size_t N>
Vector< T, N > Crux::operator+ ( const Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Component-wise addition of two vectors.

Adds corresponding components of two vectors of the same size.

Parameters
aFirst vector.
bSecond vector.
Returns
A new vector containing the sum of the components.

◆ operator+=()

template<typename T, size_t N>
Vector< T, N > & Crux::operator+= ( Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Compound addition assignment (vector += vector).

Adds each component of vector b to the corresponding component of vector a.

Parameters
aVector to be modified.
bVector to add to a.
Returns
Reference to the modified vector a.

◆ operator-()

template<typename T, size_t N>
Vector< T, N > Crux::operator- ( const Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Component-wise subtraction of two vectors.

Subtracts corresponding components of vector b from vector a.

Parameters
aFirst vector.
bSecond vector.
Returns
A new vector containing the difference of the components.

◆ operator-=()

template<typename T, size_t N>
Vector< T, N > & Crux::operator-= ( Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Compound subtraction assignment (vector -= vector).

Subtracts each component of vector b from the corresponding component of vector a.

Parameters
aVector to be modified.
bVector to subtract from a.
Returns
Reference to the modified vector a.

◆ operator/()

template<typename T, size_t N>
Vector< T, N > Crux::operator/ ( const Vector< T, N > & a,
const T & scalar )
constexpr

Scalar division of a vector.

Divides each component of the vector by the scalar value.

Parameters
aInput vector.
scalarScalar value to divide by.
Returns
A new vector containing the divided components.

◆ operator/=()

template<typename T, size_t N>
Vector< T, N > & Crux::operator/= ( Vector< T, N > & a,
const T & scalar )
constexpr

Compound scalar division assignment (vector /= scalar).

Divides each component of the vector by the scalar.

Parameters
aVector to be divided.
scalarScalar value to divide by.
Returns
Reference to the modified vector.

◆ operator==()

template<typename T, size_t N>
bool Crux::operator== ( const Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Approximate equality comparison with tolerance.

Returns
True if all components differ by less than Epsilon<T>.

◆ Project()

template<typename T, size_t N>
Vector< T, N > Crux::Project ( const Vector< T, N > & a,
const Vector< T, N > & b )
constexpr

Projects vector a onto vector b.

Projects vector a onto vector b, returning the component of a that lies in the direction of b.

Parameters
aInput vector to project.
bVector onto which a is projected.
Returns
Projected vector.

◆ Reflect()

template<typename T, size_t N>
Vector< T, N > Crux::Reflect ( const Vector< T, N > & a,
const Vector< T, N > & normal )
constexpr

Reflects vector a around the given normal.

Reflects vector a across the plane defined by the normal vector.

Parameters
aInput vector to reflect.
normalNormal vector defining the reflection plane.
Returns
Reflected vector.