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

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

#include <EBGeometry_Vec.hpp>

Public Member Functions

constexpr Vec2T () noexcept
 Default constructor. Sets the vector to the zero vector.
 
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 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.
 
constexprdot (const Vec2T &a_other) const noexcept
 Dot product.
 
constexprlength () const noexcept
 Compute length of vector.
 
constexprlength2 () const noexcept
 Compute square of vector.
 

Static Public Member Functions

static constexpr Vec2T< T > zeros () noexcept
 Return av 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.
 

Public Attributes

x
 First component in the vector.
 
y
 Second component in the vector.
 

Detailed Description

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

Two-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
Vec2T is a templated class primarily used with DCEL grids.
Template Parameters
TFloating-point precision (float or double).

Constructor & Destructor Documentation

◆ Vec2T() [1/2]

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

Copy constructor.

Parameters
[in]uOther vector

Sets *this = u

◆ Vec2T() [2/2]

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 this->x = a_x and this->y = 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: this->x*a_other.x + this->y*a_other.y.

◆ 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 std::numeric_limits<T>::infinity().

◆ length()

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

Compute length of vector.

Returns
Returns length of vector, i.e. sqrt[(this->x)*(this->x) + (this->y)*(this->y)]

◆ length2()

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

Compute square of vector.

Returns
Returns length of vector, i.e. (this->x)*(this->x) + (this->y)*(this->y)

◆ 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 std::numeric_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 -std::numeric_limits<T>::max().

◆ ones()

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

Return a vector with x = y = 1.

Returns
Unit 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*this->x, y = s*this->y.

◆ 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 = this->x + a_other.x, y = this->y + a_other.y.

◆ 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 = this->x - a_other.x, y = this->y - a_other.y.

◆ 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 = this->x/s, y = this->y/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.

◆ zeros()

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

Return av vector with x = y = 0.

Returns
Zero vector (0, 0).

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