3es  0.7
tes::Vector3< T > Class Template Reference

Represents a vector in R3. More...

#include <3esvector3.h>

Public Member Functions

 Vector3 ()
 Default constructor: undefined initialisation behaviour.
 
 Vector3 (const T &scalar)
 Initialises all members to scalar. More...
 
 Vector3 (const Vector3< T > &other)
 Copy constructor. More...
 
 Vector3 (const T &x, const T &y, const T &z)
 Per coordinate initialisation. More...
 
 Vector3 (const T *array3)
 Initialisation from a array of at least length 3. More...
 
template<typename Q >
 Vector3 (const Vector3< Q > &other)
 Copy constructor from a different numeric type. More...
 
T & operator[] (int index)
 Index operator. More...
 
const T & operator[] (int index) const
 
T & operator[] (unsigned index)
 Index operator. More...
 
const T & operator[] (unsigned index) const
 
Vector3< T > & operator= (const Vector3< T > &other)
 Simple assignment operator. More...
 
template<typename Q >
Vector3< T > & operator= (const Vector3< Q > &other)
 Simple assignment operator from a different numeric type. More...
 
bool operator== (const Vector3< T > &other) const
 Exact equality operator. More...
 
bool operator!= (const Vector3< T > &other) const
 Exact inequality operator. More...
 
Vector3< T > operator- () const
 Unarary negation operator. More...
 
bool isEqual (const Vector3< T > &other, const T &epsilon=Epsilon) const
 Equality test with error. More...
 
bool isZero (const T &epsilon=Epsilon) const
 Zero test with error. More...
 
Vector3< T > & negate ()
 Negates all components of this vector. More...
 
Vector3< T > negated () const
 Returns a negated copy of this vector. More...
 
normalise (const T &epsilon=Epsilon)
 Attempts to normalise this vector. More...
 
Vector3< T > normalised (const T &epsilon=Epsilon) const
 Returns a normalised copy of this vector. More...
 
Vector3< T > & add (const Vector3< T > &other)
 Adds other to this vector. More...
 
Vector3< T > & add (const T &scalar)
 Adds scalar to all components in this vector. More...
 
Vector3< T > & subtract (const Vector3< T > &other)
 Subtracts other from this vector (this - other). More...
 
Vector3< T > & subtract (const T &scalar)
 Subtracts scalar from all components in this vector. More...
 
Vector3< T > & multiply (const T &scalar)
 Multiplies all components in this vector by scalar. More...
 
Vector3< T > & scale (const T &scalar)
 An alias for multiply(const T &). More...
 
Vector3< T > & divide (const T &scalar)
 Divides all components in this vector by scalar. More...
 
dot (const Vector3< T > &other) const
 Calculates the dot product of this.other. More...
 
Vector3< T > cross (const Vector3< T > &other) const
 Calculates the cross product of this x other. More...
 
magnitude () const
 Calculates the magnitude of this vector. More...
 
magnitudeSquared () const
 Calculates the magnitude squared of this vector. More...
 
Vector3< T > & operator+= (const Vector3 &other)
 Arithmetic operator.
 
Vector3< T > & operator+= (const T &scalar)
 Arithmetic operator.
 
Vector3< T > & operator-= (const Vector3 &other)
 Arithmetic operator.
 
Vector3< T > & operator-= (const T &scalar)
 Arithmetic operator.
 
Vector3< T > & operator*= (const T &scalar)
 Arithmetic operator.
 
Vector3< T > & operator/= (const T &scalar)
 Arithmetic operator.
 
Vector3< T > xyz () const
 Return a copy of this vector. Provided for swizzle completeness.
 
Vector3< T > xzy () const
 Return a copy of this vector. Provided for swizzle completeness.
 
Vector3< T > yzx () const
 Swizzle operation.
 
Vector3< T > yxz () const
 Swizzle operation.
 
Vector3< T > zxy () const
 Swizzle operation.
 
Vector3< T > zyx () const
 Swizzle operation.
 

Public Attributes

union {
   struct {
      T   x
 Direct data member access.
 
      T   y
 
      T   z
 
   } 
 
   T   v [3]
 Array representation of the vector members.
 
}; 
 

Static Public Attributes

static const T Epsilon = T(1e-6)
 The default epsilon value used comparison operators.
 
static const Vector3< T > zero
 A vector with all zero values.
 
static const Vector3< T > one
 The vector (1, 1, 1).
 
static const Vector3< T > axisx
 The vector (1, 0, 0).
 
static const Vector3< T > axisy
 The vector (0, 1, 0).
 
