Main Page | Modules | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

Four-dimensional vector.
[Primitive datatypes]


Classes

class  TVector4< T >
 Generic Four-Dimensional Vector. More...

Global binary operators for three-dimensional vectors.

template<typename T>
TVector4< T > operator+ (const TVector4< T > &a, const TVector4< T > &b) throw ()
 Addition operator for two vectors.
template<typename T>
TVector4< T > operator- (const TVector4< T > &a, const TVector4< T > &b) throw ()
 Subtraction operator for two vectors.
template<typename T>
std::istream & operator>> (std::istream &s, TVector4< T > &vector) throw ()
 Input operator Reads four values of type T from an input stream and assigns them to the components x, y, z and h of the vector.
template<typename T>
std::ostream & operator<< (std::ostream &s, const TVector4< T > &vector) throw ()
 Output Operator.

Constructors and Destructors

 TVector4::TVector4 () throw ()
 Default constructor.
 TVector4::TVector4 (const T *ptr) throw (Exception::NullPointer)
 Array constructor.
 TVector4::TVector4 (const T &value) throw ()
 Scalar constructor.
 TVector4::TVector4 (const T &x, const T &y, const T &z, const T &h=(T) 1) throw ()
 Detailed constructor.
 TVector4::TVector4 (const TVector4 &vector) throw ()
 Copy constructor.
virtual TVector4::~TVector4 () throw ()
 Destructor.
virtual void TVector4::clear () throw ()
 Clear method The values are set to 0.

Assignment

void TVector4::set (const T *ptr) throw (Exception::NullPointer)
 Assign from an array.
void TVector4::set (const T &rx, const T &ry, const T &rz, const T &rh=(T) 1) throw ()
 Assign the vector components.
void TVector4::set (const TVector4 &vector) throw ()
 Assign from another TVector4.
TVector4 & TVector4::operator= (const T *ptr) throw (Exception::NullPointer)
 Array assignment operator.
TVector4 & TVector4::operator= (const TVector4 &vector) throw ()
 Assignment operator.
TVector4 & TVector4::operator= (T value) throw ()
 Assignment operator.
void TVector4::get (T *ptr) const throw (Exception::NullPointer)
 Assign to an array.
void TVector4::get (T &rx, T &ry, T &rz, T &rh) const throw ()
 Assign to four variables of type T.
void TVector4::get (TVector4 &vector) const throw ()
 Assign to another Vector4.
void TVector4::swap (TVector4 &vector) throw ()
 Swap the contents of two vectors.

Accessors

TVector4::getLength () const throw ()
 Return the length of the vector.
TVector4::getSquareLength () const throw ()
 Return the squared length of the vector.
TVector4 & TVector4::normalize () throw (Exception::DivisionByZero)
 Normalize the vector.
const TVector4 & TVector4::getZero () throw ()
 Return a vector with all components 0.
const TVector4 & TVector4::getUnit () throw ()
 Return a vector with all components 1.
void TVector4::set (const T &value=(T) 1) throw ()
 Assign one value to all vector components.
T & TVector4::operator[] (Position position) throw (Exception::IndexOverflow)
 Mutable array-like access to the components.
const T & TVector4::operator[] (Position position) const throw (Exception::IndexOverflow)
 Constant array-like access to the components.

Arithmetic operators

TVector4 TVector4::operator+ () const throw ()
 Positive sign.
TVector4 TVector4::operator- () const throw ()
 Negative sign.
TVector4 & TVector4::operator+= (const TVector4 &vector) throw ()
 Add a vector to this vector.
TVector4 & TVector4::operator-= (const TVector4 &vector) throw ()
 Subtract a vector from this vector.
TVector4 TVector4::operator * (const T &scalar) throw ()
 Scalar product.
TVector4 & TVector4::operator *= (const T &scalar) throw ()
 Multiply by a scalar.
TVector4 TVector4::operator/ (const T &scalar) throw (Exception::DivisionByZero)
 Fraction of a vector.
TVector4 & TVector4::operator/= (const T &scalar) throw (Exception::DivisionByZero)
 Divide a vector by a scalar.
