3es
0.7
|
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... | |
T | 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... | |
T | dot (const Vector4< T > &other) const |
Calculates the dot product of this.other. More... | |
T | 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... | |
T | magnitude () const |
Calculates the magnitude of this vector. More... | |
T | 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). | |
Represents a vector in R4.
|
inline |
Initialises all members to scalar
.
scalar | The value for all members. |
|
inline |
Copy constructor.
other | Vector to copy the value of. |
|
inline |
Copy constructor from a Vector3.
other | Vector to copy the value of. |
w | The w component value. |
|
inline |
Per coordinate initialisation.
x | The x coordinate. |
y | The y coordinate. |
z | The z coordinate. |
|
inline |
Initialisation from a array of at least length 4.
No bounds checking is performed.
array4 | An array of at least length 4. Copies elements (0, 1, 2, 3). |
|
inlineexplicit |
Copy constructor from a different numeric type.
other | Vector to copy the value of. |
|
inlineexplicit |
Copy constructor from a Vector3 of a different numeric type.
other | Vector to copy the value of. |
w | The w component value. |
|
inline |
Adds other
to this vector.
Component-wise addition.
other | The operand. |
References tes::Vector4< T >::x.
Referenced by tes::Vector4< T >::negated(), tes::operator+(), and tes::Vector4< T >::operator+=().
|
inline |
Adds scalar
to all components in this vector.
scalar | The scalar value to add. |
References tes::Vector4< T >::x.
Vector4< T > tes::Vector4< T >::cross3 | ( | const Vector4< T > & | other | ) | const |
Calculates the dot product with other
in R3.
W is set to 1.
References tes::Vector4< T >::v, and tes::Vector4< T >::x.
Referenced by tes::Vector4< T >::scale().
Vector4< T > & tes::Vector4< T >::divide | ( | const T & | scalar | ) |
Divides all components in this vector by scalar
.
scalar | The scalar value to divide by. Performs no operation if scalar is zero. |
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().
T tes::Vector4< T >::dot | ( | const Vector4< T > & | other | ) | const |
Calculates the dot product of this.other.
References tes::Vector4< T >::x.
Referenced by tes::Vector4< T >::magnitudeSquared(), and tes::Vector4< T >::scale().
T tes::Vector4< T >::dot3 | ( | const Vector4< T > & | other | ) | const |
Calculates the dot as if using vectors in R3.
That is, w is ignored.
References tes::Vector4< T >::x.
Referenced by tes::Vector4< T >::scale().
|
inline |
Equality test with error.
Defaults to using Epsilon
.
The vectors are considered equal if the distance between the vectors is less than epsilon
.
other | The vector to compare to. |
epsilon | The error tolerance. |
other
are equal with epsilon
. References tes::Vector4< T >::magnitudeSquared().
Referenced by tes::Vector4< T >::isZero(), and tes::Vector4< T >::operator-().
|
inline |
Zero test with error.
Defaults to using Epsilon
.
The vector is considered zero if the distance to zero less than epsilon
.
epsilon | The error tolerance. |
epsilon
of zero. References tes::Vector4< T >::isEqual(), and tes::Vector4< T >::zero.
Referenced by tes::Vector4< T >::operator-().
T tes::Vector4< T >::magnitude | ( | ) | const |
Calculates the magnitude of this vector.
References tes::Vector4< T >::magnitudeSquared().
Referenced by tes::Vector4< T >::normalise(), tes::Vector4< T >::normalised(), and tes::Vector4< T >::scale().
T tes::Vector4< T >::magnitudeSquared | ( | ) | const |
Calculates the magnitude squared of this vector.
References tes::Vector4< T >::axisw, tes::Vector4< T >::axisx, tes::Vector4< T >::axisy, tes::Vector4< T >::axisz, tes::Vector4< T >::dot(), tes::Vector4< T >::one, and tes::Vector4< T >::zero.
Referenced by tes::Vector4< T >::isEqual(), tes::Vector4< T >::magnitude(), and tes::Vector4< T >::scale().
Vector4< T > & tes::Vector4< T >::multiply | ( | const T & | scalar | ) |
Multiplies all components in this vector by scalar
.
scalar | The scalar value to multiply by. |
References tes::Vector4< T >::x.
Referenced by tes::Vector4< T >::negated(), tes::operator*(), tes::Vector4< T >::operator*=(), and tes::Vector4< T >::scale().
|
inline |
|
inline |
Returns a negated copy of this vector.
This vector is unchanged.
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-().
|
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.
References tes::Vector4< T >::divide(), and tes::Vector4< T >::magnitude().
Referenced by tes::Vector4< T >::negated().
|
inline |
Returns a normalised copy of this vector.
Normalisation fails if the length of this vector is less than or equal to epsilon
.
References tes::Vector4< T >::divide(), tes::Vector4< T >::magnitude(), tes::Vector4< T >::v, and tes::Vector4< T >::zero.
Referenced by tes::Vector4< T >::negated().
|
inline |
Exact inequality operator.
Compares each component with the same operator.
other | The vector to compare to. |
other
. References tes::Vector4< T >::x.
Referenced by tes::Vector4< T >::operator=().
|
inline |
Unarary negation operator.
Equivalent to calling negated()
.
References tes::Vector4< T >::isEqual(), tes::Vector4< T >::isZero(), and tes::Vector4< T >::negated().
|
inline |
Simple assignment operator.
other | Vector to copy the value of. |
References tes::Vector4< T >::x.
|
inline |
Simple assignment operator from a different numeric type.
other | Vector to copy the value of. |
References tes::Vector4< T >::operator!=(), tes::Vector4< T >::operator==(), and tes::Vector4< T >::x.
|
inline |
Exact equality operator.
Compares each component with the same operator.
other | The vector to compare to. |
other
. References tes::Vector4< T >::x.
Referenced by tes::Vector4< T >::operator=().
|
inline |
Index operator.
Not bounds checked.
index | Access coordinates by index; 0 = x, 1 = y, 2 = z, 3 = w. |
References tes::Vector4< T >::v.
|
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.
|
inline |
An alias for multiply(const T &)
.
scalar | The scalar value to multiply by. |
References tes::Vector4< T >::cross3(), tes::Vector4< T >::divide(), tes::Vector4< T >::dot(), tes::Vector4< T >::dot3(), tes::Vector4< T >::magnitude(), tes::Vector4< T >::magnitudeSquared(), and tes::Vector4< T >::multiply().
|
inline |
Subtracts other
from this vector (this - other).
Component-wise subtraction.
other | The operand. |
References tes::Vector4< T >::x.
Referenced by tes::Vector4< T >::negated(), tes::operator-(), and tes::Vector4< T >::operator-=().
|
inline |
Subtracts scalar
from all components in this vector.
scalar | The scalar value to subtract. |
References tes::Vector4< T >::x.
|
inline |
Downcast this vector to a Vector3.
W is lost.
References tes::Vector4< T >::x.
Referenced by tes::planegeom::projectPoint(), and tes::planegeom::signedDistanceToPoint().