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

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

#include <TVector3D.h>

Collaboration diagram for sf::TVector3D< T >:

Classes

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

Public Types

typedef T value_type
 Type declaration of the coordinate storage values.
 

Public Member Functions

 TVector3D ()=default
 Default constructor.
 
 TVector3D (const TVector3D &v)
 Copy constructor.
 
 TVector3D (TVector3D &&) noexcept
 Move constructor.
 
 TVector3D (T xp, T yp, T zp)
 Initializing constructor.
 
TVector3Dassign (T xp, T yp, T zp)
 Assignment of new coordinate values.
 
TVector3Dassign (const TVector3D &v)
 Assignment of vector instance.
 
TVector3Doperator= (TVector3D &v) noexcept
 Assignment operator.
 
TVector3Doperator= (TVector3D &&v) noexcept
 Assignment move operator.
 
TVector3Doperator*= (const TMatrix44< T > &mtx)
 Matrix transform assignment operator.
 
TVector3D operator* (const TMatrix44< T > &mtx)
 Matrix transform operator.
 
TVector3D operator- () const
 Inversion math operator inverting the vector.
 
TVector3Doperator+= (const TVector3D &)
 Compound addition operator.
 
TVector3Doperator-= (const TVector3D &)
 Compound subtraction operator.
 
TVector3Doperator*= (T c)
 Compound multiplier operator.
 
TVector3Doperator/= (T)
 Compound division operator.
 
TVector3D operator+ (const TVector3D &) const
 Addition operator.
 
TVector3D operator- (const TVector3D &) const
 Subtraction operator.
 
TVector3D operator/ (T c) const
 Division operator.
 
bool isEqual (const TVector3D &v, T tol=tolerance) const
 Compares the passed vector within the set tolerance.
 
bool operator== (const TVector3D &) const
 Equality operator.
 
bool operator!= (const TVector3D &) 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.
 
constexpr T z () const
 Gets the z-coordinate value.
 
constexpr T & z ()
 Gets the z-coordinate value as reference.
 
length () const
 Gets the length or magnitude of the vector.
 
length2D () const
 Gets the length or magnitude of the vector for only X and Y axis.
 
lengthSqr () const
 Gets the squared length or magnitude of the vector.
 
lengthSqr2D () const
 Gets the squared length or magnitude of the vector for only the X and Y axis.
 
TVector3Dnormalize ()
 Normalizes the vector also called a unit-vector, set to length 1.
 
TVector3D normalized () const
 Gets a normalized vector also called a unit-vector, made of length 1.
 
TVector3Dscale (T factor)
 Scales the vector by multiplying all axis with the passed factor.
 
TVector3D scaled (T factor) const
 Scales the vector by multiplying all axis with the passed factor.
 
TVector3D crossProduct (const TVector3D &) const
 Gets the cross (out) product of 2 vectors.
 
dotProduct (const TVector3D &) const
 Gets the dot (in) product of 2 vectors.
 
dotProduct2D (const TVector3D &) const
 Gets the dot (in) product of 2 vectors for only the X and Y axis.
 
TVector3D operator* (const TVector3D &v) const
 Gets the cross (out) product of 2 vectors.
 
angle (const TVector3D &) const
 Gets the angle between the two vectors.
 
angleNormalized () const
 Returns a normalized positive angle of function angle().
 
distance (const TVector3D &) const
 Gets the distance between this and the passed vector. Note that this has to return a double because it uses the sqrt() function.
 
distance2D (const TVector3D &) const
 Gets the distance between this and the passed vector for only the X and Y axis. Note that this has to return a double because it uses the sqrt() function.
 
distanceSqr (const TVector3D &) const
 Gets the squared distance between 2 given points. Avoids taking an expensive sqrt call. Useful when comparing different distances.
 
distanceSqr2D (const TVector3D &) const
 Gets the squared distance between 2 given points in 2D only (z is ignored). Avoids taking an expensive sqrt call. Useful when comparing different distances.
 
void updateMin (const TVector3D &vertex)
 Copy only those values of x,y or z which are smaller.
 
void updateMax (const TVector3D &vertex)
 Copy only those values of x,y or z which are larger.
 
