Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::TVector2D< T > Class Template Reference

2-dimensional vector for math operations. More...

#include <TVector2D.h>

Collaboration diagram for sf::TVector2D< T >:

Classes

union  data_type
 Storage union of the 2D coordinate making the x,y accessible as an array. More...
 

Public Types

typedef T value_type
 Type declaration of the coordinate storage values.
 

Public Member Functions

 TVector2D ()=default
 Default constructor.
 
 TVector2D (const TVector2D &v)
 Copy constructor.
 
 TVector2D (TVector2D &&) noexcept
 Move constructor.
 
 TVector2D (T xp, T yp)
 Initializing constructor.
 
TVector2Dassign (T xp, T yp)
 Assignment of new coordinate values.
 
TVector2Dassign (const TVector2D &v)
 Assignment of vector instance.
 
TVector2Doperator= (const TVector2D &v) noexcept
 Assignment operator.
 
TVector2Doperator= (TVector2D &&v) noexcept
 Assignment move operator.
 
TVector2Doperator*= (const TMatrix22< T > &mtx)
 Matrix transform operator.
 
TVector2D operator- () const
 Inversion math operator inverting the vector.
 
TVector2Doperator+= (const TVector2D &)
 Compound addition operator.
 
TVector2Doperator-= (const TVector2D &)
 Compound subtraction operator.
 
TVector2Doperator*= (T c)
 Compound multiplier operator.
 
TVector2Doperator/= (T)
 Compound division operator.
 
TVector2D operator+ (const TVector2D &) const
 Addition operator.
 
TVector2D operator- (const TVector2D &) const
 Subtraction operator.
 
TVector2D operator/ (T) const
 Division operator.
 
bool isEqual (const TVector2D &v, T tol=tolerance) const
 Compares the passed vector within the set tolerance.
 
bool operator== (const TVector2D &) const
 Equality operator.
 
bool operator!= (const TVector2D &) const
 Inequality operator.
 
T & operator[] (size_t)
 Access like an array.
 
const T & operator[] (size_t) const
 Access like a const array.
 
constexpr T * data ()
 Gets a const pointer to the data.
 
constexpr const T * data () const
 Gets a const pointer to the data.
 
constexpr operator T* ()
 Cast operator for pointer.
 
constexpr operator const T * () const
 Cast operator for const pointer.
 
constexpr T x () const
 Gets the x-coordinate value.
 
constexpr T & x ()
 Gets the x-coordinate value as reference.
 
constexpr T y () const
 Gets the y-coordinate value.
 
constexpr T & y ()
 Gets the y-coordinate value as reference.
 
length () const
 Gets the length or magnitude of the vector.
 
lengthSqr () const
 Gets the squared length or magnitude of the vector.
 
TVector2Dnormalize ()
 Normalizes the vector also called a unit-vector, set to length 1.
 
TVector2D normalized () const
 Gets a normalized vector also called a unit-vector, made of length 1.
 
TVector2Dscale (T factor)
 Scales the vector by multiplying all axis with the passed factor.
 
TVector2D scaled (T factor) const
 Scales the vector by multiplying all axis with the passed factor.
 
crossProduct (const TVector2D &) const
 Gets the cross (out) product of 2 vectors.
 
dotProduct (const TVector2D &) const
 Gets the dot (in) product of 2 vectors.
 
operator* (const TVector2D &v) const
 Gets the cross (out) product of 2 vectors.
 
angle (const TVector2D &) const
 Gets the angle between the two vectors.
 
angle () const
 Gets the angle of vector in xy-plane.
 
angleNormalized () const
 Returns a normalized positive angle of function angle().
 
slope () const
 Gets the slope (coefficient) of the line formed with the origin (0, 0). When it is an infinite value +/- std::numeric_limits<T>::infinity() is returned.
 
distance (const TVector2D &) const
 Gets the distance between this and the passed vector. Note that this has to return a double because it uses the sqrt() function.
 
