Loading...
Searching...
No Matches
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...

#include <Vector2D.H>

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.
Public Types inherited from VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >
typedef VectorSpace< Vector2D< Cmpt >, Cmpt, Ncmpts > vsType
 VectorSpace type.
typedef Cmpt cmptType
 Component type.
typedef Cmpt magType
 Magnitude type.
typedef direction size_type
 The type to represent the size of a VectorSpace.
typedef Cmpt * iterator
 Random access iterator for traversing VectorSpace.
typedef const Cmpt * const_iterator
 Random access iterator for traversing VectorSpace.

Public Member Functions

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

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

Static Public Attributes

static constexpr direction rank = 1
 Rank of Vector2D is 1.
Static Public Attributes inherited from VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >
static constexpr direction dim
 Dimensionality of space.
static constexpr direction nComponents
 Number of components in this vector space.
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.

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

template<class Cmpt>
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

template<class Cmpt>
enum components

Component labeling enumeration.

Enumerator

Definition at line 76 of file Vector2D.H.

Constructor & Destructor Documentation

◆ Vector2D() [1/6]

template<class Cmpt>
Vector2D ( )
default

Default construct.

Referenced by dist(), distSqr(), isClose(), less_xy(), less_yx(), perp(), removeCollinear(), Vector2D(), Vector2D(), and Vector2D().

Here is the caller graph for this function:

◆ Vector2D() [2/6]

template<class Cmpt>
Vector2D ( const Vector2D< Cmpt > & )
default

Copy construct.

◆ Vector2D() [3/6]

template<class Cmpt>
Vector2D ( Foam::zero )
inline

Construct initialized to zero.

Definition at line 25 of file Vector2DI.H.

References Vector2D(), and VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >::zero.

Here is the call graph for this function:

◆ Vector2D() [4/6]

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

Copy construct from VectorSpace of the same rank.

Definition at line 32 of file Vector2DI.H.

References Vector2D(), and VectorSpace< Vector2D< Cmpt >, Cmpt, 2 >::VectorSpace().

Here is the call graph for this function:

◆ Vector2D() [5/6]

template<class Cmpt>
Vector2D ( const Cmpt & vx,
const Cmpt & vy )
inline

Construct from two components.

Definition at line 42 of file Vector2DI.H.

References x, and y.

◆ Vector2D() [6/6]

template<class Cmpt>
Vector2D ( Istream & is)
inlineexplicit

Construct from Istream.

Definition at line 50 of file Vector2DI.H.

References Vector2D().

Here is the call graph for this function:

Member Function Documentation

◆ operator=()

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

Copy assignment.

◆ x() [1/2]

◆ y() [1/2]

◆ x() [2/2]

template<class Cmpt>
Cmpt & x ( )
inlinenoexcept

Access to the vector x component.

Definition at line 137 of file Vector2D.H.

◆ y() [2/2]

template<class Cmpt>
Cmpt & y ( )
inlinenoexcept

Access to the vector y component.

Definition at line 142 of file Vector2D.H.

◆ mag()

template<class Cmpt>
Foam::scalar mag ( ) const
inline

The length (L2-norm) of the vector.

Definition at line 70 of file Vector2DI.H.

References Foam::magSqr().

Here is the call graph for this function:

◆ magSqr()

template<class Cmpt>
Foam::scalar magSqr ( ) const
inline

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

Definition at line 59 of file Vector2DI.H.

References Foam::magSqr(), x, and y.

Here is the call graph for this function:

◆ dist()

template<class Cmpt>
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.

References distSqr(), and Vector2D().

Here is the call graph for this function:

◆ distSqr()

template<class Cmpt>
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.

References Foam::magSqr(), Vector2D(), x(), and y().

Referenced by dist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normalise()

template<class Cmpt>
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.

References Foam::mag(), s(), and Foam::Zero.

Here is the call graph for this function:

◆ removeCollinear()

template<class Cmpt>
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.

References Vector2D().

Here is the call graph for this function:

◆ perp()

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

Perp dot product (dot product with perpendicular vector).

Definition at line 163 of file Vector2DI.H.

References b, Vector2D(), x, and y.

Referenced by triangle2D::area(), triangle2D::lineSegmentIntersectionPoint(), and line< point, const point & >::nearestDist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isClose()

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

Return true if vector is within tol.

Definition at line 170 of file Vector2DI.H.

References b, Foam::mag(), Vector2D(), x, and y().

Here is the call graph for this function:

◆ less_xy()

template<class Cmpt>
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.

References b, Vector2D(), x(), and y().

Here is the call graph for this function:

◆ less_yx()

template<class Cmpt>
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.

References b, Vector2D(), x(), and y().

Here is the call graph for this function:

◆ operator+=()

template<class Cmpt>
template<class Cmpt2>
std::enable_if_t< std::is_convertible_v< Cmpt2, Cmpt >, void > operator+= ( const Vector2D< Cmpt2 > & b)
inline

Add compatible 2D vector to this.

Definition at line 236 of file Vector2D.H.

◆ operator-=()

template<class Cmpt>
template<class Cmpt2>
std::enable_if_t< std::is_convertible_v< Cmpt2, Cmpt >, void > operator-= ( const Vector2D< Cmpt2 > & b)
inline

Subtract compatible 2D vector from this.

Definition at line 247 of file Vector2D.H.

Member Data Documentation

◆ rank

template<class Cmpt>
direction rank = 1
staticconstexpr

Rank of Vector2D is 1.

Definition at line 70 of file Vector2D.H.


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