Vector2D< Cmpt > Class Template Reference

Templated 2D Vector derived from VectorSpace adding construction from 2 components, element access using x() and y() member functions and the inner-product (dot-product). More...

Inheritance diagram for Vector2D< Cmpt >:
Collaboration diagram for Vector2D< Cmpt >:

Public Types

enum  components { X, Y }
 Component labeling enumeration. More...
 
typedef Vector2D< label > labelType
 Equivalent type of labels used for valid component indexing. More...
 
- Public Types inherited from VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >
typedef VectorSpace< Vector2D< Cmpt >, Cmpt, Ncmpts > vsType
 VectorSpace type. More...
 
typedef Cmpt cmptType
 Component type. More...
 
typedef Cmpt magType
 Magnitude type. More...
 
typedef Cmpt * iterator
 Random access iterator for traversing VectorSpace. More...
 
typedef const Cmpt * const_iterator
 Random access iterator for traversing VectorSpace. More...
 

Public Member Functions

 Vector2D ()=default
 Default construct. More...
 
 Vector2D (const Vector2D &)=default
 Copy construct. More...
 
Vector2Doperator= (const Vector2D &)=default
 Copy assignment. More...
 
 Vector2D (const Foam::zero)
 Construct initialized to zero. More...
 
 Vector2D (const VectorSpace< Vector2D< Cmpt >, Cmpt, 2 > &vs)
 Copy construct from VectorSpace of the same rank. More...
 
 Vector2D (const Cmpt &vx, const Cmpt &vy)
 Construct from two components. More...
 
 Vector2D (Istream &is)
 Construct from Istream. More...
 
const Cmpt & x () const noexcept
 Access to the vector x component. More...
 
const Cmpt & y () const noexcept
 Access to the vector y component. More...
 
Cmpt & x () noexcept
 Access to the vector x component. More...
 
Cmpt & y () noexcept
 Access to the vector y component. More...
 
scalar mag () const
 The length (L2-norm) of the vector. More...
 
scalar magSqr () const
 The length (L2-norm) squared of the vector. More...
 
scalar dist (const Vector2D< Cmpt > &v2) const
 The L2-norm distance from another vector. The mag() of the difference. More...
 
scalar distSqr (const Vector2D< Cmpt > &v2) const
 The L2-norm distance squared from another vector. The magSqr() of the difference. More...
 
Vector2D< Cmpt > & normalise (const scalar tol=ROOTVSMALL)
 Normalise the vector by its magnitude. More...
 
Vector2D< Cmpt > & removeCollinear (const Vector2D< Cmpt > &unitVec)
 Inplace removal of components that are collinear to the given unit vector. More...
 
scalar perp (const Vector2D< Cmpt > &b) const
 Perp dot product (dot product with perpendicular vector) More...
 
bool isClose (const Vector2D< Cmpt > &b, const scalar tol=1e-10) const
 Return true if vector is within tol. More...
 
- Public Member Functions inherited from VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >
 VectorSpace ()=default
 Default construct. More...
 
 VectorSpace (const Foam::zero)
 Construct initialized to zero. More...
 
 VectorSpace (const VectorSpace< Vector2D< Cmpt >, Cmpt, Ncmpts > &vs)
 Copy construct. More...
 
 VectorSpace (const VectorSpace< Form2, Cmpt2, Ncmpts > &)
 Copy construct of a VectorSpace with the same size. More...
 
 VectorSpace (Istream &is)
 Construct from Istream. More...
 
const Cmpt & component (const direction) const
 
Cmpt & component (const direction)
 
void component (Cmpt &, const direction) const
 
void replace (const direction, const Cmpt &)
 
const Cmpt * cdata () const noexcept
 Return const pointer to the first data element. More...
 
Cmpt * data () noexcept
 Return pointer to the first data element. More...
 
const ConstBlock< SubVector, BStart > block () const
 
const Foam::VectorSpace< Vector2D< Cmpt >, Cmpt, Ncmpts >::template ConstBlock< SubVector, BStart > block () const
 
const Cmpt & operator[] (const direction) const
 
Cmpt & operator[] (const direction)
 
void operator= (const VectorSpace< Vector2D< Cmpt >, Cmpt, Ncmpts > &)
 
void operator= (const Foam::zero)
 
void operator+= (const VectorSpace< Vector2D< Cmpt >, Cmpt, Ncmpts > &)
 
void operator-= (const VectorSpace< Vector2D< Cmpt >, Cmpt, Ncmpts > &)
 
void operator*= (const scalar)
 
void operator/= (const scalar)
 
iterator begin () noexcept
 Return an iterator to begin of VectorSpace. More...
 
const_iterator begin () const noexcept
 Return const_iterator to begin of VectorSpace. More...
 
iterator end () noexcept
 Return an iterator to end of VectorSpace. More...
 
const_iterator end () const noexcept
 Return const_iterator to end of VectorSpace. More...
 
const_iterator cbegin () const noexcept
 Return const_iterator to begin of VectorSpace. More...
 
const_iterator cend () const noexcept
 Return const_iterator to end of VectorSpace. More...
 

Static Public Member Functions

static bool less_xy (const Vector2D< Cmpt > &a, const Vector2D< Cmpt > &b)
 Lexicographically compare a and b with order (x:y) More...
 
static bool less_yx (const Vector2D< Cmpt > &a, const Vector2D< Cmpt > &b)
 Lexicographically compare a and b with order (y:x) More...
 
- Static Public Member Functions inherited from VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >
static constexpr direction size () noexcept
 The number of elements in the VectorSpace = Ncmpts. More...
 
static Vector2D< Cmpt > uniform (const Cmpt &s)
 Return a VectorSpace with all elements = s. More...
 

