Jet  v1.3.3
Public Member Functions | Public Attributes | List of all members
jet::Vector< T, 2 > Class Template Referencefinal

2-D vector class. More...

#include <jet/vector2.h>

Public Member Functions

constexpr Vector ()
 Constructs default vector (0, 0). More...
 
constexpr Vector (T x_, T y_)
 Constructs vector with given parameters x_ and y_. More...
 
template<typename U >
 Vector (const std::initializer_list< U > &lst)
 Constructs vector with initializer list. More...
 
constexpr Vector (const Vector &v)
 Copy constructor. More...
 
void set (T s)
 Set both x and y components to s. More...
 
void set (T x, T y)
 Set x and y components with given parameters. More...
 
template<typename U >
void set (const std::initializer_list< U > &lst)
 Set x and y components with given initializer list. More...
 
void set (const Vector &pt)
 Set x and y with other vector pt. More...
 
void setZero ()
 Set both x and y to zero. More...
 
void normalize ()
 Normalizes this vector. More...
 
Vector add (T v) const
 Computes this + (v, v). More...
 
Vector add (const Vector &v) const
 Computes this + (v.x, v.y). More...
 
Vector sub (T v) const
 Computes this - (v, v). More...
 
Vector sub (const Vector &v) const
 Computes this - (v.x, v.y). More...
 
Vector mul (T v) const
 Computes this * (v, v). More...
 
Vector mul (const Vector &v) const
 Computes this * (v.x, v.y). More...
 
Vector div (T v) const
 Computes this / (v, v). More...
 
Vector div (const Vector &v) const
 Computes this / (v.x, v.y). More...
 
T dot (const Vector &v) const
 Computes dot product. More...
 
T cross (const Vector &v) const
 Comptues cross product. More...
 
Vector rsub (T v) const
 Computes (v, v) - this. More...
 
Vector rsub (const Vector &v) const
 Computes (v.x, v.y) - this. More...
 
Vector rdiv (T v) const
 Computes (v, v) / this. More...
 
Vector rdiv (const Vector &v) const
 Computes (v.x, v.y) / this. More...
 
T rcross (const Vector &v) const
 Computes v cross this. More...
 
void iadd (T v)
 Computes this += (v, v). More...
 
void iadd (const Vector &v)
 Computes this += (v.x, v.y). More...
 
void isub (T v)
 Computes this -= (v, v). More...
 
void isub (const Vector &v)
 Computes this -= (v.x, v.y). More...
 
void imul (T v)
 Computes this *= (v, v). More...
 
void imul (const Vector &v)
 Computes this *= (v.x, v.y). More...
 
void idiv (T v)
 Computes this /= (v, v). More...
 
void idiv (const Vector &v)
 Computes this /= (v.x, v.y). More...
 
const T & at (size_t i) const
 Returns const reference to the i -th element of the vector. More...
 
T & at (size_t i)
 Returns reference to the i -th element of the vector. More...
 
T sum () const
 Returns the sum of all the components (i.e. x + y). More...
 
T avg () const
 Returns the average of all the components. More...
 
T min () const
 Returns the minimum value among x and y. More...
 
T max () const
 Returns the maximum value among x and y. More...
 
T absmin () const
 Returns the absolute minimum value among x and y. More...
 
T absmax () const
 Returns the absolute maximum value among x and y. More...
 
size_t dominantAxis () const
 Returns the index of the dominant axis. More...
 
size_t subminantAxis () const
 Returns the index of the subminant axis. More...
 
Vector normalized () const
 Returns normalized vector. More...
 
T length () const
 Returns the length of the vector. More...
 
T lengthSquared () const
 Returns the squared length of the vector. More...
 
T distanceTo (const Vector &other) const
 Returns the distance to the other vector. More...
 
T distanceSquaredTo (const Vector &other) const
 Returns the squared distance to the other vector. More...
 
Vector reflected (const Vector &normal) const
 Returns the reflection vector to the surface with given surface normal. More...
 
Vector projected (const Vector &normal) const
 Returns the projected vector to the surface with given surface normal. More...
 
Vector tangential () const
 Returns the tangential vector for this vector. More...
 
template<typename U >
Vector< U, 2 > castTo () const
 Returns a vector with different value type. More...
 
