[nnm] No Nonsense Math 0.5.0
A No-Nonsense, C++ 17, single-header-only Math library geared towards graphics programming.
Loading...
Searching...
No Matches
nnm::Vector4< Real > Class Template Reference

#include <nnm.hpp>

Public Member Functions

constexpr Vector4 ()
template<typename Other>
constexpr Vector4 (const Vector4< Other > &vector)
constexpr Vector4 (const Vector2< Real > &vector, const Real z, const Real w)
constexpr Vector4 (const Vector3< Real > &vector, const Real w)
constexpr Vector4 (const Real x, const Real y, const Real z, const Real w)
constexpr Vector4 abs () const
Vector4 ceil () const
Vector4 floor () const
Vector4 round () const
constexpr Vector4 clamp (const Vector4 &min, const Vector4 &max) const
constexpr Real length_sqrd () const
Real length () const
Vector4 clamp_length (const Real min, const Real max) const
Vector4 normalize () const
constexpr Vector4 lerp (const Vector4 &to, const Real weight) const
constexpr Vector4 lerp_clamped (const Vector4 &to, const Real weight) const
constexpr Real dot (const Vector4 &other) const
constexpr Matrix4< Real > outer (const Vector4 &other) const
constexpr Vector4 inverse () const
constexpr Vector4 transform (const Transform3< Real > &by) const
constexpr Vector4 transform_at (const Vector3< Real > &origin, const Transform3< Real > &by) const
constexpr Real max () const
constexpr Real abs_max () const
constexpr Real min () const
constexpr Real abs_min () const
constexpr uint8_t max_index () const
constexpr uint8_t abs_max_index () const
constexpr uint8_t min_index () const
constexpr uint8_t abs_min_index () const
constexpr bool approx_equal (const Vector4 &other) const
constexpr bool approx_zero () const
constexpr Vector2< Real > xy () const
constexpr Vector3< Real > xyz () const
const Real * begin () const
const Real * end () const
Real * begin ()
Real * end ()
constexpr const Real & at (const uint8_t index) const
constexpr Real & at (const uint8_t index)
constexpr const Real & operator[] (const uint8_t index) const
constexpr Real & operator[] (const uint8_t index)
constexpr bool operator== (const Vector4 &other) const
constexpr bool operator!= (const Vector4 &other) const
constexpr Vector4 operator+ (const Vector4 &other) const
constexpr Vector4operator+= (const Vector4 &other)
constexpr Vector4 operator- (const Vector4 &other) const
constexpr Vector4operator-= (const Vector4 &other)
constexpr Vector4 operator* (const Vector4 &other) const
constexpr Vector4operator*= (const Vector4 &other)
constexpr Vector4 operator* (const Matrix4< Real > &matrix) const
constexpr Vector4 operator* (const Real value) const
constexpr Vector4operator*= (const Real value)
constexpr Vector4 operator/ (const Vector4 &other) const
constexpr Vector4operator/= (const Vector4 &other)
constexpr Vector4 operator/ (const Real value) const
constexpr Vector4operator/= (const Real value)
constexpr bool operator< (const Vector4 &other) const
constexpr Vector4 operator+ () const
constexpr Vector4 operator- () const
constexpr operator bool () const

Static Public Member Functions

static constexpr Vector4 from_quaternion (const Quaternion< Real > &quaternion)
static constexpr Vector4 all (const Real value)
static constexpr Vector4 zero ()
static constexpr Vector4 one ()
static constexpr Vector4 axis_x ()
static constexpr Vector4 axis_y ()
static constexpr Vector4 axis_z ()
static constexpr Vector4 axis_w ()

Public Attributes

Real x
Real y
Real z
Real w

Detailed Description

template<typename Real>
class nnm::Vector4< Real >

Four-dimensional vector.

Template Parameters
RealFloating-point type.

Constructor & Destructor Documentation

◆ Vector4() [1/5]