Static Public Attributes

static constexpr direction rank = 1
 Rank of Vector2D is 1. More...
 
- Static Public Attributes inherited from VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >
static constexpr direction dim
 Dimensionality of space. More...
 
static constexpr direction nComponents
 Number of components in this vector space. More...
 
static constexpr direction mRows
 
static constexpr direction nCols
 
static const char *const typeName
 
static const char *const componentNames []
 
static const Vector2D< Cmpt > zero
 
static const Vector2D< Cmpt > one
 
static const Vector2D< Cmpt > max
 
static const Vector2D< Cmpt > min
 
static const Vector2D< Cmpt > rootMax
 
static const Vector2D< Cmpt > rootMin
 

Additional Inherited Members

- Public Attributes inherited from VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >
Cmpt v_ [Ncmpts]
 The components of this vector space. More...
 

Detailed Description

template<class Cmpt>
class Foam::Vector2D< Cmpt >

Templated 2D Vector derived from VectorSpace adding construction from 2 components, element access using x() and y() member functions and the inner-product (dot-product).

Source files

Definition at line 51 of file Vector2D.H.

Member Typedef Documentation

◆ labelType

typedef Vector2D<label> labelType

Equivalent type of labels used for valid component indexing.

Definition at line 62 of file Vector2D.H.

Member Enumeration Documentation

◆ components

enum components

Component labeling enumeration.

Enumerator

Definition at line 76 of file Vector2D.H.

Constructor & Destructor Documentation

◆ Vector2D() [1/6]

Vector2D ( )
default

Default construct.

◆ Vector2D() [2/6]

Vector2D ( const Vector2D< Cmpt > &  )
default

Copy construct.

◆ Vector2D() [3/6]

Vector2D ( const Foam::zero  )
inline

Construct initialized to zero.

Definition at line 25 of file Vector2DI.H.

◆ Vector2D() [4/6]

Vector2D ( const VectorSpace< Vector2D< Cmpt >, Cmpt, 2 > &  vs)
inline

Copy construct from VectorSpace of the same rank.

Definition at line 33 of file Vector2DI.H.

◆ Vector2D() [5/6]

Vector2D ( const Cmpt &  vx,
const Cmpt &  vy 
)
inline

Construct from two components.

Definition at line 42 of file Vector2DI.H.

◆ Vector2D() [6/6]

Vector2D ( Istream is)
inlineexplicit

Construct from Istream.

Definition at line 50 of file Vector2DI.H.

Member Function Documentation

◆ operator=()

Vector2D& operator= ( const Vector2D< Cmpt > &  )
default

Copy assignment.

◆ x() [1/2]

◆ y() [1/2]

◆ x() [2/2]

Cmpt& x ( )
inlinenoexcept

Access to the vector x component.

Definition at line 137 of file Vector2D.H.

◆ y() [2/2]

Cmpt& y ( )
inlinenoexcept

Access to the vector y component.

Definition at line 142 of file Vector2D.H.

◆ mag()

Foam::scalar mag ( ) const
inline

The length (L2-norm) of the vector.

Definition at line 70 of file Vector2DI.H.

◆ magSqr()

Foam::scalar magSqr ( ) const
inline

The length (L2-norm) squared of the vector.

Definition at line 59 of file Vector2DI.H.

◆ dist()

Foam::scalar dist ( const Vector2D< Cmpt > &  v2) const
inline

The L2-norm distance from another vector. The mag() of the difference.

Definition at line 89 of file Vector2DI.H.

◆ distSqr()

Foam::scalar distSqr ( const Vector2D< Cmpt > &  v2) const
inline

The L2-norm distance squared from another vector. The magSqr() of the difference.

Definition at line 78 of file Vector2DI.H.

◆ normalise()

Foam::Vector2D< Cmpt > & normalise ( const scalar  tol = ROOTVSMALL)
inline

Normalise the vector by its magnitude.

For small magnitudes (less than ROOTVSMALL) set to zero. Will not be particularly useful for a vector of labels

Definition at line 96 of file Vector2DI.H.

◆ removeCollinear()

Foam::Vector2D< Cmpt > & removeCollinear ( const Vector2D< Cmpt > &  unitVec)
inline

Inplace removal of components that are collinear to the given unit vector.

Definition at line 115 of file Vector2DI.H.

◆ perp()

scalar perp ( const Vector2D< Cmpt > &  b) const
inline

Perp dot product (dot product with perpendicular vector)

Definition at line 163 of file Vector2DI.H.

Referenced by triangle2D::area(), triangle2D::lineSegmentIntersectionPoint(), and line< Point, PointRef >::nearestDist().

Here is the caller graph for this function:

◆ isClose()

bool isClose ( const Vector2D< Cmpt > &  b,
const scalar  tol = 1e-10 
) const
inline

Return true if vector is within tol.

Definition at line 171 of file Vector2DI.H.

Referenced by triangle2D::snapClosePoints().

Here is the caller graph for this function:

◆ less_xy()

bool less_xy ( const Vector2D< Cmpt > &  a,
const Vector2D< Cmpt > &  b 
)
inlinestatic

Lexicographically compare a and b with order (x:y)

Definition at line 126 of file Vector2DI.H.

◆ less_yx()

bool less_yx ( const Vector2D< Cmpt > &  a,
const Vector2D< Cmpt > &  b 
)
inlinestatic

Lexicographically compare a and b with order (y:x)

Definition at line 138 of file Vector2DI.H.

Member Data Documentation

◆ rank

constexpr direction rank = 1
static

Rank of Vector2D is 1.

Definition at line 70 of file Vector2D.H.


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