mal-math
C++20 mathematics library.
All Classes Namespaces Files Functions Variables Typedefs Concepts
mal_math::vec< 3, T > Struct Template Reference

Represents a 3D vector of a given primitive type. More...

#include "vec3.hpp"

Collaboration diagram for mal_math::vec< 3, T >:
[legend]

Public Types

using type = T
 Type of the vector elements.
 

Public Member Functions

constexpr vec ()=default
 Default constructor.
 
template<Primitive U>
constexpr vec (U value)
 Constructor initializing all elements to the given value.
 
template<Primitive A, Primitive B, Primitive C>
constexpr vec (A a, B b, C c)
 Constructor for initializing the vector with three values.
 
template<typename... U>
constexpr vec (U... data)
 Variadic constructor.
 
constexpr vec (std::array< T, size > const &arr)
 Constructor from std::array.
 
constexpr vec (std::array< T, size > &&arr)
 Move constructor from std::array.
 
constexpr void reset () noexcept
 Resets the vector to the zero vector.
 
template<typename U >
constexpr vec< size, T > & operator= (_detail::rvec< size, U > const &b)
 Overloaded assignment operator.
 
template<typename U >
constexpr vec< size, T > & operator= (vec< size, U > const &b)
 Overloaded assignment operator for another vec object.
 
constexpr vec< 3, T > const & operator+ () const noexcept
 Overloaded unary plus operator.
 
constexpr vec< 3, T > operator- () const noexcept
 Overloaded unary minus operator.
 
template<Primitive U>
constexpr vec< 3, T > & operator+= (U const value) noexcept
 
template<Primitive U>
constexpr vec< 3, T > & operator-= (U const value) noexcept
 
template<Primitive U>
constexpr vec< 3, T > & operator*= (U const value) noexcept
 
template<Primitive U>
constexpr vec< 3, T > & operator/= (U const value) noexcept
 
template<Primitive U>
constexpr vec< 3, T > & operator%= (U const value) noexcept
 
template<AnyVec U>
requires (size == U::size)
constexpr vec< 3, T > & operator+= (U const &other) noexcept
 
template<AnyVec U>
requires (size == U::size)
constexpr vec< 3, T > & operator-= (U const &other) noexcept
 
template<AnyVec U>
requires (size == U::size)
constexpr vec< 3, T > & operator*= (U const &other) noexcept
 
template<AnyVec U>
requires (size == U::size)
constexpr vec< 3, T > & operator/= (U const &other) noexcept
 
template<AnyVec U>
requires (size == U::size)
constexpr vec< 3, T > & operator%= (U const &other) noexcept
 
constexpr T & operator[] (size_t i)
 Overloaded subscript operator for non-const rvec.
 
constexpr T const & operator[] (size_t i) const
 Overloaded subscript operator for const rvec.
 

Static Public Member Functions

static constexpr vec< 3, T > zero () noexcept
 Returns a zero vector.
 

Public Attributes

union mal_math::vec< 3, T >:: { ... }  
 Union allowing multiple ways to access the vector elements.
 

Static Public Attributes

static constexpr size_t size = 3
 Number of elements in the vector.
 

Private Member Functions

template<Primitive U>
constexpr void unpack_data (size_t offset, U u)
 Unpacks a single primitive value into the vector data.
 
template<class V >
constexpr void unpack_data (size_t offset, V vec)
 Unpacks a vector into the matrix data.
 
template<typename A , typename B , typename... C>
constexpr void unpack_data (size_t offset, A a, B b, C... c)
 Recursively unpacks multiple values into the vector data.
 

Static Private Member Functions

template<Primitive _>
static constexpr size_t get_parameter_pack_size ()
 Determines the size of a parameter pack for primitive types.
 
template<class V >
static constexpr size_t get_parameter_pack_size ()
 Determines the size of a parameter pack for vector types.
 
template<typename A , typename B , typename... C>
static constexpr size_t get_parameter_pack_size ()
 Determines the size of a parameter pack for a mixed set of types.
 

Detailed Description

template<Primitive T>
struct mal_math::vec< 3, T >

Represents a 3D vector of a given primitive type.

Template Parameters
TThe primitive type of the vector.

Definition at line 23 of file vec3.hpp.

Member Typedef Documentation

◆ type

template<Primitive T>
using mal_math::vec< 3, T >::type = T

Type of the vector elements.

Definition at line 27 of file vec3.hpp.

Constructor & Destructor Documentation

◆ vec() [1/6]

template<Primitive T>
mal_math::vec< 3, T >::vec ( )
constexprdefault

Default constructor.

◆ vec() [2/6]

template<Primitive T>
template<Primitive U>
mal_math::vec< 3, T >::vec ( U value)
constexpr

Constructor initializing all elements to the given value.

Template Parameters
UType of the value.
Parameters
valueThe value to initialize all elements with.

Definition at line 7 of file vec3.inl.

◆ vec() [3/6]