std::string toString () const
 Gets the string representation of the 2D vector formed like '(1.23,4.56)'.
 
TVector3DfromString (const std::string &s) noexcept(false)
 Gets the vector value from the string representation formed like '(1.23,4.56,7.89)'. Throws an exception when the string is not in the correct format.
 
int dominantAxis ()
 Gets the dominant axis where x=0, y=1 and z=2.
 
void copyTo (T fa[3]) const
 Copies the X, Y and Z values to an array of type 'T' or type 'TVector3D<T>::value_type'.
 
template<typename F = T, size_t N = 3>
std::array< F, N > array (F value=1) const
 Gets a std::array of type F of the X, Y and Z axis. Allows the size of the array to be specified so it can be used in a OpenGL function call.
 
template<typename F = float, size_t N = 4>
const F * floatPtr (F value=1) const
 Gets an array pointer of floating point type F of the X, Y and Z axis. Used to pass to OpenGL where a specific floating point value is required. This function is thread safe by returning a thread local static variable.
 

Static Public Attributes

static constexpr auto tolerance = std::numeric_limits<T>::epsilon() * T(15.0)
 Tolerance for when comparing in the equal operator. Empirical chosen epsilon multiplier to make it work after calculations. Used as: std::fabs(x1 - x2) < tolerance.
 

Protected Attributes

union sf::TVector3D::data_type _data
 

Detailed Description

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

3-dimensional vector for math operations.

Member Typedef Documentation

◆ value_type

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

Type declaration of the coordinate storage values.

Constructor & Destructor Documentation

◆ TVector3D() [1/4]

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

Default constructor.

◆ TVector3D() [2/4]

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

Copy constructor.

◆ TVector3D() [3/4]

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

Move constructor.

◆ TVector3D() [4/4]

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

Initializing constructor.

Parameters
xpX-axis value.
ypY-axis value.
zpZ-axis value.

Member Function Documentation

◆ angle()

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

Gets the angle between the two vectors.

Returns
angle between the two vectors.

◆ angleNormalized()

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

Returns a normalized positive angle of function angle().

Returns
normalized positive angle.

◆ array()

template<typename T >
template<typename F = T, size_t N = 3>
std::array< F, N > sf::TVector3D< T >::array ( value = 1) const

Gets a std::array of type F of the X, Y and Z axis. Allows the size of the array to be specified so it can be used in a OpenGL function call.

Template Parameters
FType of the float array being returned.
NSize of the array being returned.
Parameters
valueValue of the array entries beyond the 3rd entry.
Returns
A std::array of this instance array.

◆ assign() [1/2]

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

Assignment of vector instance.

Parameters
vVector value.
Returns
Itself.

◆ assign() [2/2]

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

Assignment of new coordinate values.

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

◆ copyTo()

template<typename T >
void sf::TVector3D< T >::copyTo ( fa[3]) const

Copies the X, Y and Z values to an array of type 'T' or type 'TVector3D<T>::value_type'.

◆ crossProduct()