bool isEqual (const Vector &other) const
 Returns true if other is the same as this vector. More...
 
bool isSimilar (const Vector &other, T epsilon=std::numeric_limits< T >::epsilon()) const
 Returns true if other is similar to this vector. More...
 
T & operator[] (size_t i)
 Returns reference to the i -th element of the vector. More...
 
const T & operator[] (size_t i) const
 Returns const reference to the i -th element of the vector. More...
 
template<typename U >
Vector & operator= (const std::initializer_list< U > &lst)
 Set x and y components with given initializer list. More...
 
Vector & operator= (const Vector &v)
 Set x and y with other vector pt. More...
 
Vector & operator+= (T v)
 Computes this += (v, v) More...
 
Vector & operator+= (const Vector &v)
 Computes this += (v.x, v.y) More...
 
Vector & operator-= (T v)
 Computes this -= (v, v) More...
 
Vector & operator-= (const Vector &v)
 Computes this -= (v.x, v.y) More...
 
Vector & operator*= (T v)
 Computes this *= (v, v) More...
 
Vector & operator*= (const Vector &v)
 Computes this *= (v.x, v.y) More...
 
Vector & operator/= (T v)
 Computes this /= (v, v) More...
 
Vector & operator/= (const Vector &v)
 Computes this /= (v.x, v.y) More...
 
bool operator== (const Vector &v) const
 Returns true if other is the same as this vector. More...
 
bool operator!= (const Vector &v) const
 Returns true if other is the not same as this vector. More...
 

Public Attributes

T x
 X (or the first) component of the vector. More...
 
T y
 Y (or the second) component of the vector. More...
 

Detailed Description

template<typename T>
class jet::Vector< T, 2 >

2-D vector class.

This class defines simple 2-D vector data.

Template Parameters
T- Type of the element

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<typename T >
constexpr jet::Vector< T, 2 >::Vector ( )
inlineconstexpr

Constructs default vector (0, 0).

◆ Vector() [2/4]

template<typename T >
constexpr jet::Vector< T, 2 >::Vector ( T  x_,
T  y_ 
)
inlineconstexpr

Constructs vector with given parameters x_ and y_.

◆ Vector() [3/4]

template<typename T >
template<typename U >
jet::Vector< T, 2 >::Vector ( const std::initializer_list< U > &  lst)

Constructs vector with initializer list.

◆ Vector() [4/4]

template<typename T >
constexpr jet::Vector< T, 2 >::Vector ( const Vector< T, 2 > &  v)
inlineconstexpr

Copy constructor.

Member Function Documentation

◆ absmax()

template<typename T >
T jet::Vector< T, 2 >::absmax ( ) const

Returns the absolute maximum value among x and y.

◆ absmin()

template<typename T >
T jet::Vector< T, 2 >::absmin ( ) const

Returns the absolute minimum value among x and y.

◆ add() [1/2]

template<typename T >
Vector jet::Vector< T, 2 >::add ( const Vector< T, 2 > &  v) const

Computes this + (v.x, v.y).

◆ add() [2/2]

template<typename T >
Vector jet::Vector< T, 2 >::add ( T  v) const

Computes this + (v, v).

◆ at() [1/2]

template<typename T >
T& jet::Vector< T, 2 >::at ( size_t  i)

Returns reference to the i -th element of the vector.

◆ at() [2/2]

template<typename T >
const T& jet::Vector< T, 2 >::at ( size_t  i) const

Returns const reference to the i -th element of the vector.

◆ avg()

template<typename T >
T jet::Vector< T, 2 >::avg ( ) const

Returns the average of all the components.

◆ castTo()

template<typename T >
template<typename U >
Vector<U, 2> jet::Vector< T, 2 >::castTo ( ) const

Returns a vector with different value type.

◆ cross()

template<typename T >
T jet::Vector< T, 2 >::cross ( const Vector< T, 2 > &  v) const

Comptues cross product.

◆ distanceSquaredTo()

template<typename T >
T jet::Vector< T, 2 >::distanceSquaredTo ( const Vector< T, 2 > &  other) const

Returns the squared distance to the other vector.

◆ distanceTo()