template<typename Real>
nnm::Vector4< Real >::Vector4 ( )
inlineconstexpr

Initialize all components with zero.

◆ Vector4() [2/5]

template<typename Real>
template<typename Other>
nnm::Vector4< Real >::Vector4 ( const Vector4< Other > & vector)
inlineexplicitconstexpr

Cast from another vector type.

Template Parameters
OtherOther type.
Parameters
vectorVector to cast from.

◆ Vector4() [3/5]

template<typename Real>
nnm::Vector4< Real >::Vector4 ( const Vector2< Real > & vector,
const Real z,
const Real w )
inlineconstexpr

Initialize x and y from two-dimensional vector and z and w values.

Parameters
vectorTwo-dimensional vector.
zZ value.
wW value.

◆ Vector4() [4/5]

template<typename Real>
nnm::Vector4< Real >::Vector4 ( const Vector3< Real > & vector,
const Real w )
inlineconstexpr

Initialize x, y, and z with three-dimensional vector and w value.

Parameters
vectorThree-dimensional vector.
wW value.

◆ Vector4() [5/5]

template<typename Real>
nnm::Vector4< Real >::Vector4 ( const Real x,
const Real y,
const Real z,
const Real w )
inlineconstexpr

Initialize with components.

Parameters
xX value.
yY value.
zZ value.
wW value.

Member Function Documentation

◆ abs()

template<typename Real>
Vector4 nnm::Vector4< Real >::abs ( ) const
inlinenodiscardconstexpr

Component-wise absolute value.

Returns
Result.

◆ abs_max()

template<typename Real>
Real nnm::Vector4< Real >::abs_max ( ) const
inlinenodiscardconstexpr

Absolute-value maximum component.

Returns
Result.

◆ abs_max_index()

template<typename Real>
uint8_t nnm::Vector4< Real >::abs_max_index ( ) const
inlinenodiscardconstexpr

◆ abs_min()

template<typename Real>
Real nnm::Vector4< Real >::abs_min ( ) const
inlinenodiscardconstexpr

Absolute-value minimum component.

Returns
Result.

◆ abs_min_index()

template<typename Real>
uint8_t nnm::Vector4< Real >::abs_min_index ( ) const
inlinenodiscardconstexpr

Index of absolute-value minimum component.

Returns
Result.

◆ all()

template<typename Real>
constexpr Vector4 nnm::Vector4< Real >::all ( const Real value)
inlinestaticconstexpr

Vector with all components with value.

Parameters
valueValue.
Returns
Result.

◆ approx_equal()

template<typename Real>
bool nnm::Vector4< Real >::approx_equal ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

If approximately equal to another vector.

Parameters
otherOther vector.
Returns
True if approximately equal, false otherwise.

◆ approx_zero()

template<typename Real>
bool nnm::Vector4< Real >::approx_zero ( ) const
inlinenodiscardconstexpr

If all components are approximately zero.

Returns
True if approximately equal, false otherwise.

◆ at() [1/2]

template<typename Real>
Real & nnm::Vector4< Real >::at ( const uint8_t index)
inlineconstexpr

Reference to component at index.

Parameters
indexIndex.
Returns
Reference.

◆ at() [2/2]

template<typename Real>
const Real & nnm::Vector4< Real >::at ( const uint8_t index) const
inlinenodiscardconstexpr

Constant reference to component at index.

Parameters
indexIndex.
Returns
Constant reference.

◆ axis_w()

template<typename Real>
constexpr Vector4 nnm::Vector4< Real >::axis_w ( )
inlinestaticconstexpr

Normalized vector that points in the direction of the positive w-axis.

Returns
Result.

◆ axis_x()

template<typename Real>
constexpr Vector4 nnm::Vector4< Real >::axis_x ( )
inlinestaticconstexpr

Normalized vector that points in the direction of the positive x-axis.

Returns
Result.

