EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
EBGeometry::Vec3T< T > Class Template Reference

Three-dimensional vector class with arithmetic operators. More...

#include <EBGeometry_Vec.hpp>

Collaboration diagram for EBGeometry::Vec3T< T >:
Collaboration graph
[legend]

Public Member Functions

 Vec3T () noexcept=default
 Default constructor. Leaves the components uninitialized.
 
constexpr Vec3T (const Vec3T< T > &a_u) noexcept=default
 Copy constructor.
 
constexpr Vec3T (const T &a_x, const T &a_y, const T &a_z) noexcept
 Full constructor.
 
 ~Vec3T () noexcept=default
 Destructor (does nothing)
 
constexpr bool lessLX (const Vec3T< T > &u) const noexcept
 Lexicographic comparison (x first, then y, then z).
 
constexpr T & operator[] (size_t i) noexcept
 Mutable element access.
 
constexpr const T & operator[] (size_t i) const noexcept
 Const element access.
 
constexpr bool operator== (const Vec3T< T > &u) const noexcept
 Equality comparison.
 
constexpr bool operator!= (const Vec3T< T > &u) const noexcept
 Inequality comparison.
 
constexpr Vec3T< T > & operator= (const Vec3T< T > &u) noexcept=default
 Assignment operator.
 
constexpr Vec3T< T > operator+ (const Vec3T< T > &u) const noexcept
 Addition operator.
 
constexpr Vec3T< T > operator- (const Vec3T< T > &u) const noexcept
 Subtraction operator. Returns a new vector with subtracted components.
 
constexpr Vec3T< T > operator+ () const noexcept
 Identity operator.
 
constexpr Vec3T< T > operator- () const noexcept
 Negation operator.
 
constexpr Vec3T< T > operator* (const T &s) const noexcept
 Multiplication operator. Returns a vector with scalar multiplied components.
 
constexpr Vec3T< T > operator* (const Vec3T< T > &s) const noexcept
 Component-wise multiplication operator.
 
constexpr Vec3T< T > operator/ (const T &s) const noexcept
 Division operator. Returns a vector with scalar divided components.
 
constexpr Vec3T< T > operator/ (const Vec3T< T > &v) const noexcept
 Component-wise division operator.
 
constexpr Vec3T< T > & operator+= (const Vec3T< T > &u) noexcept
 Vector addition operator.
 
constexpr Vec3T< T > & operator-= (const Vec3T< T > &u) noexcept
 Vector subtraction operator.
 
constexpr Vec3T< T > & operator*= (const T &s) noexcept
 Vector multiplication operator.
 
constexpr Vec3T< T > & operator/= (const T &s) noexcept
 In-place scalar division operator.
 
constexpr Vec3T< T > cross (const Vec3T< T > &u) const noexcept
 Vector cross product.
 
constexpr T dot (const Vec3T< T > &u) const noexcept
 Vector dot product.
 
size_t minDir (const bool a_doAbs) const noexcept
 Return the index of the smallest component (optionally by magnitude).
 
size_t maxDir (const bool a_doAbs) const noexcept
 Return the direction which has the largest component (can be absolute)
 
T length () const noexcept
 Compute vector length.
 
constexpr T length2 () const noexcept
 Compute squared vector length.
 
Deleted ordering operators

Vec3T has no ordering operators.

These once meant "every component less (greater, ...) than", which is not a strict weak ordering: two different vectors can each fail to be less than the other, so std::set, std::map and std::sort built on them silently merge or misorder distinct vectors. Compare components explicitly, or use lessLX() for a lexicographic ordering.

bool operator< (const Vec3T< T > &u) const noexcept=delete
 
bool operator> (const Vec3T< T > &u) const noexcept=delete
 
bool operator<= (const Vec3T< T > &u) const noexcept=delete
 
bool operator>= (const Vec3T< T > &u) const noexcept=delete
 

Static Public Member Functions

static constexpr Vec3T< T > zeros () noexcept
 Return a vector with x = y = z = 0.
 
static constexpr Vec3T< T > ones () noexcept
 Return a vector with x = y = z = 1.
 
static constexpr Vec3T< T > unit (const size_t a_dir) noexcept
 Return the unit basis vector for the given coordinate axis.
 
static constexpr Vec3T< T > min () noexcept
 Return the most-negative representable vector.
 
static constexpr Vec3T< T > max () noexcept
 Return the most-positive representable vector.
 
static constexpr Vec3T< T > infinity () noexcept
 Return a vector with infinite components.
 

Protected Attributes

Array< T, 3 > m_X
 Vector components.
 

Detailed Description

template<typename T>
class EBGeometry::Vec3T< T >

Three-dimensional vector class with arithmetic operators.

The components are reached through operator[] (index 0, 1 or 2).

Note
Vec3T is the point and vector type used throughout EBGeometry. It is always 3D, i.e. independent of the application's spatial dimension.
Template Parameters
TFloating-point precision (float or double).

Constructor & Destructor Documentation

