Topaz 5.0
Topaz Game Engine
Loading...
Searching...
No Matches
tz::vector< T, N > Struct Template Reference

Description

template<typename T, int N>
requires std::integral<T> || std::floating_point<T>
struct tz::vector< T, N >

Represents the generic vector.

#include "vector.hpp"

Public Member Functions

template<typename... Ts>
requires ( sizeof...(Ts) <= N && sizeof...(Ts) > 1 && std::is_convertible_v<std::tuple_element_t<0, std::tuple<Ts...>>, T>)
constexpr vector (Ts &&... ts)
 
constexpr vector (std::array< T, N > data)
 
 vector ()=default
 
const T & operator[] (std::size_t idx) const
 
T & operator[] (std::size_t idx)
 
vector< T, N > & operator+= (const vector< T, N > &rhs)
 Add one vector to another.
 
vector< T, N > & operator-= (const vector< T, N > &rhs)
 Subtract one vector from another.
 
vector< T, N > & operator*= (const vector< T, N > &rhs)
 Multiply one vector with another.
 
vector< T, N > & operator/= (const vector< T, N > &rhs)
 Divide one vector by another.
 
vector< T, N > operator+ (const vector< T, N > &rhs) const
 Add one vector to another.
 
vector< T, N > operator- (const vector< T, N > &rhs) const
 Subtract one vector from another.
 
vector< T, N > operator* (const vector< T, N > &rhs) const
 Multiply one vector with another.
 
vector< T, N > operator/ (const vector< T, N > &rhs) const
 Divide one vector by another.
 
length () const
 Retrieve the magnitude of the vector.
 
dot (const vector< T, N > &rhs) const
 Retrieve the dot (scalar) product of two vectors.
 
vector< T, N > cross (const vector< T, N > &rhs) const
 Retrieve a cross product between two three-dimensional vectors.
 
bool operator== (const vector< T, N > &rhs) const =default
 Compare two vectors. Two vectors are equal if all of their components are exactly equal.
 

Static Public Member Functions

static constexpr vector< T, N > zero ()
 Retrieve a vector filled with zeroes.
 
static constexpr vector< T, N > filled (T t)
 Retrieve a vector filled with the given value.
 

Constructor & Destructor Documentation

◆ vector() [1/3]

template<typename T , int N>
template<typename... Ts>
requires ( sizeof...(Ts) <= N && sizeof...(Ts) > 1 && std::is_convertible_v<std::tuple_element_t<0, std::tuple<Ts...>>, T>)
tz::vector< T, N >::vector ( Ts &&... ts)
inlineconstexpr

Construct a vector directly using a variadic parameter pack value. If the number of parameters provided is less than the vector's length, the remainder elements of the vector will be of indeterminate value.

◆ vector() [2/3]

template<typename T , int N>
tz::vector< T, N >::vector ( std::array< T, N > data)
inlineconstexpr

Construct a vector using an existing array of appropriate size.

◆ vector() [3/3]

template<typename T , int N>
tz::vector< T, N >::vector ( )
default

Default-constructed vectors have indeterminate values.

Member Function Documentation

◆ zero()

template<typename T , int N>
static constexpr vector< T, N > tz::vector< T, N >::zero ( )
inlinestaticconstexpr

Retrieve a vector filled with zeroes.

◆ filled()

template<typename T , int N>
static constexpr vector< T, N > tz::vector< T, N >::filled ( T t)
inlinestaticconstexpr

Retrieve a vector filled with the given value.

◆ operator[]() [1/2]

template<typename T , int N>
const T & tz::vector< T, N >::operator[] ( std::size_t idx) const

Retrieve the element value at the given index. Precondition: idx < S. Otherwise, this will assert and invoke UB.

Returns
The value at the given index.

◆ operator[]() [2/2]

template<typename T , int N>
T & tz::vector< T, N >::operator[] ( std::size_t idx)

Retrieve the element value at the given index. Precondition: idx < S. Otherwise, this will assert and invoke UB.

Returns
The value at the given index.

◆ operator+=()

template<typename T , int N>
vector< T, N > & tz::vector< T, N >::operator+= ( const vector< T, N > & rhs)

Add one vector to another.

◆ operator-=()

template<typename T , int N>
vector< T, N > & tz::vector< T, N >::operator-= ( const vector< T, N > & rhs)

Subtract one vector from another.

◆ operator*=()

template<typename T , int N>
vector< T, N > & tz::vector< T, N >::operator*= ( const vector< T, N > & rhs)

Multiply one vector with another.

◆ operator/=()

template<typename T , int N>
vector< T, N > & tz::vector< T, N >::operator/= ( const vector< T, N > & rhs)

Divide one vector by another.

◆ operator+()

template<typename T , int N>
vector< T, N > tz::vector< T, N >::operator+ ( const vector< T, N > & rhs) const
inline

Add one vector to another.

◆ operator-()

template<typename T , int N>
vector< T, N > tz::vector< T, N >::operator- ( const vector< T, N > & rhs) const
inline

Subtract one vector from another.

◆ operator*()

template<typename T , int N>
vector< T, N > tz::vector< T, N >::operator* ( const vector< T, N > & rhs) const
inline

Multiply one vector with another.

◆ operator/()

template<typename T , int N>
vector< T, N > tz::vector< T, N >::operator/ ( const vector< T, N > & rhs) const
inline

Divide one vector by another.

◆ length()

template<typename T , int N>
T tz::vector< T, N >::length ( ) const

Retrieve the magnitude of the vector.

◆ dot()

template<typename T , int N>
T tz::vector< T, N >::dot ( const vector< T, N > & rhs) const

Retrieve the dot (scalar) product of two vectors.

◆ cross()

template<typename T , int N>
vector< T, N > tz::vector< T, N >::cross ( const vector< T, N > & rhs) const

Retrieve a cross product between two three-dimensional vectors.

Warning
If you invoke this on a vector that is not three-dimensional, the program is ill-formed.

◆ operator==()

template<typename T , int N>
bool tz::vector< T, N >::operator== ( const vector< T, N > & rhs) const
default

Compare two vectors. Two vectors are equal if all of their components are exactly equal.