◆ axis_y()

template<typename Real>
constexpr Vector4 nnm::Vector4< Real >::axis_y ( )
inlinestaticconstexpr

Normalized vector that points in the direction of the positive y-axis.

Returns
Result.

◆ axis_z()

template<typename Real>
constexpr Vector4 nnm::Vector4< Real >::axis_z ( )
inlinestaticconstexpr

Normalized vector that points in the direction of the positive z-axis.

Returns
Result.

◆ begin() [1/2]

template<typename Real>
Real * nnm::Vector4< Real >::begin ( )
inline

Start iterator.

Returns
Iterator.

◆ begin() [2/2]

template<typename Real>
const Real * nnm::Vector4< Real >::begin ( ) const
inlinenodiscard

Start constant iterator.

Returns
Constant iterator.

◆ ceil()

template<typename Real>
Vector4 nnm::Vector4< Real >::ceil ( ) const
inlinenodiscard

Component-wise ceiling.

Returns
Result.

◆ clamp()

template<typename Real>
Vector4 nnm::Vector4< Real >::clamp ( const Vector4< Real > & min,
const Vector4< Real > & max ) const
inlinenodiscardconstexpr

Component-wise clamp.

Parameters
minMinimum.
maxMaximum.
Returns
Result.

◆ clamp_length()

template<typename Real>
Vector4 nnm::Vector4< Real >::clamp_length ( const Real min,
const Real max ) const
inlinenodiscard

Vector with same direction but length is clamped between minimum and maximum values.

Parameters
minMinimum length.
maxMaximum length.
Returns
Result.

◆ dot()

template<typename Real>
Real nnm::Vector4< Real >::dot ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

Vector dot product.

Parameters
otherOther vector.
Returns
Result.

◆ end() [1/2]

template<typename Real>
Real * nnm::Vector4< Real >::end ( )
inline

End iterator.

Returns
Iterator.

◆ end() [2/2]

template<typename Real>
const Real * nnm::Vector4< Real >::end ( ) const
inlinenodiscard

End constant iterator.

Returns
Constant iterator.

◆ floor()

template<typename Real>
Vector4 nnm::Vector4< Real >::floor ( ) const
inlinenodiscard

Component-wise floor.

Returns
Result.

◆ from_quaternion()

template<typename Real>
Vector4< Real > nnm::Vector4< Real >::from_quaternion ( const Quaternion< Real > & quaternion)
staticconstexpr

Vector from quaternion. X, y, and z values are copied directly.

Parameters
quaternionQuaternion.
Returns
Result.

◆ inverse()

template<typename Real>
Vector4 nnm::Vector4< Real >::inverse ( ) const
inlinenodiscardconstexpr

Inverse vector.

Returns
Result.

◆ length()

template<typename Real>
Real nnm::Vector4< Real >::length ( ) const
inlinenodiscard

Vector length.

Returns
Result.

◆ length_sqrd()

template<typename Real>
Real nnm::Vector4< Real >::length_sqrd ( ) const
inlinenodiscardconstexpr

Squared vector length.

Returns
Result.

◆ lerp()

template<typename Real>
Vector4 nnm::Vector4< Real >::lerp ( const Vector4< Real > & to,
const Real weight ) const
inlinenodiscardconstexpr

Component-wise linear interpolation.

Parameters
toVector to interpolate to.
weightInterpolation weight typically from zero to one.
Returns
Result.

◆ lerp_clamped()

template<typename Real>
Vector4 nnm::Vector4< Real >::lerp_clamped ( const Vector4< Real > & to,
const Real weight ) const
inlinenodiscardconstexpr

Component-wise linear interpolation with weight clamped between zero and one.

Parameters
toVector to interpolate to.
weightInterpolation weight that is clamped between zero and one.
Returns
Result.

◆ max()

template<typename Real>
Real nnm::Vector4< Real >::max ( ) const
inlinenodiscardconstexpr

