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

Represents a vector in R4. More...

#include <3esvector4.h>

Public Member Functions

 Vector4 ()
 Default constructor: undefined initialisation behaviour.
 
 Vector4 (const T &scalar)
 Initialises all members to scalar. More...
 
 Vector4 (const Vector4< T > &other)
 Copy constructor. More...
 
 Vector4 (const Vector3< T > &other, const T &w)
 Copy constructor from a Vector3. More...
 
 Vector4 (const T &x, const T &y, const T &z, const T &w)
 Per coordinate initialisation. More...
 
 Vector4 (const T *array4)
 Initialisation from a array of at least length 4. More...
 
template<typename Q >
 Vector4 (const Vector4< Q > &other)
 Copy constructor from a different numeric type. More...
 
template<typename Q >
 Vector4 (const Vector3< Q > &other, const T &w)
 Copy constructor from a Vector3 of a different numeric type. More...
 
T & operator[] (int index)
 Index operator. More...
 
const T & operator[] (int index) const
 
Vector4< T > & operator= (const Vector4< T > &other)
 Simple assignment operator. More...
 
template<typename Q >
Vector4< T > & operator= (const Vector4< Q > &other)
 Simple assignment operator from a different numeric type. More...
 
bool operator== (const Vector4< T > &other) const
 Exact equality operator. More...
 
bool operator!= (const Vector4< T > &other) const
 Exact inequality operator. More...
 
Vector4< T > operator- () const
 Unarary negation operator. More...
 
bool isEqual (const Vector4< T > &other, const T &epsilon=Epsilon) const
 Equality test with error. More...
 
bool isZero (const T &epsilon=Epsilon) const
 Zero test with error. More...
 
Vector4< T > & negate ()
 Negates all components of this vector. More...
 
Vector4< T > negated () const
 Returns a negated copy of this vector. More...
 
normalise (const T &epsilon=Epsilon)
 Attempts to normalise this vector. More...
 
Vector4< T > normalised (const T &epsilon=Epsilon) const
 Returns a normalised copy of this vector. More...
 
Vector4< T > & add (const Vector4< T > &other)
 Adds other to this vector. More...
 
Vector4< T > & add (const T &scalar)
 Adds scalar to all components in this vector. More...
 
Vector4< T > & subtract (const Vector4< T > &other)
 Subtracts other from this vector (this - other). More...
 
Vector4< T > & subtract (const T &scalar)
 Subtracts scalar from all components in this vector. More...
 
Vector4< T > & multiply (const T &scalar)
 Multiplies all components in this vector by scalar. More...
 
Vector4< T > & scale (const T &scalar)
 An alias for multiply(const T &). More...
 
Vector4< T > & divide (const T &scalar)
 Divides all components in this vector by scalar. More...
 
dot (const Vector4< T > &other) const
 Calculates the dot product of this.other. More...
 
dot3 (const Vector4< T > &other) const
 Calculates the dot as if using vectors in R3. More...
 
Vector4< T > cross3 (const Vector4< T > &other) const
 Calculates the dot product with other in R3. More...
 
magnitude () const
 Calculates the magnitude of this vector. More...
 
magnitudeSquared () const
 Calculates the magnitude squared of this vector. More...
 
Vector4< T > & operator+= (const Vector4 &other)
 Arithmetic operator.
 
Vector4< T > & operator+= (const T &scalar)
 Arithmetic operator.
 
Vector4< T > & operator-= (const Vector4 &other)
 Arithmetic operator.
 
Vector4< T > & operator-= (const T &scalar)
 Arithmetic operator.
 
Vector4< T > & operator*= (const T &scalar)
 Arithmetic operator.
 
Vector4< T > & operator/= (const T &scalar)
 Arithmetic operator.
 
Vector3< T > xyz () const
 Downcast this vector to a Vector3. More...
 

Public Attributes

union {
   struct {
      T   x
 Direct data member access.
 
      T   y
 
      T   z
 
      T   w
 
   } 
 