template<typename T >
TVector3D sf::TVector3D< T >::crossProduct ( const TVector3D< 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::TVector3D< T >::data ( )
constexpr

Gets a const pointer to the data.

◆ data() [2/2]

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

Gets a const pointer to the data.

◆ distance()

template<typename T >
T sf::TVector3D< T >::distance ( const TVector3D< 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.

◆ distance2D()

template<typename T >
T sf::TVector3D< T >::distance2D ( const TVector3D< T > &  ) const

Gets the distance between this and the passed vector for only the X and Y axis. 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::TVector3D< T >::distanceSqr ( const TVector3D< 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

◆ distanceSqr2D()

template<typename T >
T sf::TVector3D< T >::distanceSqr2D ( const TVector3D< T > &  ) const

Gets the squared distance between 2 given points in 2D only (z is ignored). Avoids taking an expensive sqrt call. Useful when comparing different distances.

Returns
squared distance between 2 given points

◆ dominantAxis()

template<typename T >
int sf::TVector3D< T >::dominantAxis ( )

Gets the dominant axis where x=0, y=1 and z=2.

Returns
Integer value representing the dominant axis.

◆ dotProduct()

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

Gets the dot (in) product of 2 vectors.

Returns
Dot (in) product of 2 vectors.

◆ dotProduct2D()

template<typename T >
T sf::TVector3D< T >::dotProduct2D ( const TVector3D< T > &  ) const

Gets the dot (in) product of 2 vectors for only the X and Y axis.

Returns
Dot (in) product of 2 vectors.

◆ floatPtr()

template<typename T >
template<typename F = float, size_t N = 4>
const F * sf::TVector3D< T >::floatPtr ( value = 1) const

Gets an array pointer of floating point type F of the X, Y and Z axis. Used to pass to OpenGL where a specific floating point value is required. This function is thread safe by returning a thread local static variable.

Template Parameters
FType of the float pointer being returned.
NDepth of the array being returned.
Parameters
valueValue of the array entries beyond the 3rd entry.
Returns
A pointer of the floating point values converted to a float type.

◆ fromString()

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

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

Exceptions
std::invalid_argument

◆ isEqual()

template<typename T >
bool sf::TVector3D< T >::isEqual ( const TVector3D< 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::TVector3D< 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.

◆ length2D()

template<typename T >
T sf::TVector3D< T >::length2D ( ) const

Gets the length or magnitude of the vector for only X and Y axis.

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::TVector3D< T >::lengthSqr ( ) const

Gets the squared length or magnitude of the vector.

Returns
Squared length.

◆ lengthSqr2D()

template<typename T >
T sf::TVector3D< T >::lengthSqr2D ( ) const

Gets the squared length or magnitude of the vector for only the X and Y axis.

Returns
Squared length.

◆ normalize()

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

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

Returns
normalized vector.

◆ normalized()

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

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

Returns
normalized vector.

◆ operator const T *()

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

Cast operator for const pointer.

◆ operator T*()

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

Cast operator for pointer.

◆ operator!=()

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

Inequality operator.

◆ operator*() [1/2]

template<typename T >
TVector3D sf::TVector3D< T >::operator* ( const TMatrix44< T > &  mtx)

Matrix transform operator.

◆ operator*() [2/2]

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

Gets the cross (out) product of 2 vectors.

Returns
Cross product of 2 vectors.

◆ operator*=() [1/2]

template<typename T >
TVector3D & sf::TVector3D< T >::operator*= ( const TMatrix44< T > &  mtx)

Matrix transform assignment operator.

◆ operator*=() [2/2]

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

Compound multiplier operator.

◆ operator+()

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

Addition operator.

◆ operator+=()

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

Compound addition operator.

◆ operator-() [1/2]

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

Inversion math operator inverting the vector.

◆ operator-() [2/2]

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

Subtraction operator.

◆ operator-=()

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

Compound subtraction operator.

◆ operator/()

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

Division operator.

◆ operator/=()

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

Compound division operator.

◆ operator=() [1/2]

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

Assignment move operator.

◆ operator=() [2/2]

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

Assignment operator.

◆ operator==()

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

Equality operator.

◆ operator[]() [1/2]

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

Access like an array.

Exceptions
std::out_of_range

◆ operator[]() [2/2]

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

Access like a const array.

Exceptions
std::out_of_range

◆ scale()

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

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

Returns
This scaled vector.

◆ scaled()

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

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

Returns
A scaled vector.

◆ toString()

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

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

◆ updateMax()

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

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

Parameters
vertex

◆ updateMin()

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

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

Parameters
vertex

◆ x() [1/2]

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

Gets the x-coordinate value as reference.

◆ x() [2/2]

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

Gets the x-coordinate value.

◆ y() [1/2]

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

Gets the y-coordinate value as reference.

◆ y() [2/2]

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

Gets the y-coordinate value.

◆ z() [1/2]

template<typename T >
constexpr T & sf::TVector3D< T >::z ( )
constexpr

Gets the z-coordinate value as reference.

◆ z() [2/2]

template<typename T >
constexpr T sf::TVector3D< T >::z ( ) const
constexpr

Gets the z-coordinate value.

Member Data Documentation

◆ _data

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

◆ tolerance

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

Tolerance for when comparing in the equal operator. Empirical chosen epsilon multiplier to make it work after calculations. Used as: std::fabs(x1 - x2) < tolerance.


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