Maximum component.

Returns
Result.

◆ max_index()

template<typename Real>
uint8_t nnm::Vector4< Real >::max_index ( ) const
inlinenodiscardconstexpr

Index of maximum component.

Returns
Index.

◆ min()

template<typename Real>
Real nnm::Vector4< Real >::min ( ) const
inlinenodiscardconstexpr

Minimum component.

Returns
Result.

◆ min_index()

template<typename Real>
uint8_t nnm::Vector4< Real >::min_index ( ) const
inlinenodiscardconstexpr

Index of minimum component.

Returns
Index.

◆ normalize()

template<typename Real>
Vector4 nnm::Vector4< Real >::normalize ( ) const
inlinenodiscard

Normalize vector length to one.

Returns
Result.

◆ one()

template<typename Real>
constexpr Vector4 nnm::Vector4< Real >::one ( )
inlinestaticconstexpr

Vector with all components one.

Returns
Result.

◆ operator bool()

template<typename Real>
nnm::Vector4< Real >::operator bool ( ) const
inlineexplicitnodiscardconstexpr

Evaluates to false if all components are zero, true otherwise.

◆ operator!=()

template<typename Real>
bool nnm::Vector4< Real >::operator!= ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

Component-wise inequality.

Parameters
otherOther vector.
Returns
True if unequal, false otherwise.

◆ operator*() [1/3]

template<typename Real>
Vector4< Real > nnm::Vector4< Real >::operator* ( const Matrix4< Real > & matrix) const
nodiscardconstexpr

Vector-matrix multiplication.

Parameters
matrix4x4 matrix.
Returns
Result.

◆ operator*() [2/3]

template<typename Real>
Vector4 nnm::Vector4< Real >::operator* ( const Real value) const
inlinenodiscardconstexpr

Component-wise multiplication with value.

Parameters
valueValue.
Returns
Result.

◆ operator*() [3/3]

template<typename Real>
Vector4 nnm::Vector4< Real >::operator* ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

Component-wise multiplication.

Parameters
otherOther vector.
Returns
Result.

◆ operator*=() [1/2]

template<typename Real>
Vector4 & nnm::Vector4< Real >::operator*= ( const Real value)
inlineconstexpr

Component-wise multiplication with value.

Parameters
valueValue.
Returns
Reference to this modified vector.

◆ operator*=() [2/2]

template<typename Real>
Vector4 & nnm::Vector4< Real >::operator*= ( const Vector4< Real > & other)
inlineconstexpr

Component-wise multiplication.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator+() [1/2]

template<typename Real>
Vector4 nnm::Vector4< Real >::operator+ ( ) const
inlinenodiscardconstexpr

Unary plus. Does nothing but provide symmetry with unary minus.

Returns
Result.

◆ operator+() [2/2]

template<typename Real>
Vector4 nnm::Vector4< Real >::operator+ ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

Component-wise addition.

Parameters
otherOther vector.
Returns
Result.

◆ operator+=()

template<typename Real>
Vector4 & nnm::Vector4< Real >::operator+= ( const Vector4< Real > & other)
inlineconstexpr

Component-wise addition.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator-() [1/2]

template<typename Real>
Vector4 nnm::Vector4< Real >::operator- ( ) const
inlinenodiscardconstexpr

Component-wise negation.

Returns
Result.

◆ operator-() [2/2]

template<typename Real>
Vector4 nnm::Vector4< Real >::operator- ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

Component-wise subtraction.

Parameters
otherOther vector.
Returns
Result.

◆ operator-=()

template<typename Real>
Vector4 & nnm::Vector4< Real >::operator-= ( const Vector4< Real > & other)
inlineconstexpr

Component-wise subtraction.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator/() [1/2]

template<typename Real>
Vector4 nnm::Vector4< Real >::operator/ ( const Real value) const
inlinenodiscardconstexpr