TVector4::operator * (const TVector4 &vector) const throw ()
 Dot product.
TVector4::getDistance (const TVector4 &vector) const throw ()
 Return the distance to another vector.
TVector4::getSquareDistance (const TVector4 &vector) const throw ()
 Return the squared distance to another vector.

Predicates

bool TVector4::operator== (const TVector4 &vector) const throw ()
 Equality operator.
bool TVector4::operator!= (const TVector4 &vector) const throw ()
 Inequality operator.
bool TVector4::isOrthogonalTo (const TVector4 &vector) const throw ()
 Orthogonality predicate.

Debugging and Diagnostics

bool TVector4::isValid () const throw ()
 Test whether instance is valid.
void TVector4::dump (std::ostream &s=std::cout, Size depth=0) const throw ()
 Internal state dump.

Typedefs

typedef TVector4< float > Vector4
 Default four-dimensional vector type.

Functions

template<typename T>
TVector4< T > operator * (const T &scalar, const TVector4< T > &v) throw ()
 Multiplication operator for a scalar and a vector.
template<typename T>
TVector4< T > operator * (const TVector4< T > &v, const T &scalar) throw ()
 Multiplication operator for a vector and a scalar.

Detailed Description


Function Documentation

template<typename T>
virtual void TVector4< T >::clear  )  throw () [virtual, inherited]
 

Clear method The values are set to 0.

template<typename T>
void TVector4< T >::dump std::ostream &  s = std::cout,
Size  depth = 0
const throw () [inherited]
 

Internal state dump.

Dump the current internal state of {*this} to the output ostream s with dumping depth depth .

Parameters:
s - output stream where to output the internal state of {*this}
depth - the dumping depth

template<typename T>
void TVector4< T >::get TVector4< T > &  vector  )  const throw () [inherited]
 

Assign to another Vector4.

Assigns the vector components to another vector.

Parameters:
vector the vector to be assigned to

template<typename T>
void TVector4< T >::get T &  rx,
T &  ry,
T &  rz,
T &  rh
const throw () [inherited]
 

Assign to four variables of type T.

Parameters:
rx the x component
ry the y component
rz the z component
rh the h component

template<typename T>
void TVector4< T >::get T *  ptr  )  const throw (Exception::NullPointer) [inherited]
 

Assign to an array.

Sets the first four array elements pointed of array ptr to the values of the four vector components.

Parameters:
ptr the array
Exceptions:
NullPointer if ptr == 0

template<typename T>
T TVector4< T >::getDistance const TVector4< T > &  vector  )  const throw () [inherited]
 

Return the distance to another vector.

Parameters:
vector the reference vector
Returns:
T, the distance

template<typename T>
T TVector4< T >::getLength  )  const throw () [inherited]
 

Return the length of the vector.

The length of the vector is calculated as $\sqrt{x^2 + y^2 + z^2 + h^2}$.

Returns:
T, the vector length

template<typename T>
T TVector4< T >::getSquareDistance const TVector4< T > &  vector  )  const throw () [inherited]
 

Return the squared distance to another vector.

This method avoids the square root needed in getDistance, so this method should be preferred if possible.

Parameters:
vector the reference vector
Returns:
T, the squared distance

template<typename T>
T TVector4< T >::getSquareLength  )  const throw () [inherited]
 

Return the squared length of the vector.

This method avoids the square root needed in getLength, so this method should be preferred if possible.

Returns:
T, $x^2 + y^2 + z^2 + h^2$

template<typename T>
const TVector4< T > & TVector4< T >::getUnit  )  throw () [static, inherited]
 

Return a vector with all components 1.

template<typename T>
const TVector4< T > & TVector4< T >::getZero  )  throw () [static, inherited]
 

Return a vector with all components 0.

template<typename T>
bool TVector4< T >::isOrthogonalTo const TVector4< T > &  vector  )  const throw () [inherited]
 

Orthogonality predicate.

template<typename T>
bool TVector4< T >::isValid  )  const throw () [inherited]
 

Test whether instance is valid.

Always returns true

Returns:
bool true

template<typename T>
TVector4< T > & TVector4< T >::normalize  )  throw (Exception::DivisionByZero) [inherited]
 

Normalize the vector.

The vector is scaled with its length: $\{x|y|z|h\} *= \sqrt{x^2 + y^2 + z^2 + h^2}$.

Returns:
T, a reference to {*this} vector
Exceptions:
DivisionByZero if the length of the vector is 0

template<typename T>
T TVector4< T >::operator * const TVector4< T > &  vector  )  const throw () [inherited]
 

Dot product.

Parameters:
vector the vector to multiply by
Returns:
T the dot product of this vector with vector.

template<typename T>
TVector4< T > TVector4< T >::operator * const T &  scalar  )  throw () [inherited]
 

Scalar product.

Return TVector4(x * scalar, y * scalar, z * scalar, h * scalar).

Parameters:
scalar the scalar to multiply by
Returns:
TVector4 the scalar product of this vector and scalar

template<typename T>
TVector4<T> operator * const TVector4< T > &  v,
const T &  scalar
throw ()
 

Multiplication operator for a vector and a scalar.

Returns:
TVector4 the new vector

template<typename T>
TVector4<T> operator * const T &  scalar,
const TVector4< T > &  v
throw ()
 

Multiplication operator for a scalar and a vector.

Returns:
TVector4 the new vector

template<typename T>
TVector4< T > & TVector4< T >::operator *= const T &  scalar  )  throw () [inherited]
 

Multiply by a scalar.

Multiply all components of the vector with a scalar.

Parameters:
scalar the scalar to multiply by
Returns:
TVector4& {*this}

template<typename T>
bool TVector4< T >::operator!= const TVector4< T > &  vector  )  const throw () [inherited]
 

Inequality operator.

The function Maths::isEqual is used to compare the values. Maths::isEqual

Returns:
bool, true if the two vectors differ in at least one component, false otherwise

template<typename T>
TVector4< T > TVector4< T >::operator+  )  const throw () [inherited]
 

Positive sign.

template<typename T>
TVector4< T > & TVector4< T >::operator+= const TVector4< T > &  vector  )  throw () [inherited]
 

Add a vector to this vector.

Parameters:
vector the vector to add
Returns:
TVector4, {*this}

template<typename T>
TVector4< T > TVector4< T >::operator-  )  const throw () [inherited]
 

Negative sign.

template<typename T>
TVector4< T > operator- const TVector4< T > &  a,
const TVector4< T > &  b
throw ()
 

Subtraction operator for two vectors.

Returns:
TVector4 the new vector

template<typename T>
TVector4< T > & TVector4< T >::operator-= const TVector4< T > &  vector  )  throw () [inherited]
 

Subtract a vector from this vector.

Parameters:
vector the vector to subtract
Returns:
TVector4 {*this}

template<typename T>
TVector4< T > TVector4< T >::operator/ const T &  scalar  )  throw (Exception::DivisionByZero) [inherited]
 

Fraction of a vector.

Return TVector4(x / scalar, y / scalar, z / scalar, h / scalar).

Parameters:
scalar the scalar to divide by
Returns:
TVector4
Exceptions:
Exception::DivisionByZero if scalar == (T)0

template<typename T>
TVector4< T > & TVector4< T >::operator/= const T &  scalar  )  throw (Exception::DivisionByZero) [inherited]
 

Divide a vector by a scalar.

Parameters:
scalar the scalar to divide by
Returns:
TVector4&, {*this}
Exceptions:
Exception::DivisionByZero if scalar == (T)0

template<typename T>
std::ostream & operator<< std::ostream &  s,
const TVector4< T > &  v
throw ()
 

Output Operator.

Write the four components of the vector to an output stream. The values are enclosed by brackets.

Example:
(0.1 2.0 0 1)

template<typename T>
TVector4< T > & TVector4< T >::operator= value  )  throw () [inherited]
 

Assignment operator.

Assign a constant value to all four vector components.

Parameters:
value the constant to assign to x, y, z, h

template<typename T>
TVector4< T > & TVector4< T >::operator= const TVector4< T > &  vector  )  throw () [inherited]
 

Assignment operator.

Assign the vector components from another vector.

Parameters:
vector the vector to assign from

template<typename T>
TVector4< T > & TVector4< T >::operator= const T *  ptr  )  throw (Exception::NullPointer) [inherited]
 

Array assignment operator.

Assigns the first four elements of an array to the vector components x, y, z and h.

Parameters:
ptr the array
Exceptions:
NullPointer if ptr == 0

template<typename T>
bool TVector4< T >::operator== const TVector4< T > &  vector  )  const throw () [inherited]
 

Equality operator.

The function Maths::isEqual is used to compare the values. Maths::isEqual

Returns:
bool, true if all four vector components are equal, false otherwise

template<typename T>
std::istream & operator>> std::istream &  s,
TVector4< T > &  v
throw ()
 

Input operator Reads four values of type T from an input stream and assigns them to the components x, y, z and h of the vector.

template<typename T>
const T & TVector4< T >::operator[] Position  position  )  const throw (Exception::IndexOverflow) [inherited]
 

Constant array-like access to the components.

Exceptions:
Exception::IndexOverflow if index > 3

template<typename T>
T & TVector4< T >::operator[] Position  position  )  throw (Exception::IndexOverflow) [inherited]
 

Mutable array-like access to the components.

Exceptions:
Exception::IndexOverflow if index > 3

template<typename T>
void TVector4< T >::set const T &  value = (T) 1  )  throw () [inherited]
 

Assign one value to all vector components.

Parameters:
value the value to be assigned to, default: 1

template<typename T>
void TVector4< T >::set const TVector4< T > &  vector  )  throw () [inherited]
 

Assign from another TVector4.

Parameters:
vector the TVector4 object to assign from

template<typename T>
void TVector4< T >::set const T &  rx,
const T &  ry,
const T &  rz,
const T &  rh = (T) 1
throw () [inherited]
 

Assign the vector components.

Parameters:
rx the new x component
ry the new y component
rz the new z component
rh the new h component, default: 1

template<typename T>
void TVector4< T >::set const T *  ptr  )  throw (Exception::NullPointer) [inherited]
 

Assign from an array.

Assign the four components x, y, z and h from the first four elements of the array pointed to by ptr.

Parameters:
ptr an array
Exceptions:
Nullpointer if ptr == 0

template<typename T>
void TVector4< T >::swap TVector4< T > &  vector  )  throw () [inherited]
 

Swap the contents of two vectors.

Parameters:
vector the vector to swap contents with

template<typename T>
TVector4< T >::TVector4 const TVector4< T > &  vector  )  throw () [inherited]
 

Copy constructor.

Create a new TVector4 object from another.

Parameters:
vector the TVector4 object to be copied

template<typename T>
TVector4< T >::TVector4 const T &  x,
const T &  y,
const T &  z,
const T &  h = (T) 1
throw () [inherited]
 

Detailed constructor.

Create a new TVector4 object from three or four values of type T.

Parameters:
x assigned to x
y assigned to y
z assigned to z
h assigned to h, default: 1 ;

template<typename T>
TVector4< T >::TVector4 const T &  value  )  throw () [explicit, inherited]
 

Scalar constructor.

Create a new vector with all components set to the same value.

Parameters:
value the value of all components

template<typename T>
TVector4< T >::TVector4 const T *  ptr  )  throw (Exception::NullPointer) [inherited]
 

Array constructor.

This constructor creates a TVector4 object from the first four elements pointed by ptr.

Parameters:
ptr the array to construct from
Exceptions:
NullPointer if ptr == 0

template<typename T>
TVector4< T >::TVector4  )  throw () [inherited]
 

Default constructor.

This method creates a new TVector4 object. The four components are initialized to (T)0.

template<typename T>
TVector4< T >::~TVector4  )  throw () [virtual, inherited]
 

Destructor.

Destructs the TVector4 object. As there are no dynamic data structures, nothing happens.