distanceSqr (const TVector2D &) const
 Gets the squared distance between 2 given points. Avoids taking an expensive sqrt call. Useful when comparing different distances.
 
void updateMin (const TVector2D &vertex)
 Copy only those values of x or y which are smaller.
 
void updateMax (const TVector2D &vertex)
 Copy only those values of x or y which are larger.
 
std::string toString () const
 Gets the string representation of the 2D vector formed like '(1.23,4.56)'.
 
TVector2DfromString (const std::string &s) noexcept(false)
 Gets the vector value from the string representation formed like '(1.23,4.56)'. Throws an exception when the string is not in the correct format.
 

Static Public Member Functions

static int areOnSameSide (const TVector2D &lp1, const TVector2D &lp2, const TVector2D &p1, const TVector2D &p2)
 Checks where 2 points lie in relation to a given line given by 2 points.
 

Static Public Attributes

static constexpr auto tolerance = std::numeric_limits<T>::epsilon() * 10.0
 Tolerance for when comparing in the equal operator. Empirical chosen epsilon multiplier to make it work. Used in: sf::isEqual()
 

Protected Attributes

union sf::TVector2D::data_type _data
 

Friends

class TRectangle2D< T >
 

Detailed Description

template<typename T>
class sf::TVector2D< T >

2-dimensional vector for math operations.

Member Typedef Documentation

◆ value_type

template<typename T >
typedef T sf::TVector2D< T >::value_type

Type declaration of the coordinate storage values.

Constructor & Destructor Documentation

◆ TVector2D() [1/4]

template<typename T >
sf::TVector2D< T >::TVector2D ( )
default

Default constructor.

◆ TVector2D() [2/4]

template<typename T >
sf::TVector2D< T >::TVector2D ( const TVector2D< T > &  v)

Copy constructor.

◆ TVector2D() [3/4]

template<typename T >
sf::TVector2D< T >::TVector2D ( TVector2D< T > &&  )
noexcept

Move constructor.

◆ TVector2D() [4/4]

template<typename T >
sf::TVector2D< T >::TVector2D ( xp,
yp 
)

Initializing constructor.

Parameters
xpX-axis value.
ypY-axis value.

Member Function Documentation

◆ angle() [1/2]

template<typename T >
T sf::TVector2D< T >::angle ( ) const

Gets the angle of vector in xy-plane.

Returns
angle of vector in xy-plane.

◆ angle() [2/2]

template<typename T >
T sf::TVector2D< T >::angle ( const TVector2D< T > &  ) const

Gets the angle between the two vectors.

Returns
angle between the two vectors.

◆ angleNormalized()

template<typename T >
T sf::TVector2D< T >::angleNormalized ( ) const

Returns a normalized positive angle of function angle().

Returns
normalized positive angle.

◆ areOnSameSide()

template<typename T >
static int sf::TVector2D< T >::areOnSameSide ( const TVector2D< T > &  lp1,
const TVector2D< T > &  lp2,
const TVector2D< T > &  p1,
const TVector2D< T > &  p2 
)
static

Checks where 2 points lie in relation to a given line given by 2 points.

Parameters
lp1Point 1 which forms the line.
lp2Point 2 which forms the line.
p1Free point 1.
p2Free point 2.
Returns
>0: Same side, <0: Opposite sides, 0 : A point on the line

◆ assign() [1/2]

template<typename T >
TVector2D & sf::TVector2D< T >::assign ( const TVector2D< T > &  v)

Assignment of vector instance.

Parameters
vVector value.
Returns
Itself.

◆ assign() [2/2]

template<typename T >
TVector2D & sf::TVector2D< T >::assign ( xp,
yp 
)

Assignment of new coordinate values.

Parameters
xpX-axis value.
ypY-axis value.
Returns
Itself.

◆ crossProduct()

template<typename T >
T sf::TVector2D< T >::crossProduct ( const TVector2D< T > &  ) const