template<typename T >
T jet::Vector< T, 2 >::distanceTo ( const Vector< T, 2 > &  other) const

Returns the distance to the other vector.

◆ div() [1/2]

template<typename T >
Vector jet::Vector< T, 2 >::div ( const Vector< T, 2 > &  v) const

Computes this / (v.x, v.y).

◆ div() [2/2]

template<typename T >
Vector jet::Vector< T, 2 >::div ( T  v) const

Computes this / (v, v).

◆ dominantAxis()

template<typename T >
size_t jet::Vector< T, 2 >::dominantAxis ( ) const

Returns the index of the dominant axis.

◆ dot()

template<typename T >
T jet::Vector< T, 2 >::dot ( const Vector< T, 2 > &  v) const

Computes dot product.

◆ iadd() [1/2]

template<typename T >
void jet::Vector< T, 2 >::iadd ( const Vector< T, 2 > &  v)

Computes this += (v.x, v.y).

◆ iadd() [2/2]

template<typename T >
void jet::Vector< T, 2 >::iadd ( T  v)

Computes this += (v, v).

◆ idiv() [1/2]

template<typename T >
void jet::Vector< T, 2 >::idiv ( const Vector< T, 2 > &  v)

Computes this /= (v.x, v.y).

◆ idiv() [2/2]

template<typename T >
void jet::Vector< T, 2 >::idiv ( T  v)

Computes this /= (v, v).

◆ imul() [1/2]

template<typename T >
void jet::Vector< T, 2 >::imul ( const Vector< T, 2 > &  v)

Computes this *= (v.x, v.y).

◆ imul() [2/2]

template<typename T >
void jet::Vector< T, 2 >::imul ( T  v)

Computes this *= (v, v).

◆ isEqual()

template<typename T >
bool jet::Vector< T, 2 >::isEqual ( const Vector< T, 2 > &  other) const

Returns true if other is the same as this vector.

◆ isSimilar()

template<typename T >
bool jet::Vector< T, 2 >::isSimilar ( const Vector< T, 2 > &  other,
T  epsilon = std::numeric_limits< T >::epsilon() 
) const

Returns true if other is similar to this vector.

◆ isub() [1/2]

template<typename T >
void jet::Vector< T, 2 >::isub ( const Vector< T, 2 > &  v)

Computes this -= (v.x, v.y).

◆ isub() [2/2]

template<typename T >
void jet::Vector< T, 2 >::isub ( T  v)

Computes this -= (v, v).

◆ length()

template<typename T >
T jet::Vector< T, 2 >::length ( ) const

Returns the length of the vector.

◆ lengthSquared()

template<typename T >
T jet::Vector< T, 2 >::lengthSquared ( ) const

Returns the squared length of the vector.

◆ max()

template<typename T >
T jet::Vector< T, 2 >::max ( ) const

Returns the maximum value among x and y.

◆ min()

template<typename T >
T jet::Vector< T, 2 >::min ( ) const

Returns the minimum value among x and y.

◆ mul() [1/2]

template<typename T >
Vector jet::Vector< T, 2 >::mul ( const Vector< T, 2 > &  v) const

Computes this * (v.x, v.y).

◆ mul() [2/2]

template<typename T >
Vector jet::Vector< T, 2 >::mul ( T  v) const

Computes this * (v, v).

◆ normalize()

template<typename T >
void jet::Vector< T, 2 >::normalize ( )

Normalizes this vector.

◆ normalized()

template<typename T >
Vector jet::Vector< T, 2 >::normalized ( ) const

Returns normalized vector.

◆ operator!=()

template<typename T >
bool jet::Vector< T, 2 >::operator!= ( const Vector< T, 2 > &  v) const

Returns true if other is the not same as this vector.

