UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
ufo::Vec< Dim, T > Struct Template Reference

A fixed-size arithmetic vector of up to 4 dimensions. More...

#include <lib/numeric/include/ufo/numeric/vec.hpp>

Inheritance diagram for ufo::Vec< Dim, T >:
ufo::Normal< Dim, T > ufo::PlanNode< Dim, T > ufo::TreeCoord< Dim, T >

Public Types

using size_type = std::size_t
 
using value_type = T
 

Public Member Functions

constexpr Vec () noexcept=default
 Default constructor; initializes all elements to zero.
 
constexpr auto begin (this auto &self) noexcept
 Returns an iterator to the first element.
 
constexpr auto data (this auto &self) noexcept
 Returns a pointer to the underlying element array.
 
constexpr auto end (this auto &self) noexcept
 Returns a past-the-end iterator.
 
template<class U >
constexpr explicit (!std::is_same_v< T, U >) Vec(Vec< Dim
 Converting constructor from a vector with a different element type.
 
template<std::convertible_to< T >... Args>
requires (sizeof...(Args) <= Dim)
 explicit (sizeof...(Args)==1) const expr Vec(Args... args) noexcept
 Constructs a vector from up to Dim individual element values.
 
constexpr Vecoperator%= (T rhs) noexcept
 Computes the remainder of every component divided by scalar rhs (integral types only).
 
constexpr Vecoperator%= (Vec const &rhs) noexcept
 Computes the remainder of each component divided by the corresponding component of rhs (integral types only).
 
constexpr Vecoperator&= (T rhs) noexcept
 Bitwise ANDs every component with scalar rhs (integral types only).
 
constexpr Vecoperator&= (Vec const &rhs) noexcept
 Bitwise ANDs each component with the corresponding component of rhs (integral types only).
 
constexpr Vecoperator*= (T rhs) noexcept
 Multiplies every component by scalar rhs.
 
constexpr Vecoperator*= (Vec const &rhs) noexcept
 Multiplies each component by the corresponding component of rhs.
 
constexpr Vec operator+ () const noexcept
 Unary identity operator.
 
constexpr Vecoperator+= (T rhs) noexcept
 Adds scalar rhs to every component.
 
constexpr Vecoperator+= (Vec const &rhs) noexcept
 Adds each component of rhs to the corresponding component.
 
constexpr Vec operator- () const noexcept
 Unary negation operator.
 
constexpr Vecoperator-= (T rhs) noexcept
 Subtracts scalar rhs from every component.
 
constexpr Vecoperator-= (Vec const &rhs) noexcept
 Subtracts each component of rhs from the corresponding component.
 
constexpr Vecoperator/= (T rhs) noexcept
 Divides every component by scalar rhs.
 
constexpr Vecoperator/= (Vec const &rhs) noexcept
 Divides each component by the corresponding component of rhs.
 
constexpr Vecoperator<<= (T rhs) noexcept
 Left-shifts every component by scalar rhs (integral types only).
 
constexpr Vecoperator<<= (Vec const &rhs) noexcept
 Left-shifts each component by the corresponding component of rhs (integral types only).
 
constexpr bool operator== (Vec const &) const =default
 Compares two vectors for equality (component-wise).
 
constexpr Vecoperator>>= (T rhs) noexcept
 Right-shifts every component by scalar rhs (integral types only).
 
constexpr Vecoperator>>= (Vec const &rhs) noexcept
 Right-shifts each component by the corresponding component of rhs (integral types only).
 
constexpr auto & operator[] (this auto &self, size_type i) noexcept
 Accesses the element at index i.
 
constexpr Vecoperator^= (T rhs) noexcept
 Bitwise XORs every component with scalar rhs (integral types only).
 
constexpr Vecoperator^= (Vec const &rhs) noexcept
 Bitwise XORs each component with the corresponding component of rhs (integral types only).
 
constexpr Vecoperator|= (T rhs) noexcept
 Bitwise ORs every component with scalar rhs (integral types only).
 
constexpr Vecoperator|= (Vec const &rhs) noexcept
 Bitwise ORs each component with the corresponding component of rhs (integral types only).
 
constexpr Vec operator~ () const noexcept
 Bitwise NOT operator (integral types only).
 
constexpr auto & w (this auto &self) noexcept
 Accesses the fourth component (w).
 
constexpr auto & x (this auto &self) noexcept
 Accesses the first component (x).
 
constexpr auto & y (this auto &self) noexcept
 Accesses the second component (y).
 
constexpr auto & z (this auto &self) noexcept
 Accesses the third component (z).
 

Static Public Member Functions

static constexpr std::size_t size () noexcept
 Returns the number of dimensions.
 

Public Attributes

std::array< T, Dim > fields {}
 
constexpr U const &other noexcept
 

Detailed Description

template<std::size_t Dim, class T>
requires (Dim <= 4 && std::is_arithmetic_v<T>)
struct ufo::Vec< Dim, T >

A fixed-size arithmetic vector of up to 4 dimensions.

Template Parameters
DimNumber of dimensions (1–4).
TArithmetic element type (e.g., int, float, double).

Definition at line 76 of file vec.hpp.

Member Typedef Documentation

◆ size_type

template<std::size_t Dim, class T >
using ufo::Vec< Dim, T >::size_type = std::size_t

Definition at line 78 of file vec.hpp.

◆ value_type

template<std::size_t Dim, class T >
using ufo::Vec< Dim, T >::value_type = T

Definition at line 77 of file vec.hpp.

Member Function Documentation

◆ begin()

template<std::size_t Dim, class T >
constexpr auto ufo::Vec< Dim, T >::begin ( this auto &  self)
inlineconstexprnoexcept

Returns an iterator to the first element.

Returns
Iterator (const or non-const, deduced from this).

Definition at line 176 of file vec.hpp.

◆ data()

template<std::size_t Dim, class T >
constexpr auto ufo::Vec< Dim, T >::data ( this auto &  self)
inlineconstexprnoexcept

Returns a pointer to the underlying element array.

Returns
Pointer to the first element (const or non-const, deduced from this).

Definition at line 191 of file vec.hpp.

◆ end()

template<std::size_t Dim, class T >
constexpr auto ufo::Vec< Dim, T >::end ( this auto &  self)
inlineconstexprnoexcept

Returns a past-the-end iterator.

Returns
Iterator (const or non-const, deduced from this).

Definition at line 185 of file vec.hpp.

◆ explicit() [1/2]

template<std::size_t Dim, class T >
template<class U >
constexpr ufo::Vec< Dim, T >::explicit ( !std::is_same_v< T, U >  )
constexpr

Converting constructor from a vector with a different element type.

Template Parameters
USource element type.
Parameters
[in]otherThe source vector; each element is static_cast to T.

Implicit when U is the same as T; explicit otherwise.

◆ explicit() [2/2]

template<std::size_t Dim, class T >
template<std::convertible_to< T >... Args>
requires (sizeof...(Args) <= Dim)
ufo::Vec< Dim, T >::explicit ( sizeof...  Args = = 1) const
inlinenoexcept

Constructs a vector from up to Dim individual element values.

Template Parameters
ArgsArgument types, each convertible to T.
Parameters
[in]argsElement values. Unspecified trailing elements are zero-initialized.

The constructor is explicit unless exactly one argument is provided, in which case implicit conversion (broadcast) is allowed.

Definition at line 98 of file vec.hpp.

◆ operator%=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator%= ( rhs)
inlineconstexprnoexcept

Computes the remainder of every component divided by scalar rhs (integral types only).

Parameters
[in]rhsScalar value.
Returns
Reference to *this.

Definition at line 428 of file vec.hpp.

◆ operator%=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator%= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Computes the remainder of each component divided by the corresponding component of rhs (integral types only).

Parameters
[in]rhsRight-hand side vector.
Returns
Reference to *this.

Definition at line 300 of file vec.hpp.

◆ operator&=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator&= ( rhs)
inlineconstexprnoexcept

Bitwise ANDs every component with scalar rhs (integral types only).

Parameters
[in]rhsScalar value.
Returns
Reference to *this.

Definition at line 440 of file vec.hpp.

◆ operator&=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator&= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Bitwise ANDs each component with the corresponding component of rhs (integral types only).

Parameters
[in]rhsRight-hand side vector.
Returns
Reference to *this.

Definition at line 313 of file vec.hpp.

◆ operator*=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator*= ( rhs)
inlineconstexprnoexcept

Multiplies every component by scalar rhs.

Parameters
[in]rhsScalar value.
Returns
Reference to *this.

Definition at line 405 of file vec.hpp.

◆ operator*=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator*= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Multiplies each component by the corresponding component of rhs.

Parameters
[in]rhsRight-hand side vector.
Returns
Reference to *this.

Definition at line 277 of file vec.hpp.

◆ operator-()

template<std::size_t Dim, class T >
constexpr Vec ufo::Vec< Dim, T >::operator- ( ) const
inlineconstexprnoexcept

Unary negation operator.

Returns
A vector with each element negated.

Definition at line 225 of file vec.hpp.

◆ operator-=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator-= ( rhs)
inlineconstexprnoexcept

Subtracts scalar rhs from every component.

Parameters
[in]rhsScalar value.
Returns
Reference to *this.

Definition at line 394 of file vec.hpp.

◆ operator-=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator-= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Subtracts each component of rhs from the corresponding component.

Parameters
[in]rhsRight-hand side vector.
Returns
Reference to *this.

Definition at line 266 of file vec.hpp.

◆ operator/=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator/= ( rhs)
inlineconstexprnoexcept

Divides every component by scalar rhs.

Parameters
[in]rhsScalar value.
Returns
Reference to *this.

Definition at line 416 of file vec.hpp.

◆ operator/=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator/= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Divides each component by the corresponding component of rhs.

Parameters
[in]rhsRight-hand side vector.
Returns
Reference to *this.

Definition at line 288 of file vec.hpp.

◆ operator<<=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator<<= ( rhs)
inlineconstexprnoexcept

Left-shifts every component by scalar rhs (integral types only).

Parameters
[in]rhsShift amount.
Returns
Reference to *this.

Definition at line 476 of file vec.hpp.

◆ operator<<=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator<<= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Left-shifts each component by the corresponding component of rhs (integral types only).

Parameters
[in]rhsPer-component shift amounts.
Returns
Reference to *this.

Definition at line 352 of file vec.hpp.

◆ operator==()

template<std::size_t Dim, class T >
constexpr bool ufo::Vec< Dim, T >::operator== ( Vec< Dim, T > const &  ) const
constexprdefault

Compares two vectors for equality (component-wise).

Parameters
[in]rhsThe vector to compare against.
Returns
true iff all corresponding elements are equal.

◆ operator>>=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator>>= ( rhs)
inlineconstexprnoexcept

Right-shifts every component by scalar rhs (integral types only).

Parameters
[in]rhsShift amount.
Returns
Reference to *this.

Definition at line 488 of file vec.hpp.

◆ operator>>=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator>>= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Right-shifts each component by the corresponding component of rhs (integral types only).

Parameters
[in]rhsPer-component shift amounts.
Returns
Reference to *this.

Definition at line 365 of file vec.hpp.

◆ operator^=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator^= ( rhs)
inlineconstexprnoexcept

Bitwise XORs every component with scalar rhs (integral types only).

Parameters
[in]rhsScalar value.
Returns
Reference to *this.

Definition at line 464 of file vec.hpp.

◆ operator^=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator^= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Bitwise XORs each component with the corresponding component of rhs (integral types only).

Parameters
[in]rhsRight-hand side vector.
Returns
Reference to *this.

Definition at line 339 of file vec.hpp.

◆ operator|=() [1/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator|= ( rhs)
inlineconstexprnoexcept

Bitwise ORs every component with scalar rhs (integral types only).

Parameters
[in]rhsScalar value.
Returns
Reference to *this.

Definition at line 452 of file vec.hpp.

◆ operator|=() [2/2]

template<std::size_t Dim, class T >
constexpr Vec & ufo::Vec< Dim, T >::operator|= ( Vec< Dim, T > const &  rhs)
inlineconstexprnoexcept

Bitwise ORs each component with the corresponding component of rhs (integral types only).

Parameters
[in]rhsRight-hand side vector.
Returns
Reference to *this.

Definition at line 326 of file vec.hpp.

◆ operator~()

template<std::size_t Dim, class T >
constexpr Vec ufo::Vec< Dim, T >::operator~ ( ) const
inlineconstexprnoexcept

Bitwise NOT operator (integral types only).

Returns
A vector with each element bitwise-complemented.

Definition at line 236 of file vec.hpp.

◆ size()

template<std::size_t Dim, class T >
static constexpr std::size_t ufo::Vec< Dim, T >::size ( )
inlinestaticconstexprnoexcept

Returns the number of dimensions.

Returns
Dim.

Definition at line 200 of file vec.hpp.

◆ w()

template<std::size_t Dim, class T >
constexpr auto & ufo::Vec< Dim, T >::w ( this auto &  self)
inlineconstexprnoexcept

Accesses the fourth component (w).

Returns
Reference to the fourth element (const or non-const, deduced from this).

Definition at line 166 of file vec.hpp.

◆ x()

template<std::size_t Dim, class T >
constexpr auto & ufo::Vec< Dim, T >::x ( this auto &  self)
inlineconstexprnoexcept

Accesses the first component (x).

Returns
Reference to the first element (const or non-const, deduced from this).

Definition at line 136 of file vec.hpp.

◆ y()

template<std::size_t Dim, class T >
constexpr auto & ufo::Vec< Dim, T >::y ( this auto &  self)
inlineconstexprnoexcept

Accesses the second component (y).

Returns
Reference to the second element (const or non-const, deduced from this).

Definition at line 146 of file vec.hpp.

◆ z()

template<std::size_t Dim, class T >
constexpr auto & ufo::Vec< Dim, T >::z ( this auto &  self)
inlineconstexprnoexcept

Accesses the third component (z).

Returns
Reference to the third element (const or non-const, deduced from this).

Definition at line 156 of file vec.hpp.

Member Data Documentation

◆ fields

template<std::size_t Dim, class T >
std::array<T, Dim> ufo::Vec< Dim, T >::fields {}

Definition at line 80 of file vec.hpp.

◆ noexcept

template<std::size_t Dim, class T >
constexpr U const& other ufo::Vec< Dim, T >::noexcept
Initial value:
{
std::ranges::transform(other, begin(), [](U const& v) { return static_cast<T>(v); })
constexpr auto begin(this auto &self) noexcept
Returns an iterator to the first element.
Definition vec.hpp:176

Definition at line 111 of file vec.hpp.


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