Gets the cross (out) product of 2 vectors.

Returns
Cross product of 2 vectors.

◆ data() [1/2]

template<typename T >
constexpr T * sf::TVector2D< T >::data ( )
constexpr

Gets a const pointer to the data.

◆ data() [2/2]

template<typename T >
constexpr const T * sf::TVector2D< T >::data ( ) const
constexpr

Gets a const pointer to the data.

◆ distance()

template<typename T >
T sf::TVector2D< T >::distance ( const TVector2D< T > &  ) const

Gets the distance between this and the passed vector. Note that this has to return a double because it uses the sqrt() function.

Returns
distance to another vector.

◆ distanceSqr()

template<typename T >
T sf::TVector2D< T >::distanceSqr ( const TVector2D< T > &  ) const

Gets the squared distance between 2 given points. Avoids taking an expensive sqrt call. Useful when comparing different distances.

Returns
squared distance between 2 given points

◆ dotProduct()

template<typename T >
T sf::TVector2D< T >::dotProduct ( const TVector2D< T > &  ) const

Gets the dot (in) product of 2 vectors.

Returns
Dot (in) product of 2 vectors.

◆ fromString()

template<typename T >
TVector2D & sf::TVector2D< T >::fromString ( const std::string &  s)

Gets the vector value from the string representation formed like '(1.23,4.56)'. Throws an exception when the string is not in the correct format.

Exceptions
std::invalid_argument

◆ isEqual()

template<typename T >
bool sf::TVector2D< T >::isEqual ( const TVector2D< T > &  v,
tol = tolerance 
) const

Compares the passed vector within the set tolerance.

Parameters
vVector to compare with.
tolThe tolerance when comparing which has a default.
Returns
True when equal.

◆ length()

template<typename T >
T sf::TVector2D< T >::length ( ) const

Gets the length or magnitude of the vector.

Note that this has to return a double because it uses the sqrt function.

Returns
Length of the vector.

◆ lengthSqr()

template<typename T >
T sf::TVector2D< T >::lengthSqr ( ) const

Gets the squared length or magnitude of the vector.

Returns
Squared length.

◆ normalize()

template<typename T >
TVector2D & sf::TVector2D< T >::normalize ( )

Normalizes the vector also called a unit-vector, set to length 1.

Returns
This normalized vector.

◆ normalized()

template<typename T >
TVector2D sf::TVector2D< T >::normalized ( ) const

Gets a normalized vector also called a unit-vector, made of length 1.

Returns
A normalized vector.

◆ operator const T *()

template<typename T >
constexpr sf::TVector2D< T >::operator const T * ( ) const
constexpr

Cast operator for const pointer.

◆ operator T*()

template<typename T >
constexpr sf::TVector2D< T >::operator T* ( )
constexpr

Cast operator for pointer.

◆ operator!=()

template<typename T >
bool sf::TVector2D< T >::operator!= ( const TVector2D< T > &  ) const

Inequality operator.

◆ operator*()

template<typename T >
T sf::TVector2D< T >::operator* ( const TVector2D< T > &  v) const

Gets the cross (out) product of 2 vectors.

Returns
Cross product of 2 vectors.

◆ operator*=() [1/2]

template<typename T >
TVector2D & sf::TVector2D< T >::operator*= ( const TMatrix22< T > &  mtx)

Matrix transform operator.

◆ operator*=() [2/2]

template<typename T >
TVector2D & sf::TVector2D< T >::operator*= ( c)

Compound multiplier operator.

◆ operator+()

template<typename T >
TVector2D sf::TVector2D< T >::operator+ ( const TVector2D< T > &  ) const

Addition operator.

◆ operator+=()

template<typename T >
TVector2D & sf::TVector2D< T >::operator+= ( const TVector2D< T > &  )

Compound addition operator.

◆ operator-() [1/2]