template<Primitive T>
template<Primitive A, Primitive B, Primitive C>
mal_math::vec< 3, T >::vec ( A a,
B b,
C c )
constexpr

Constructor for initializing the vector with three values.

Template Parameters
AType of the first value.
BType of the second value.
CType of the third value.
Parameters
aFirst value.
bSecond value.
cThird value.

Definition at line 10 of file vec3.inl.

◆ vec() [4/6]

template<Primitive T>
template<typename... U>
mal_math::vec< 3, T >::vec ( U... data)
constexpr

Variadic constructor.

Template Parameters
UTypes of the values.
Parameters
dataValues to initialize the vector with.

Definition at line 18 of file vec3.inl.

◆ vec() [5/6]

template<Primitive T>
mal_math::vec< 3, T >::vec ( std::array< T, size > const & arr)
inlineconstexpr

Constructor from std::array.

Definition at line 61 of file vec3.hpp.

◆ vec() [6/6]

template<Primitive T>
mal_math::vec< 3, T >::vec ( std::array< T, size > && arr)
inlineconstexpr

Move constructor from std::array.

Definition at line 63 of file vec3.hpp.

Member Function Documentation

◆ get_parameter_pack_size() [1/3]

template<Primitive T>
template<class V >
size_t mal_math::vec< 3, T >::get_parameter_pack_size ( )
staticconstexprprivate

Determines the size of a parameter pack for primitive types.

Returns
size_t Always returns 1 for primitive types.

Definition at line 148 of file vec3.inl.

◆ get_parameter_pack_size() [2/3]

template<Primitive T>
template<class V >
static constexpr size_t mal_math::vec< 3, T >::get_parameter_pack_size ( )
staticconstexprprivate

Determines the size of a parameter pack for vector types.

Returns
size_t Returns the size attribute of the vector type.

◆ get_parameter_pack_size() [3/3]

template<Primitive T>
template<typename A , typename B , typename... C>
size_t mal_math::vec< 3, T >::get_parameter_pack_size ( )
staticconstexprprivate

Determines the size of a parameter pack for a mixed set of types.

Returns
size_t Returns the cumulative size of the parameter pack types.

Definition at line 160 of file vec3.inl.

◆ operator%=() [1/2]

template<Primitive T>
requires (size == U::size)
template<AnyVec U>
requires (size == U::size)
vec< 3, T > & mal_math::vec< 3, T >::operator%= ( U const & other)
constexprnoexcept

Definition at line 126 of file vec3.inl.

◆ operator%=() [2/2]

template<Primitive T>
template<Primitive U>
vec< 3, T > & mal_math::vec< 3, T >::operator%= ( U const value)
constexprnoexcept

Definition at line 79 of file vec3.inl.

◆ operator*=() [1/2]

template<Primitive T>
requires (size == U::size)
template<AnyVec U>
requires (size == U::size)
vec< 3, T > & mal_math::vec< 3, T >::operator*= ( U const & other)
constexprnoexcept

Definition at line 107 of file vec3.inl.

◆ operator*=() [2/2]

template<Primitive T>
template<Primitive U>
vec< 3, T > & mal_math::vec< 3, T >::operator*= ( U const value)
constexprnoexcept

Definition at line 61 of file vec3.inl.

◆ operator+()

template<Primitive T>
vec< 3, T > const & mal_math::vec< 3, T >::operator+ ( ) const
nodiscardconstexprnoexcept

Overloaded unary plus operator.

Definition at line 31 of file vec3.inl.

◆ operator+=() [1/2]

template<Primitive T>
requires (size == U::size)
template<AnyVec U>
requires (size == U::size)
vec< 3, T > & mal_math::vec< 3, T >::operator+= ( U const & other)
constexprnoexcept

Definition at line 89 of file vec3.inl.

◆ operator+=() [2/2]

template<Primitive T>
template<Primitive U>
vec< 3, T > & mal_math::vec< 3, T >::operator+= ( U const value)
constexprnoexcept

Definition at line 43 of file vec3.inl.

◆ operator-()

template<Primitive T>
vec< 3, T > mal_math::vec< 3, T >::operator- ( ) const
nodiscardconstexprnoexcept

Overloaded unary minus operator.

Definition at line 36 of file vec3.inl.

◆ operator-=() [1/2]

template<Primitive T>
requires (size == U::size)
template<AnyVec U>
requires (size == U::size)
vec< 3, T > & mal_math::vec< 3, T >::operator-= ( U const & other)
constexprnoexcept

Definition at line 98 of file vec3.inl.

◆ operator-=() [2/2]

template<Primitive T>
template<Primitive U>
vec< 3, T > & mal_math::vec< 3, T >::operator-= ( U const value)
constexprnoexcept

Definition at line 52 of file vec3.inl.

◆ operator/=() [1/2]

template<Primitive T>
requires (size == U::size)
template<AnyVec U>
requires (size == U::size)
vec< 3, T > & mal_math::vec< 3, T >::operator/= ( U const & other)
constexprnoexcept

Definition at line 116 of file vec3.inl.