◆ operator*=() [1/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator*= ( const Vector< T, 2 > &  v)

Computes this *= (v.x, v.y)

◆ operator*=() [2/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator*= ( T  v)

Computes this *= (v, v)

◆ operator+=() [1/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator+= ( const Vector< T, 2 > &  v)

Computes this += (v.x, v.y)

◆ operator+=() [2/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator+= ( T  v)

Computes this += (v, v)

◆ operator-=() [1/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator-= ( const Vector< T, 2 > &  v)

Computes this -= (v.x, v.y)

◆ operator-=() [2/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator-= ( T  v)

Computes this -= (v, v)

◆ operator/=() [1/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator/= ( const Vector< T, 2 > &  v)

Computes this /= (v.x, v.y)

◆ operator/=() [2/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator/= ( T  v)

Computes this /= (v, v)

◆ operator=() [1/2]

template<typename T >
template<typename U >
Vector& jet::Vector< T, 2 >::operator= ( const std::initializer_list< U > &  lst)

Set x and y components with given initializer list.

◆ operator=() [2/2]

template<typename T >
Vector& jet::Vector< T, 2 >::operator= ( const Vector< T, 2 > &  v)

Set x and y with other vector pt.

◆ operator==()

template<typename T >
bool jet::Vector< T, 2 >::operator== ( const Vector< T, 2 > &  v) const

Returns true if other is the same as this vector.

◆ operator[]() [1/2]

template<typename T >
T& jet::Vector< T, 2 >::operator[] ( size_t  i)

Returns reference to the i -th element of the vector.

◆ operator[]() [2/2]

template<typename T >
const T& jet::Vector< T, 2 >::operator[] ( size_t  i) const

Returns const reference to the i -th element of the vector.

◆ projected()

template<typename T >
Vector jet::Vector< T, 2 >::projected ( const Vector< T, 2 > &  normal) const

Returns the projected vector to the surface with given surface normal.

◆ rcross()

template<typename T >
T jet::Vector< T, 2 >::rcross ( const Vector< T, 2 > &  v) const

Computes v cross this.

◆ rdiv() [1/2]

template<typename T >
Vector jet::Vector< T, 2 >::rdiv ( const Vector< T, 2 > &  v) const

Computes (v.x, v.y) / this.

◆ rdiv() [2/2]

template<typename T >
Vector jet::Vector< T, 2 >::rdiv ( T  v) const

Computes (v, v) / this.

◆ reflected()

template<typename T >
Vector jet::Vector< T, 2 >::reflected ( const Vector< T, 2 > &  normal) const

Returns the reflection vector to the surface with given surface normal.

◆ rsub() [1/2]

template<typename T >
Vector jet::Vector< T, 2 >::rsub ( const Vector< T, 2 > &  v) const

Computes (v.x, v.y) - this.

◆ rsub() [2/2]

template<typename T >
Vector jet::Vector< T, 2 >::rsub ( T  v) const

Computes (v, v) - this.

◆ set() [1/4]

template<typename T >
template<typename U >
void jet::Vector< T, 2 >::set ( const std::initializer_list< U > &  lst)

Set x and y components with given initializer list.

◆ set() [2/4]

template<typename T >
void jet::Vector< T, 2 >::set ( const Vector< T, 2 > &  pt)

Set x and y with other vector pt.

◆ set() [3/4]

template<typename T >
void jet::Vector< T, 2 >::set ( T  s)

Set both x and y components to s.

◆ set() [4/4]

template<typename T >
void jet::Vector< T, 2 >::set ( T  x,
T  y 
)

Set x and y components with given parameters.

◆ setZero()

template<typename T >
void jet::Vector< T, 2 >::setZero ( )

Set both x and y to zero.

◆ sub() [1/2]

template<typename T >
Vector jet::Vector< T, 2 >::sub ( const Vector< T, 2 > &  v) const

Computes this - (v.x, v.y).

◆ sub() [2/2]

template<typename T >
Vector jet::Vector< T, 2 >::sub ( T  v) const

Computes this - (v, v).

◆ subminantAxis()

template<typename T >
size_t jet::Vector< T, 2 >::subminantAxis ( ) const

Returns the index of the subminant axis.

◆ sum()

template<typename T >
T jet::Vector< T, 2 >::sum ( ) const

Returns the sum of all the components (i.e. x + y).

◆ tangential()

template<typename T >
Vector jet::Vector< T, 2 >::tangential ( ) const

Returns the tangential vector for this vector.

Member Data Documentation

◆ x

template<typename T >
T jet::Vector< T, 2 >::x

X (or the first) component of the vector.

◆ y

template<typename T >
T jet::Vector< T, 2 >::y

Y (or the second) component of the vector.


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