   T   v [4]
 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 Vector4< T > zero
 A vector with all zero values.
 
static const Vector4< T > one
 The vector (1, 1, 1, 1).
 
static const Vector4< T > axisx
 The vector (1, 0, 0, 0).
 
static const Vector4< T > axisy
 The vector (0, 1, 0, 0).
 
static const Vector4< T > axisz
 The vector (0, 0, 1, 0).
 
static const Vector4< T > axisw
 The vector (0, 0, 0, 1).
 

Detailed Description

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

Represents a vector in R4.

Constructor & Destructor Documentation

◆ Vector4() [1/7]

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

Initialises all members to scalar.

Parameters
scalarThe value for all members.

◆ Vector4() [2/7]

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

Copy constructor.

Parameters
otherVector to copy the value of.

◆ Vector4() [3/7]

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

Copy constructor from a Vector3.

Parameters
otherVector to copy the value of.
wThe w component value.

◆ Vector4() [4/7]

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

Per coordinate initialisation.

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

◆ Vector4() [5/7]

template<typename T>
tes::Vector4< T >::Vector4 ( const T *  array4)
inline

Initialisation from a array of at least length 4.

No bounds checking is performed.

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

◆ Vector4() [6/7]

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

Copy constructor from a different numeric type.

Parameters
otherVector to copy the value of.

◆ Vector4() [7/7]

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

Copy constructor from a Vector3 of a different numeric type.

Parameters
otherVector to copy the value of.
wThe w component value.

Member Function Documentation

◆ add() [1/2]

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

Adds other to this vector.

Component-wise addition.

Parameters
otherThe operand.
Returns
This vector after the operation.

References tes::Vector4< T >::x.

Referenced by tes::Vector4< T >::negated(), tes::operator+(), and tes::Vector4< T >::operator+=().

◆ add() [2/2]

template<typename T >
Vector4< T > & tes::Vector4< 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.

References tes::Vector4< T >::x.

◆ cross3()

template<typename T >
Vector4< T > tes::Vector4< T >::cross3 ( const Vector4< T > &  other) const

Calculates the dot product with other in R3.

W is set to 1.

Returns
The cross product in R3.

References tes::Vector4< T >::v, and tes::Vector4< T >::x.

Referenced by tes::Vector4< T >::scale().

◆ divide()

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

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.

References tes::Vector4< T >::x.

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

◆ dot()

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

Calculates the dot product of this.other.

Returns
The dot product.

References tes::Vector4< T >::x.

Referenced by tes::Vector4< T >::magnitudeSquared(), and tes::Vector4< T >::scale().

◆ dot3()

template<typename T >
T tes::Vector4< T >::dot3 ( const Vector4< T > &  other) const

Calculates the dot as if using vectors in R3.

That is, w is ignored.

Returns
The dot product.

References tes::Vector4< T >::x.

Referenced by tes::Vector4< T >::scale().

◆ isEqual()

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

References tes::Vector4< T >::magnitudeSquared().

Referenced by tes::Vector4< T >::isZero(), and tes::Vector4< T >::operator-().

◆ isZero()

template<typename T >
bool tes::Vector4< 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.

References tes::Vector4< T >::isEqual(), and tes::Vector4< T >::zero.

Referenced by tes::Vector4< T >::operator-().

◆ magnitude()

template<typename T >
T tes::Vector4< T >::magnitude ( ) const

Calculates the magnitude of this vector.

Returns
The magnitude.

References tes::Vector4< T >::magnitudeSquared().

Referenced by tes::Vector4< T >::normalise(), tes::Vector4< T >::normalised(), and tes::Vector4< T >::scale().

◆ magnitudeSquared()

template<typename T >
T tes::Vector4< T >::magnitudeSquared ( ) const

◆ multiply()

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

Multiplies all components in this vector by scalar.

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

References tes::Vector4< T >::x.

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

◆ negate()

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

Negates all components of this vector.

Returns
This.

References tes::Vector4< T >::x.

◆ negated()

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

Returns a negated copy of this vector.

This vector is unchanged.

Returns
The negated value of this vector.

References tes::Vector4< T >::add(), tes::Vector4< T >::multiply(), tes::Vector4< T >::normalise(), tes::Vector4< T >::normalised(), tes::Vector4< T >::subtract(), and tes::Vector4< T >::x.

Referenced by tes::Vector4< T >::operator-().

◆ normalise()

template<typename T >
T tes::Vector4< 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.

References tes::Vector4< T >::divide(), and tes::Vector4< T >::magnitude().

Referenced by tes::Vector4< T >::negated().

◆ normalised()

template<typename T >
Vector4< T > tes::Vector4< 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.

References tes::Vector4< T >::divide(), tes::Vector4< T >::magnitude(), tes::Vector4< T >::v, and tes::Vector4< T >::zero.

Referenced by tes::Vector4< T >::negated().

◆ operator!=()

template<typename T >
bool tes::Vector4< T >::operator!= ( const Vector4< 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.

References tes::Vector4< T >::x.

Referenced by tes::Vector4< T >::operator=().

◆ operator-()

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

Unarary negation operator.

Equivalent to calling negated().

Returns
A negated copy of the vector.

References tes::Vector4< T >::isEqual(), tes::Vector4< T >::isZero(), and tes::Vector4< T >::negated().

◆ operator=() [1/2]

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

Simple assignment operator.

Parameters
otherVector to copy the value of.
Returns
This.

References tes::Vector4< T >::x.

◆ operator=() [2/2]

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

Simple assignment operator from a different numeric type.

Parameters
otherVector to copy the value of.
Returns
This.

References tes::Vector4< T >::operator!=(), tes::Vector4< T >::operator==(), and tes::Vector4< T >::x.

◆ operator==()

template<typename T >
bool tes::Vector4< T >::operator== ( const Vector4< 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.

References tes::Vector4< T >::x.

Referenced by tes::Vector4< T >::operator=().

◆ operator[]() [1/2]

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

Index operator.

Not bounds checked.

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

References tes::Vector4< T >::v.

◆ operator[]() [2/2]

template<typename T>
const T& tes::Vector4< 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.

References tes::Vector4< T >::v.

◆ scale()

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

◆ subtract() [1/2]

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

Subtracts other from this vector (this - other).

Component-wise subtraction.

Parameters
otherThe operand.
Returns
This vector after the operation.

References tes::Vector4< T >::x.

Referenced by tes::Vector4< T >::negated(), tes::operator-(), and tes::Vector4< T >::operator-=().

◆ subtract() [2/2]

template<typename T >
Vector4< T > & tes::Vector4< 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.

References tes::Vector4< T >::x.

◆ xyz()

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

Downcast this vector to a Vector3.

W is lost.

Returns
The x, y, z components.

References tes::Vector4< T >::x.

Referenced by tes::planegeom::projectPoint(), and tes::planegeom::signedDistanceToPoint().


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