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 | Friends | 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

constexpr Vec3T () noexcept
 Default constructor. Sets the vector to the zero vector.
 
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 bool operator< (const Vec3T< T > &u) const noexcept
 "Smaller than" operator.
 
constexpr bool operator> (const Vec3T< T > &u) const noexcept
 "Greater than" operator.
 
constexpr bool operator<= (const Vec3T< T > &u) const noexcept
 "Smaller or equal to" operator.
 
constexpr bool operator>= (const Vec3T< T > &u) const noexcept
 "Greater or equal to" operator.
 
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
 Vector division operator.
 
constexpr Vec3T< T > cross (const Vec3T< T > &u) const noexcept
 Vector cross product.
 
constexprdot (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)
 
constexprlength () const noexcept
 Compute vector length.
 
constexprlength2 () const noexcept
 Compute squared vector length.
 

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

std::array< T, 3 > m_X
 Vector components.
 

Friends

std::ostream & operator<< (std::ostream &os, const Vec3T< T > &vec)
 Stream insertion operator.
 

Detailed Description

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

Three-dimensional vector class with arithmetic operators.

The class has a public-only interface. To change it's components one can call the member functions, or set components directly, e.g. vec.x = 5.0

Note
Vec3T is a templated class primarily used with DCEL grids. It is always 3D, i.e. independent of Chombo configuration settings. This lets one use DCEL functionality even though the simulation might only be 2D.
Template Parameters
TFloating-point precision (float or double).

Constructor & Destructor Documentation

◆ Vec3T() [1/2]

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

Copy constructor.

Parameters
[in]a_uOther vector

Sets *this = u

◆ Vec3T() [2/2]

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 this->x = a_x, this->y = a_y, and this->z = 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 std::numeric_limits<T>::infinity().

◆ length()

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

Compute vector length.

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 std::numeric_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 -std::numeric_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
Returns (*this) with multiplied components, e.g. this->X[0] = this->X[0] * s

◆ 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
Returns (*this) with incremented components, e.g. this->X[0] = this->X[0] + u.X[0]

◆ 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
Returns a new vector with x = this->x - u.x and so on.
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 subtraction
Returns
Returns (*this) with subtracted components, e.g. this->X[0] = this->X[0] - u.X[0]

◆ 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 divided 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

Vector division operator.

Parameters
[in]sScalar to divide by
Returns
Returns (*this) with multiplied components, e.g. this->X[0] = this->X[0] / s

◆ operator<()

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

"Smaller than" operator.

Returns true if this->x < u.x AND this->y < u.y AND this->z < u.z and false otherwise

Parameters
[in]uOther vector
Returns
True if all three components of *this are strictly less than the corresponding components of u, false otherwise.

◆ operator<=()

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

"Smaller or equal to" operator.

Returns true if this->x <= u.x AND this->y <= u.y AND this->z <= u.z

Parameters
[in]uOther vector
Returns
True if all three components of *this are less than or equal to the corresponding components of u, false otherwise.

◆ 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>()

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

"Greater than" operator.

Returns true if this->x > u.x AND this->y > u.y AND this->z > u.z

Parameters
[in]uOther vector
Returns
True if all three components of *this are strictly greater than the corresponding components of u, false otherwise.

◆ operator>=()

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

"Greater or equal to" operator.

Returns true if this->x >= u.x AND this->y >= u.y AND this->z >= u.z

Parameters
[in]uOther vector
Returns
True if all three components of *this are greater than or equal to the corresponding components of u, false otherwise.

◆ 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).

Friends And Related Symbol Documentation

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream &  os,
const Vec3T< T > &  vec 
)
friend

Stream insertion operator.

Parameters
[in,out]osOutput stream.
[in]vecVector to print.
Returns
Reference to the output stream after insertion.

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