Component-wise division with value.

Parameters
valueValue.
Returns
Result.

◆ operator/() [2/2]

template<typename Real>
Vector4 nnm::Vector4< Real >::operator/ ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

Component-wise division.

Parameters
otherOther vector.
Returns
Result.

◆ operator/=() [1/2]

template<typename Real>
Vector4 & nnm::Vector4< Real >::operator/= ( const Real value)
inlineconstexpr

Component-wise division with value.

Parameters
valueValue.
Returns
Reference to this modified vector.

◆ operator/=() [2/2]

template<typename Real>
Vector4 & nnm::Vector4< Real >::operator/= ( const Vector4< Real > & other)
inlineconstexpr

Component-wise division.

Parameters
otherOther vector.
Returns
Reference to this modified vector.

◆ operator<()

template<typename Real>
bool nnm::Vector4< Real >::operator< ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

Lexicographical comparison between components.

Parameters
otherOther vector.
Returns
True if less than, false otherwise.

◆ operator==()

template<typename Real>
bool nnm::Vector4< Real >::operator== ( const Vector4< Real > & other) const
inlinenodiscardconstexpr

Component-wise equality.

Parameters
otherOther vector.
Returns
True if equal, false otherwise.

◆ operator[]() [1/2]

template<typename Real>
Real & nnm::Vector4< Real >::operator[] ( const uint8_t index)
inlineconstexpr

Reference to component at index.

Parameters
indexIndex.
Returns
Reference.

◆ operator[]() [2/2]

template<typename Real>
const Real & nnm::Vector4< Real >::operator[] ( const uint8_t index) const
inlinenodiscardconstexpr

Constant reference to component at index.

Parameters
indexIndex.
Returns
Constant reference.

◆ outer()

template<typename Real>
Matrix4< Real > nnm::Vector4< Real >::outer ( const Vector4< Real > & other) const
nodiscardconstexpr

Vector outer product.

Parameters
otherOther vector.
Returns
Resulting 4x4 matrix.

◆ round()

template<typename Real>
Vector4 nnm::Vector4< Real >::round ( ) const
inlinenodiscard

Component-wise round.

Returns
Result.

◆ transform()

template<typename Real>
Vector4< Real > nnm::Vector4< Real >::transform ( const Transform3< Real > & by) const
nodiscardconstexpr

Transform by a three-dimensional transformation matrix about the origin.

Parameters
byTransformation matrix to transform by.
Returns
Result.

◆ transform_at()

template<typename Real>
Vector4< Real > nnm::Vector4< Real >::transform_at ( const Vector3< Real > & origin,
const Transform3< Real > & by ) const
nodiscardconstexpr

Transform by a three-dimensional transformation matrix about an origin.

Parameters
originOrigin to transform about.
byTransformation matrix to transform by.
Returns
Result.

◆ xy()

template<typename Real>
Vector2< Real > nnm::Vector4< Real >::xy ( ) const
inlinenodiscardconstexpr

Two-dimensional vector from the first two components (x and y) of this vector.

Returns
Resulting two-dimensional vector.

◆ xyz()

template<typename Real>
Vector3< Real > nnm::Vector4< Real >::xyz ( ) const
inlinenodiscardconstexpr

Three-dimensional vector from the first three components (x, y, and z) of this vector.

Returns
Resulting three-dimensional vector.

◆ zero()

template<typename Real>
constexpr Vector4 nnm::Vector4< Real >::zero ( )
inlinestaticconstexpr

Vector with all components zero.

Returns
Result.

Member Data Documentation

◆ w

template<typename Real>
Real nnm::Vector4< Real >::w

◆ x

template<typename Real>
Real nnm::Vector4< Real >::x

◆ y

template<typename Real>
Real nnm::Vector4< Real >::y

◆ z

template<typename Real>
Real nnm::Vector4< Real >::z

The documentation for this class was generated from the following file: