sandbox
Loading...
Searching...
No Matches
sbx::math::basic_vector< Size, Type > Class Template Reference

Fixed-size vector type. More...

#include <vector.hpp>

Public Types

using value_type = Type
 
using reference = value_type &
 
using const_reference = const value_type &
 
using size_type = std::size_t
 
using length_type = std::float_t
 

Public Member Functions

template<scalar Other = value_type>
requires (Size > 1u)
constexpr basic_vector (Other value=Other{0}) noexcept
 Constructs a vector with all components initialized to a value. More...
 
template<scalar Other = value_type>
requires (Size > 1u)
constexpr basic_vector (const basic_vector< Size, Other > &other) noexcept
 Constructs a vector from another vector with convertible scalar type. More...
 
constexpr basic_vector (const basic_vector &other) noexcept=default
 
constexpr basic_vector (basic_vector &&other) noexcept=default
 
auto operator= (const basic_vector &other) noexcept -> basic_vector &=default
 
auto operator= (basic_vector &&other) noexcept -> basic_vector &=default
 
constexpr auto data () noexcept -> value_type *
 Returns a pointer to the underlying contiguous storage. More...
 
constexpr auto data () const noexcept -> const value_type *
 Returns a pointer to the underlying contiguous storage (const). More...
 
constexpr auto operator[] (size_type index) noexcept -> reference
 Accesses a component by index. More...
 
constexpr auto operator[] (size_type index) const noexcept -> const_reference
 Accesses a component by index (const). More...
 
template<scalar Other>
requires (Size > 1u)
constexpr auto operator+= (const basic_vector< Size, Other > &other) noexcept -> basic_vector &
 Adds another vector to this vector. More...
 
template<scalar Other>
requires (Size > 1u)
constexpr auto operator-= (const basic_vector< Size, Other > &other) noexcept -> basic_vector &
 Subtracts another vector from this vector. More...
 
template<scalar Other>
requires (Size > 1u)
constexpr auto operator*= (Other scalar) noexcept -> basic_vector &
 Multiplies this vector by a scalar. More...
 
template<scalar Other>
requires (Size > 1u)
constexpr auto operator*= (const basic_vector< Size, Other > &other) noexcept -> basic_vector &
 Multiplies this vector component-wise by another vector. More...
 
template<scalar Other>
requires (Size > 1u)
constexpr auto operator/= (Other scalar) noexcept -> basic_vector &
 Divides this vector by a scalar. More...
 
constexpr auto length_squared () const noexcept -> length_type
 Returns the squared length of the vector. More...
 
constexpr auto length () const noexcept -> length_type
 Returns the length of the vector. More...
 
constexpr auto normalize () noexcept -> basic_vector &
 Normalizes the vector in-place. More...
 

Static Public Member Functions

static constexpr auto min (const basic_vector &vector) noexcept -> value_type
 Returns the minimum component of a vector. More...
 
template<scalar Lhs = value_type, scalar Rhs = value_type>
requires (Size > 1u)
static constexpr auto min (const basic_vector< Size, Lhs > &lhs, const basic_vector< Size, Rhs > &rhs) noexcept -> basic_vector
 Returns the component-wise minimum of two vectors. More...
 
static constexpr auto max (const basic_vector &vector) noexcept -> value_type
 Returns the maximum component of a vector. More...
 
template<scalar Lhs = value_type, scalar Rhs = value_type>
requires (Size > 1u)
static constexpr auto max (const basic_vector< Size, Lhs > &lhs, const basic_vector< Size, Rhs > &rhs) noexcept -> basic_vector
 Returns the component-wise maximum of two vectors. More...
 
template<scalar Lhs = value_type>
requires (Size > 1u)
static constexpr auto abs (const basic_vector< Size, Lhs > &vector) noexcept -> basic_vector
 Returns the component-wise absolute value of a vector. More...
 
template<size_type Axis, scalar Other = value_type>
requires (Axis < Size)
static constexpr auto splat (const basic_vector< Size, Other > &vector) noexcept -> basic_vector< Size, Other >
 Splat a single component across all axes. More...
 
static constexpr auto lerp (const basic_vector &x, const basic_vector &y, const value_type a) noexcept -> basic_vector
 Linearly interpolates between two vectors. More...
 

Protected Member Functions

template<std::convertible_to< value_type >... Args>
requires (sizeof...(Args) == Size)
constexpr basic_vector (Args &&... args) noexcept
 
constexpr basic_vector (std::array< value_type, Size > &&components) noexcept
 

Static Protected Member Functions

template<scalar Other>
requires (Size > 1u)
static constexpr auto fill (Other value) noexcept -> basic_vector
 
template<std::size_t Index, scalar Other>
requires (Size > 1u)
static constexpr auto axis (Other value) noexcept -> basic_vector
 

Detailed Description

template<std::size_t Size, scalar Type>
requires (Size > 1u)
class sbx::math::basic_vector< Size, Type >

Fixed-size vector type.

Template Parameters
SizeComponent count.
TypeScalar component type.

Constructor & Destructor Documentation

◆ basic_vector() [1/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Other>
requires (Size > 1u)
constexpr sbx::math::basic_vector< Size, Type >::basic_vector ( Other  value = Other{0})
constexprnoexcept

Constructs a vector with all components initialized to a value.

Template Parameters
OtherScalar type.
Parameters
valueInitialization value.

◆ basic_vector() [2/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Other>
requires (Size > 1u)
constexpr sbx::math::basic_vector< Size, Type >::basic_vector ( const basic_vector< Size, Other > &  other)
constexprnoexcept

Constructs a vector from another vector with convertible scalar type.

Template Parameters
OtherSource scalar type.
Parameters
otherSource vector.

Member Function Documentation

◆ abs()

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Lhs>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::abs ( const basic_vector< Size, Lhs > &  vector) -> basic_vector
staticconstexprnoexcept

Returns the component-wise absolute value of a vector.

Template Parameters
LhsScalar type of the input vector.
Parameters
vectorInput vector.
Returns
Vector with absolute component values.

◆ data() [1/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::data
constexprnoexcept

Returns a pointer to the underlying contiguous storage (const).

Returns
Pointer to the first component.

◆ data() [2/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::data
constexprnoexcept

Returns a pointer to the underlying contiguous storage.

Returns
Pointer to the first component.

◆ length()

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::length
constexprnoexcept

Returns the length of the vector.

Returns
Vector length.

◆ length_squared()

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::length_squared
constexprnoexcept

Returns the squared length of the vector.

Returns
Squared vector length.

◆ lerp()

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::lerp ( const basic_vector< Size, Type > &  x,
const basic_vector< Size, Type > &  y,
const value_type  a 
) -> basic_vector
staticconstexprnoexcept

Linearly interpolates between two vectors.

Parameters
xStart vector.
yEnd vector.
aInterpolation factor.
Returns
Interpolated vector.

◆ max() [1/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::max ( const basic_vector< Size, Type > &  vector) -> value_type
staticconstexprnoexcept

Returns the maximum component of a vector.

Parameters
vectorInput vector.
Returns
Largest component value.

◆ max() [2/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Lhs, scalar Rhs>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::max ( const basic_vector< Size, Lhs > &  lhs,
const basic_vector< Size, Rhs > &  rhs 
) -> basic_vector
staticconstexprnoexcept

Returns the component-wise maximum of two vectors.

Template Parameters
LhsLeft-hand scalar type.
RhsRight-hand scalar type.
Parameters
lhsLeft-hand side vector.
rhsRight-hand side vector.
Returns
Component-wise maximum vector.

◆ min() [1/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::min ( const basic_vector< Size, Type > &  vector) -> value_type
staticconstexprnoexcept

Returns the minimum component of a vector.

Parameters
vectorInput vector.
Returns
Smallest component value.

◆ min() [2/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Lhs, scalar Rhs>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::min ( const basic_vector< Size, Lhs > &  lhs,
const basic_vector< Size, Rhs > &  rhs 
) -> basic_vector
staticconstexprnoexcept

Returns the component-wise minimum of two vectors.

Template Parameters
LhsLeft-hand scalar type.
RhsRight-hand scalar type.
Parameters
lhsLeft-hand side vector.
rhsRight-hand side vector.
Returns
Component-wise minimum vector.

◆ normalize()

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::normalize
constexprnoexcept

Normalizes the vector in-place.

Returns
Reference to this vector.

◆ operator*=() [1/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Other>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::operator*= ( const basic_vector< Size, Other > &  other) -> basic_vector&
constexprnoexcept

Multiplies this vector component-wise by another vector.

Template Parameters
OtherScalar type of the operand.
Parameters
otherRight-hand side vector.
Returns
Reference to this vector.

◆ operator*=() [2/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Other>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::operator*= ( Other  scalar) -> basic_vector&
constexprnoexcept

Multiplies this vector by a scalar.

Template Parameters
OtherScalar type.
Parameters
scalarScalar multiplier.
Returns
Reference to this vector.

◆ operator+=()

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Other>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::operator+= ( const basic_vector< Size, Other > &  other) -> basic_vector&
constexprnoexcept

Adds another vector to this vector.

Template Parameters
OtherScalar type of the operand.
Parameters
otherRight-hand side vector.
Returns
Reference to this vector.

◆ operator-=()

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Other>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::operator-= ( const basic_vector< Size, Other > &  other) -> basic_vector&
constexprnoexcept

Subtracts another vector from this vector.

Template Parameters
OtherScalar type of the operand.
Parameters
otherRight-hand side vector.
Returns
Reference to this vector.

◆ operator/=()

template<std::size_t Size, scalar Type>
requires (Size > 1u)
template<scalar Other>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::operator/= ( Other  scalar) -> basic_vector&
constexprnoexcept

Divides this vector by a scalar.

Template Parameters
OtherScalar type.
Parameters
scalarScalar divisor.
Returns
Reference to this vector.

◆ operator[]() [1/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::operator[] ( size_type  index) const -> const_reference
constexprnoexcept

Accesses a component by index (const).

Parameters
indexComponent index.
Returns
Const reference to the component.

◆ operator[]() [2/2]

template<std::size_t Size, scalar Type>
requires (Size > 1u)
constexpr auto sbx::math::basic_vector< Size, Type >::operator[] ( size_type  index) -> reference
constexprnoexcept

Accesses a component by index.

Parameters
indexComponent index.
Returns
Reference to the component.

◆ splat()

template<std::size_t Size, scalar Type>
requires (Axis < Size)
template<typename basic_vector< Size, Type >::size_type Axis, scalar Other>
requires (Axis < Size)
constexpr auto sbx::math::basic_vector< Size, Type >::splat ( const basic_vector< Size, Other > &  vector) -> basic_vector<Size, Other>
staticconstexprnoexcept

Splat a single component across all axes.

Template Parameters
AxisComponent index to splat.
OtherScalar type.
Parameters
vectorInput vector.
Returns
Vector with all components set to vector[Axis].

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