template<typename T >
TVector2D sf::TVector2D< T >::operator- ( ) const

Inversion math operator inverting the vector.

◆ operator-() [2/2]

template<typename T >
TVector2D sf::TVector2D< T >::operator- ( const TVector2D< T > &  ) const

Subtraction operator.

◆ operator-=()

template<typename T >
TVector2D & sf::TVector2D< T >::operator-= ( const TVector2D< T > &  )

Compound subtraction operator.

◆ operator/()

template<typename T >
TVector2D sf::TVector2D< T >::operator/ ( ) const

Division operator.

◆ operator/=()

template<typename T >
TVector2D & sf::TVector2D< T >::operator/= ( )

Compound division operator.

◆ operator=() [1/2]

template<typename T >
TVector2D & sf::TVector2D< T >::operator= ( const TVector2D< T > &  v)
noexcept

Assignment operator.

◆ operator=() [2/2]

template<typename T >
TVector2D & sf::TVector2D< T >::operator= ( TVector2D< T > &&  v)
noexcept

Assignment move operator.

◆ operator==()

template<typename T >
bool sf::TVector2D< T >::operator== ( const TVector2D< T > &  ) const

Equality operator.

◆ operator[]() [1/2]

template<typename T >
T & sf::TVector2D< T >::operator[] ( size_t  )

Access like an array.

Exceptions
std::out_of_range

◆ operator[]() [2/2]

template<typename T >
const T & sf::TVector2D< T >::operator[] ( size_t  ) const

Access like a const array.

Exceptions
std::out_of_range

◆ scale()

template<typename T >
TVector2D & sf::TVector2D< T >::scale ( factor)

Scales the vector by multiplying all axis with the passed factor.

Returns
This scaled vector.

◆ scaled()

template<typename T >
TVector2D sf::TVector2D< T >::scaled ( factor) const

Scales the vector by multiplying all axis with the passed factor.

Returns
A scaled vector.

◆ slope()

template<typename T >
T sf::TVector2D< T >::slope ( ) const

Gets the slope (coefficient) of the line formed with the origin (0, 0). When it is an infinite value +/- std::numeric_limits<T>::infinity() is returned.

Returns
slope with the origin.

◆ toString()

template<typename T >
std::string sf::TVector2D< T >::toString ( ) const

Gets the string representation of the 2D vector formed like '(1.23,4.56)'.

◆ updateMax()

template<typename T >
void sf::TVector2D< T >::updateMax ( const TVector2D< T > &  vertex)

Copy only those values of x or y which are larger.

Parameters
vertex

◆ updateMin()

template<typename T >
void sf::TVector2D< T >::updateMin ( const TVector2D< T > &  vertex)

Copy only those values of x or y which are smaller.

Parameters
vertex

◆ x() [1/2]

template<typename T >
constexpr T & sf::TVector2D< T >::x ( )
constexpr

Gets the x-coordinate value as reference.

◆ x() [2/2]

template<typename T >
constexpr T sf::TVector2D< T >::x ( ) const
constexpr

Gets the x-coordinate value.

◆ y() [1/2]

template<typename T >
constexpr T & sf::TVector2D< T >::y ( )
constexpr

Gets the y-coordinate value as reference.

◆ y() [2/2]

template<typename T >
constexpr T sf::TVector2D< T >::y ( ) const
constexpr

Gets the y-coordinate value.

Friends And Related Symbol Documentation

◆ TRectangle2D< T >

template<typename T >
friend class TRectangle2D< T >
friend

Member Data Documentation

◆ _data

template<typename T >
union sf::TVector2D::data_type sf::TVector2D< T >::_data
protected

◆ tolerance

template<typename T >
constexpr auto sf::TVector2D< T >::tolerance = std::numeric_limits<T>::epsilon() * 10.0
staticconstexpr

Tolerance for when comparing in the equal operator. Empirical chosen epsilon multiplier to make it work. Used in: sf::isEqual()


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