static const Vector3< T > axisz
 The vector (0, 0, 1).
 

Detailed Description

template<typename T>
class tes::Vector3< T >

Represents a vector in R3.

Constructor & Destructor Documentation

◆ Vector3() [1/5]

template<typename T>
tes::Vector3< T >::Vector3 ( const T &  scalar)
inline

Initialises all members to scalar.

Parameters
scalarThe value for all members.

◆ Vector3() [2/5]

template<typename T>
tes::Vector3< T >::Vector3 ( const Vector3< T > &  other)
inline

Copy constructor.

Parameters
otherVector to copy the value of.

◆ Vector3() [3/5]

template<typename T>
tes::Vector3< T >::Vector3 ( const T &  x,
const T &  y,
const T &  z 
)
inline

Per coordinate initialisation.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.

◆ Vector3() [4/5]

template<typename T>
tes::Vector3< T >::Vector3 ( const T *  array3)
inline

Initialisation from a array of at least length 3.

No bounds checking is performed.

Parameters
array3An array of at least length 3. Copies elements (0, 1, 2).

◆ Vector3() [5/5]

template<typename T>
template<typename Q >
tes::Vector3< T >::Vector3 ( const Vector3< Q > &  other)
inlineexplicit

Copy constructor from a different numeric type.

Parameters
otherVector to copy the value of.

Member Function Documentation

◆ add() [1/2]

template<typename T>
Vector3< T > & tes::Vector3< T >::add ( const Vector3< T > &  other)
inline

Adds other to this vector.

Component-wise addition.

Parameters
otherThe operand.
Returns
This vector after the operation.

Referenced by tes::Vector3< float >::negated(), tes::operator+(), and tes::Vector3< float >::operator+=().

◆ add() [2/2]

template<typename T>
Vector3< T > & tes::Vector3< T >::add ( const T &  scalar)
inline

Adds scalar to all components in this vector.

Parameters
scalarThe scalar value to add.
Returns
This vector after the operation.

◆ cross()

template<typename T>
Vector3< T > tes::Vector3< T >::cross ( const Vector3< T > &  other) const
inline

Calculates the cross product of this x other.

Returns
The cross product vector.

Referenced by tes::Vector3< float >::scale().

◆ divide()

template<typename T>
Vector3< T > & tes::Vector3< T >::divide ( const T &  scalar)
inline

Divides all components in this vector by scalar.

Parameters
scalarThe scalar value to divide by. Performs no operation if scalar is zero.
Returns
This vector after the operation.

Referenced by tes::Vector3< float >::normalise(), tes::Vector3< float >::normalised(), tes::operator/(), tes::Vector3< float >::operator/=(), and tes::Vector3< float >::scale().

◆ dot()

template<typename T>
T tes::Vector3< T >::dot ( const Vector3< T > &  other) const
inline

◆ isEqual()

template<typename T>
bool tes::Vector3< T >::isEqual ( const Vector3< T > &  other,
const T &  epsilon = Epsilon 
) const
inline

Equality test with error.

Defaults to using Epsilon.

The vectors are considered equal if the distance between the vectors is less than epsilon.

Parameters
otherThe vector to compare to.
epsilonThe error tolerance.
Returns
True this and other are equal with epsilon.

Referenced by tes::Vector3< float >::isZero(), and tes::Vector3< float >::operator-().

◆ isZero()

template<typename T>
bool tes::Vector3< T >::isZero ( const T &  epsilon = Epsilon) const
inline

Zero test with error.

Defaults to using Epsilon.

The vector is considered zero if the distance to zero less than epsilon.

Parameters
epsilonThe error tolerance.
Returns
True this within epsilon of zero.

Referenced by tes::Vector3< float >::operator-().

◆ magnitude()

template<typename T >
T tes::Vector3< T >::magnitude ( ) const
inline

Calculates the magnitude of this vector.

Returns
The magnitude.

Referenced by tes::Vector3< float >::normalise(), tes::Vector3< float >::normalised(), and tes::Vector3< float >::scale().

◆ magnitudeSquared()

template<typename T >
T tes::Vector3< T >::magnitudeSquared ( ) const
inline

Calculates the magnitude squared of this vector.

Returns
The magnitude squared.

Referenced by tes::Vector3< float >::isEqual(), tes::Vector3< float >::magnitude(), and tes::Vector3< float >::scale().

◆ multiply()

template<typename T>
Vector3< T > & tes::Vector3< T >::multiply ( const T &  scalar)
inline