◆ Vec3T() [1/3]

template<typename T >
EBGeometry::Vec3T< T >::Vec3T ( )
defaultnoexcept

Default constructor. Leaves the components uninitialized.

Defaulted, so that Vec3T is trivially default constructible and can be the element type of a CUDA/HIP __shared__ array, which may not have an initializer. As with a plain T, Vec3T<T> v; leaves v uninitialized, while value initialization (Vec3T<T> v{};, Vec3T<T>()) zeroes it, as does zeros().

◆ Vec3T() [2/3]

template<typename T >
constexpr EBGeometry::Vec3T< T >::Vec3T ( const Vec3T< T > &  a_u)
constexprdefaultnoexcept

Copy constructor.

Parameters
[in]a_uOther vector

Sets *this = a_u

◆ Vec3T() [3/3]

template<typename T >
constexpr EBGeometry::Vec3T< T >::Vec3T ( const T &  a_x,
const T &  a_y,
const T &  a_z 
)
constexprnoexcept

Full constructor.

Parameters
[in]a_xFirst vector component
[in]a_ySecond vector component
[in]a_zThird vector component

Sets X[0] = a_x, X[1] = a_y and X[2] = a_z.

Member Function Documentation

◆ cross()

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::cross ( const Vec3T< T > &  u) const
inlineconstexprnoexcept

Vector cross product.

Parameters
[in]uOther vector.
Returns
Cross product (*this) × u.

◆ dot()

template<typename T >
constexpr T EBGeometry::Vec3T< T >::dot ( const Vec3T< T > &  u) const
inlineconstexprnoexcept

Vector dot product.

Parameters
[in]uOther vector.
Returns
Scalar dot product (*this) · u.

◆ infinity()

template<typename T >
static constexpr Vec3T< T > EBGeometry::Vec3T< T >::infinity ( )
inlinestaticconstexprnoexcept

Return a vector with infinite components.

Returns
Vector with each component equal to Math::Limits<T>::infinity().

◆ length()

template<typename T >
T EBGeometry::Vec3T< T >::length ( ) const
inlinenoexcept

Compute vector length.

Not constexpr, since std::sqrt is not.

Returns
Euclidean length: std::sqrt(X[0]*X[0] + X[1]*X[1] + X[2]*X[2]).

◆ length2()

template<typename T >
constexpr T EBGeometry::Vec3T< T >::length2 ( ) const
inlineconstexprnoexcept

Compute squared vector length.

Returns
Squared Euclidean length: X[0]*X[0] + X[1]*X[1] + X[2]*X[2].

◆ lessLX()

template<typename T >
constexpr bool EBGeometry::Vec3T< T >::lessLX ( const Vec3T< T > &  u) const
inlineconstexprnoexcept

Lexicographic comparison (x first, then y, then z).

Returns true if this vector is lexicographically less than u, i.e. the first differing component of (*this) is less than the corresponding component of u.

Parameters
[in]uOther vector.
Returns
True if (*this) is lexicographically less than u.

◆ max()

template<typename T >
static constexpr Vec3T< T > EBGeometry::Vec3T< T >::max ( )
inlinestaticconstexprnoexcept

Return the most-positive representable vector.

Returns
Vector with each component equal to Math::Limits<T>::max().

◆ maxDir()

template<typename T >
size_t EBGeometry::Vec3T< T >::maxDir ( const bool  a_doAbs) const
inlinenoexcept

Return the direction which has the largest component (can be absolute)

Parameters
[in]a_doAbsIf true, evaluate component magnitudes rather than values.
Returns
Direction with the biggest component

◆ min()

template<typename T >
static constexpr Vec3T< T > EBGeometry::Vec3T< T >::min ( )
inlinestaticconstexprnoexcept

Return the most-negative representable vector.

Returns
Vector with each component equal to -Math::Limits<T>::max().

◆ minDir()

template<typename T >
size_t EBGeometry::Vec3T< T >::minDir ( const bool  a_doAbs) const
inlinenoexcept

Return the index of the smallest component (optionally by magnitude).

Parameters
[in]a_doAbsIf true, compare |X[i]| instead of X[i].
Returns
Index (0, 1, or 2) of the component with the smallest value (or magnitude).

◆ ones()

template<typename T >
static constexpr Vec3T< T > EBGeometry::Vec3T< T >::ones ( )
inlinestaticconstexprnoexcept

Return a vector with x = y = z = 1.

Returns
Ones vector (1, 1, 1).

◆ operator!=()

template<typename T >
constexpr bool EBGeometry::Vec3T< T >::operator!= ( const Vec3T< T > &  u) const
inlineconstexprnoexcept

Inequality comparison.

Parameters
[in]uOther vector.
Returns
True if any component differs.

◆ operator*() [1/2]

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::operator* ( const T &  s) const
inlineconstexprnoexcept

Multiplication operator. Returns a vector with scalar multiplied components.

