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::Vec2T< T > Class Template Reference

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

#include <EBGeometry_Vec.hpp>

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

Public Member Functions

 Vec2T () noexcept=default
 Default constructor. Leaves the components uninitialized.
 
constexpr Vec2T (const Vec2T &u) noexcept=default
 Copy constructor.
 
constexpr Vec2T (const T &a_x, const T &a_y) noexcept
 Full constructor.
 
 ~Vec2T ()=default
 Destructor (does nothing)
 
constexpr T & operator[] (size_t i) noexcept
 Mutable element access.
 
constexpr const T & operator[] (size_t i) const noexcept
 Const element access.
 
constexpr Vec2T< T > & operator= (const Vec2T &a_other) noexcept=default
 Assignment operator.
 
constexpr Vec2T< T > operator+ (const Vec2T &a_other) const noexcept
 Addition operator.
 
constexpr Vec2T< T > operator- (const Vec2T &a_other) const noexcept
 Subtraction operator.
 
constexpr Vec2T< T > operator- () const noexcept
 Negation operator.
 
constexpr Vec2T< T > operator* (const T &s) const noexcept
 Scalar multiplication operator.
 
constexpr Vec2T< T > operator/ (const T &s) const noexcept
 Scalar division operator.
 
constexpr Vec2T< T > & operator+= (const Vec2T &a_other) noexcept
 In-place addition operator.
 
constexpr Vec2T< T > & operator-= (const Vec2T &a_other) noexcept
 In-place subtraction operator.
 
constexpr Vec2T< T > & operator*= (const T &s) noexcept
 In-place scalar multiplication operator.
 
constexpr Vec2T< T > & operator/= (const T &s) noexcept
 In-place scalar division operator.
 
constexpr T dot (const Vec2T &a_other) const noexcept
 Dot product.
 
T length () const noexcept
 Compute length of vector.
 
constexpr T length2 () const noexcept
 Compute squared vector length.
 

Static Public Member Functions

static constexpr Vec2T< T > zeros () noexcept
 Return a vector with x = y = 0.
 
static constexpr Vec2T< T > ones () noexcept
 Return a vector with x = y = 1.
 
static constexpr Vec2T< T > min () noexcept
 Return the most-negative representable vector.
 
static constexpr Vec2T< T > max () noexcept
 Return the most-positive representable vector.
 
static constexpr Vec2T< T > infinity () noexcept
 Return a vector with infinite components.
 

Protected Attributes

Array< T, 2 > m_X
 Vector components.
 

Detailed Description

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

Two-dimensional vector class with arithmetic operators.

Like Vec3T, the components are reached through operator[] (index 0 or 1).

Note
Vec2T is used where a computation is reduced to two dimensions: a point projected to the plane of a DCEL polygon face or a triangle, and the cross-sections of some analytic shapes.
Template Parameters
TFloating-point precision (float or double).

Constructor & Destructor Documentation

◆ Vec2T() [1/3]

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

Default constructor. Leaves the components uninitialized.

Defaulted, so that Vec2T 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, Vec2T<T> v; leaves v uninitialized, while value initialization (Vec2T<T> v{};, Vec2T<T>()) zeroes it, as does zeros().

◆ Vec2T() [2/3]

template<typename T >
constexpr EBGeometry::Vec2T< T >::Vec2T ( const Vec2T< T > &  u)
constexprdefaultnoexcept

Copy constructor.

Parameters
[in]uOther vector

Sets *this = u

◆ Vec2T() [3/3]

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

Full constructor.

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

Sets X[0] = a_x and X[1] = a_y.

Member Function Documentation

◆ dot()

template<typename T >
constexpr T EBGeometry::Vec2T< T >::dot ( const Vec2T< T > &  a_other) const
inlineconstexprnoexcept

Dot product.

Parameters
[in]a_otherOther vector.
Returns
Scalar dot product: X[0]*a_other[0] + X[1]*a_other[1].

◆ infinity()

template<typename T >
static constexpr Vec2T< T > EBGeometry::Vec2T< 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::Vec2T< T >::length ( ) const
inlinenoexcept

Compute length of vector.

Not constexpr, since std::sqrt is not.

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

◆ length2()

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

Compute squared vector length.

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

◆ max()

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

Return the most-positive representable vector.

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

◆ min()

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

Return the most-negative representable vector.

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

◆ ones()

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

Return a vector with x = y = 1.

Returns
Ones vector (1, 1).

◆ operator*()

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

Scalar multiplication operator.

Parameters
[in]sScalar.
Returns
New vector with x = s*X[0], y = s*X[1].

◆ operator*=()

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

In-place scalar multiplication operator.

Parameters
[in]sScalar.
Returns
Reference to *this after multiplication.

◆ operator+()

template<typename T >
constexpr Vec2T< T > EBGeometry::Vec2T< T >::operator+ ( const Vec2T< T > &  a_other) const
inlineconstexprnoexcept

Addition operator.

Parameters
[in]a_otherOther vector.
Returns
New vector with x = X[0] + a_other[0], y = X[1] + a_other[1].

◆ operator+=()

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

In-place addition operator.

Parameters
[in]a_otherOther vector to add.
Returns
Reference to *this after addition.

◆ operator-() [1/2]

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

Negation operator.

Returns
New Vec2T<T> with negated components.

◆ operator-() [2/2]

template<typename T >
constexpr Vec2T< T > EBGeometry::Vec2T< T >::operator- ( const Vec2T< T > &  a_other) const
inlineconstexprnoexcept

Subtraction operator.

Parameters
[in]a_otherOther vector.
Returns
New vector with x = X[0] - a_other[0], y = X[1] - a_other[1].

◆ operator-=()

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

In-place subtraction operator.

Parameters
[in]a_otherOther vector to subtract.
Returns
Reference to *this after subtraction.

◆ operator/()

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

Scalar division operator.

Parameters
[in]sScalar divisor.
Returns
New vector with x = X[0]/s, y = X[1]/s.

◆ operator/=()

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

In-place scalar division operator.

Parameters
[in]sScalar divisor.
Returns
Reference to *this after division.

◆ operator=()

template<typename T >
constexpr Vec2T< T > & EBGeometry::Vec2T< T >::operator= ( const Vec2T< T > &  a_other)
constexprdefaultnoexcept

Assignment operator.

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

◆ operator[]() [1/2]

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

Const element access.

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

◆ operator[]() [2/2]

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

Mutable element access.

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

◆ zeros()

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

Return a vector with x = y = 0.

Returns
Zero vector (0, 0).

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