Multiplies all components in this vector by scalar.

Parameters
scalarThe scalar value to multiply by.
Returns
This vector after the operation.

Referenced by tes::Vector3< float >::negated(), tes::operator*(), tes::Vector3< float >::operator*=(), and tes::Vector3< float >::scale().

◆ negate()

template<typename T>
Vector3<T>& tes::Vector3< T >::negate ( )
inline

Negates all components of this vector.

Returns
This.

◆ negated()

template<typename T>
Vector3<T> tes::Vector3< T >::negated ( ) const
inline

Returns a negated copy of this vector.

This vector is unchanged.

Returns
The negated value of this vector.

Referenced by tes::Vector3< float >::operator-().

◆ normalise()

template<typename T>
T tes::Vector3< T >::normalise ( const T &  epsilon = Epsilon)
inline

Attempts to normalise this vector.

Normalisation fails if the length of this vector is less than or equal to epsilon. In this case, the vector remains unchanged.

Returns
The length of this vector before normalisation or zero if normalisation failed.

Referenced by tes::Vector3< float >::negated().

◆ normalised()

template<typename T>
Vector3< T > tes::Vector3< T >::normalised ( const T &  epsilon = Epsilon) const
inline

Returns a normalised copy of this vector.

Normalisation fails if the length of this vector is less than or equal to epsilon.

Returns
A normalised copy of this vector, or a zero vector if if normalisation failed.

Referenced by tes::Vector3< float >::negated().

◆ operator!=()

template<typename T>
bool tes::Vector3< T >::operator!= ( const Vector3< T > &  other) const
inline

Exact inequality operator.

Compares each component with the same operator.

Parameters
otherThe vector to compare to.
Returns
True if this is not exactly equal to other.

Referenced by tes::Vector3< float >::operator=().

◆ operator-()

template<typename T>
Vector3<T> tes::Vector3< T >::operator- ( ) const
inline

Unarary negation operator.

Equivalent to calling negated().

Returns
A negated copy of the vector.

◆ operator=() [1/2]

template<typename T>
Vector3<T>& tes::Vector3< T >::operator= ( const Vector3< T > &  other)
inline

Simple assignment operator.

Parameters
otherVector to copy the value of.
Returns
This.

◆ operator=() [2/2]

template<typename T>
template<typename Q >
Vector3<T>& tes::Vector3< T >::operator= ( const Vector3< Q > &  other)
inline

Simple assignment operator from a different numeric type.

Parameters
otherVector to copy the value of.
Returns
This.

◆ operator==()

template<typename T>
bool tes::Vector3< T >::operator== ( const Vector3< T > &  other) const
inline

Exact equality operator.

Compares each component with the same operator.

Parameters
otherThe vector to compare to.
Returns
True if this is exactly equal to other.

Referenced by tes::Vector3< float >::operator=().

◆ operator[]() [1/4]

template<typename T>
T& tes::Vector3< T >::operator[] ( int  index)
inline

Index operator.

Not bounds checked.

Parameters
indexAccess coordinates by index; 0 = x, 1 = y, 2 = z.
Returns
The coordinate value.

◆ operator[]() [2/4]

template<typename T>
const T& tes::Vector3< T >::operator[] ( int  index) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator[]() [3/4]

template<typename T>
T& tes::Vector3< T >::operator[] ( unsigned  index)
inline

Index operator.

Not bounds checked.

Parameters
indexAccess coordinates by index; 0 = x, 1 = y, 2 = z.
Returns
The coordinate value.

◆ operator[]() [4/4]

template<typename T>
const T& tes::Vector3< T >::operator[] ( unsigned  index) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ scale()

template<typename T>
Vector3<T>& tes::Vector3< T >::scale ( const T &  scalar)
inline

An alias for multiply(const T &).

Parameters
scalarThe scalar value to multiply by.
Returns
This vector after the operation.

◆ subtract() [1/2]

template<typename T>
Vector3< T > & tes::Vector3< T >::subtract ( const Vector3< T > &  other)
inline

Subtracts other from this vector (this - other).

Component-wise subtraction.

Parameters
otherThe operand.
Returns
This vector after the operation.

Referenced by tes::Vector3< float >::negated(), tes::operator-(), and tes::Vector3< float >::operator-=().

◆ subtract() [2/2]

template<typename T>
Vector3< T > & tes::Vector3< T >::subtract ( const T &  scalar)
inline

Subtracts scalar from all components in this vector.

Parameters
scalarThe scalar value to subtract.
Returns
This vector after the operation.

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