Parameters
[in]sScalar to multiply by
Returns
Returns a new vector with X[i] = this->X[i] * s

◆ operator*() [2/2]

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::operator* ( const Vec3T< T > &  s) const
inlineconstexprnoexcept

Component-wise multiplication operator.

Parameters
[in]sScalar to multiply by
Returns
Returns a new vector with X[i] = this->X[i] * s[i] for each component.

◆ operator*=()

template<typename T >
constexpr Vec3T< T > & EBGeometry::Vec3T< T >::operator*= ( const T &  s)
inlineconstexprnoexcept

Vector multiplication operator.

Parameters
[in]sScalar to multiply by
Returns
(*this), with X[i] *= s for each component.

◆ operator+() [1/2]

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::operator+ ( ) const
inlineconstexprnoexcept

Identity operator.

Returns
Copy of this vector (unary plus, component-wise identity).

◆ operator+() [2/2]

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::operator+ ( const Vec3T< T > &  u) const
inlineconstexprnoexcept

Addition operator.

Parameters
[in]uOther vector.
Returns
New vector with X[i] = this->X[i] + u[i] for each component.

◆ operator+=()

template<typename T >
constexpr Vec3T< T > & EBGeometry::Vec3T< T >::operator+= ( const Vec3T< T > &  u)
inlineconstexprnoexcept

Vector addition operator.

Parameters
[in]uVector to add
Returns
(*this), with X[i] += u[i] for each component.

◆ operator-() [1/2]

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::operator- ( ) const
inlineconstexprnoexcept

Negation operator.

Returns
New vector with each component negated.

◆ operator-() [2/2]

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::operator- ( const Vec3T< T > &  u) const
inlineconstexprnoexcept

Subtraction operator. Returns a new vector with subtracted components.

Returns
New vector with X[i] = this->X[i] - u[i] for each component.
Parameters
[in]uOther vector

◆ operator-=()

template<typename T >
constexpr Vec3T< T > & EBGeometry::Vec3T< T >::operator-= ( const Vec3T< T > &  u)
inlineconstexprnoexcept

Vector subtraction operator.

Parameters
[in]uVector to subtract
Returns
(*this), with X[i] -= u[i] for each component.

◆ operator/() [1/2]

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::operator/ ( const T &  s) const
inlineconstexprnoexcept

Division operator. Returns a vector with scalar divided components.

Parameters
[in]sScalar to divide by
Returns
Returns a new vector with X[i] = this->X[i] / s

◆ operator/() [2/2]

template<typename T >
constexpr Vec3T< T > EBGeometry::Vec3T< T >::operator/ ( const Vec3T< T > &  v) const
inlineconstexprnoexcept

Component-wise division operator.

Parameters
[in]vOther vector
Returns
Returns a new vector with X[i] = this->X[i]/v[i] for each component.

◆ operator/=()

template<typename T >
constexpr Vec3T< T > & EBGeometry::Vec3T< T >::operator/= ( const T &  s)
inlineconstexprnoexcept

In-place scalar division operator.

Parameters
[in]sScalar to divide by
Returns
(*this), with X[i] /= s for each component.

◆ operator=()

template<typename T >
constexpr Vec3T< T > & EBGeometry::Vec3T< T >::operator= ( const Vec3T< T > &  u)
constexprdefaultnoexcept

Assignment operator.

Parameters
[in]uOther vector.
Returns
Reference to *this after assignment.

◆ operator==()

template<typename T >
constexpr bool EBGeometry::Vec3T< T >::operator== ( const Vec3T< T > &  u) const
inlineconstexprnoexcept

Equality comparison.

Parameters
[in]uOther vector.
Returns
True if all three components are equal.

◆ operator[]() [1/2]

template<typename T >
constexpr const T & EBGeometry::Vec3T< T >::operator[] ( size_t  i) const
inlineconstexprnoexcept

Const element access.

Parameters
[in]iComponent index (0 = x, 1 = y, 2 = z). Must be < 3.
Returns
Const reference to the i-th component.

◆ operator[]() [2/2]

template<typename T >
constexpr T & EBGeometry::Vec3T< T >::operator[] ( size_t  i)
inlineconstexprnoexcept

Mutable element access.

Parameters
[in]iComponent index (0 = x, 1 = y, 2 = z). Must be < 3.
Returns
Reference to the i-th component.

◆ unit()

template<typename T >
static constexpr Vec3T< T > EBGeometry::Vec3T< T >::unit ( const size_t  a_dir)
inlinestaticconstexprnoexcept

Return the unit basis vector for the given coordinate axis.

Parameters
[in]a_dirAxis index (0 = x, 1 = y, 2 = z).
Returns
Basis vector e_{a_dir} with a 1 in position a_dir and 0 elsewhere.

◆ zeros()

template<typename T >
static constexpr Vec3T< T > EBGeometry::Vec3T< T >::zeros ( )
inlinestaticconstexprnoexcept

Return a vector with x = y = z = 0.

Returns
Zero vector (0, 0, 0).

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