◆ operator/=() [2/2]

template<Primitive T>
template<Primitive U>
vec< 3, T > & mal_math::vec< 3, T >::operator/= ( U const value)
constexprnoexcept

Definition at line 70 of file vec3.inl.

◆ operator=() [1/2]

template<Primitive T>
template<typename U >
vec< size, T > & mal_math::vec< 3, T >::operator= ( _detail::rvec< size, U > const & b)
inlineconstexpr

Overloaded assignment operator.

Definition at line 71 of file vec3.hpp.

◆ operator=() [2/2]

template<Primitive T>
template<typename U >
vec< size, T > & mal_math::vec< 3, T >::operator= ( vec< size, U > const & b)
inlineconstexpr

Overloaded assignment operator for another vec object.

Definition at line 81 of file vec3.hpp.

◆ operator[]() [1/2]

template<Primitive T>
T & mal_math::vec< 3, T >::operator[] ( size_t i)
nodiscardconstexpr

Overloaded subscript operator for non-const rvec.

Definition at line 134 of file vec3.inl.

◆ operator[]() [2/2]

template<Primitive T>
T const & mal_math::vec< 3, T >::operator[] ( size_t i) const
nodiscardconstexpr

Overloaded subscript operator for const rvec.

Definition at line 140 of file vec3.inl.

◆ reset()

template<Primitive T>
void mal_math::vec< 3, T >::reset ( )
constexprnoexcept

Resets the vector to the zero vector.

Definition at line 25 of file vec3.inl.

◆ unpack_data() [1/3]

template<Primitive T>
template<typename A , typename B , typename... C>
void mal_math::vec< 3, T >::unpack_data ( size_t offset,
A a,
B b,
C... c )
constexprprivate

Recursively unpacks multiple values into the vector data.

Parameters
offsetThe position to start unpacking in the vector data.
firstThe first value to unpack.
secondThe second value to unpack.
restThe remaining values to unpack.

Definition at line 182 of file vec3.inl.

◆ unpack_data() [2/3]

template<Primitive T>
template<class V >
void mal_math::vec< 3, T >::unpack_data ( size_t offset,
V u )
constexprprivate

Unpacks a single primitive value into the vector data.

Parameters
offsetThe position to start unpacking in the vector data.
uThe primitive value to unpack.

Definition at line 167 of file vec3.inl.

◆ unpack_data() [3/3]

template<Primitive T>
template<class V >
void mal_math::vec< 3, T >::unpack_data ( size_t offset,
V vec )
constexprprivate

Unpacks a vector into the matrix data.

Parameters
offsetThe position to start unpacking in the vector data.
vecThe vector to unpack.

◆ zero()

template<Primitive T>
static constexpr vec< 3, T > mal_math::vec< 3, T >::zero ( )
inlinestaticconstexprnoexcept

Returns a zero vector.

Definition at line 65 of file vec3.hpp.

Member Data Documentation

◆ []

union mal_math::vec< 3, T > { ... } mal_math::vec< 3, T >

Union allowing multiple ways to access the vector elements.

◆ b

template<Primitive T>
T mal_math::vec< 3, T >::b

Definition at line 135 of file vec3.hpp.

◆ data

template<Primitive T>
std::array<T, 3> mal_math::vec< 3, T >::data

Definition at line 138 of file vec3.hpp.

◆ g

template<Primitive T>
T mal_math::vec< 3, T >::g

Definition at line 131 of file vec3.hpp.

◆ p

template<Primitive T>
T mal_math::vec< 3, T >::p

Definition at line 135 of file vec3.hpp.

◆ r

template<Primitive T>
T mal_math::vec< 3, T >::r

Definition at line 127 of file vec3.hpp.

◆ s

template<Primitive T>
T mal_math::vec< 3, T >::s

Definition at line 127 of file vec3.hpp.

◆ size

template<Primitive T>
size_t mal_math::vec< 3, T >::size = 3
staticconstexpr

Number of elements in the vector.

Definition at line 29 of file vec3.hpp.

◆ t

template<Primitive T>
T mal_math::vec< 3, T >::t

Definition at line 131 of file vec3.hpp.

◆ x

template<Primitive T>
T mal_math::vec< 3, T >::x

Definition at line 127 of file vec3.hpp.

◆ x_anonymous_padding_

template<Primitive T>
T mal_math::vec< 3, T >::x_anonymous_padding_

Definition at line 142 of file vec3.hpp.

◆ xy

template<Primitive T>
vec<2, T> mal_math::vec< 3, T >::xy

Definition at line 139 of file vec3.hpp.

◆ y

template<Primitive T>
T mal_math::vec< 3, T >::y

Definition at line 131 of file vec3.hpp.

◆ yz

template<Primitive T>
vec<2, T> mal_math::vec< 3, T >::yz

Definition at line 143 of file vec3.hpp.

◆ z

template<Primitive T>
T mal_math::vec< 3, T >::z

Definition at line 135 of file vec3.hpp.


The documentation for this struct was generated from the following files: