BALL::TVector2< T > Class Template Reference
[Two-dimensional vectors.]

Generic Two-Dimensional Vector. More...

#include <vector2.h>

Inheritance diagram for BALL::TVector2< T >:
Inheritance graph
[legend]

List of all members.


Public Member Functions

Constructors and Destructors
TVector2 ()
Default constructor.
TVector2 (const T &value)
Scalar constructor.
TVector2 (const T &vx, const T &vy)
Detailed constructor.
TVector2 (const TVector2 &vector)
Copy constructor.
TVector2 (const T *ptr) throw (Exception::NullPointer)
Array constructor.
virtual ~TVector2 ()
Destructor.
virtual void clear ()
Clear method The values are set to 0.
Persistence
virtual void persistentWrite (PersistenceManager &pm, const char *name=0) const throw (Exception::GeneralException)
Persistent writing.
virtual void persistentRead (PersistenceManager &pm) throw (Exception::GeneralException)
Persistent reading.
Arithmetic operators
const TVector2 & operator+ () const
Positive sign.
TVector2 operator- () const
Negative sign.
TVector2 operator+ (const TVector2 &b) const
Addition.
TVector2 operator- (const TVector2 &b) const
Subtraction.
TVector2 & operator+= (const TVector2 &vector)
Add a vector to this vector.
TVector2 & operator-= (const TVector2 &vector)
Subtract a vector from this vector.
TVector2 operator* (const T &scalar) const
Scalar product.
TVector2 & operator*= (const T &scalar)
Multiply by a scalar.
TVector2 operator/ (const T &lambda) const throw (Exception::DivisionByZero)
Fraction of a vector.
TVector2 & operator/= (const T &lambda) throw (Exception::DivisionByZero)
Divide a vector by a scalar.
T operator* (const TVector2 &vector) const
Dot product.
Geometric properties
T getDistance (const TVector2 &vector) const
Return the distance to another vector.
T getSquareDistance (const TVector2 &vector) const
Return the squared distance to another vector.
Predicates
bool operator== (const TVector2 &vector) const
Equality operator.
bool operator!= (const TVector2 &vector) const
Inequality operator.
bool isZero () const
Zero predicate.
bool isOrthogonalTo (TVector2 &vector) const
Orthogonality predicate.
Debugging and Diagnostics
void dump (std::ostream &s=std::cout, Size depth=0) const
Internal state dump.
bool isValid () const
Test if instance is valid.

Public Attributes

Vector components
For easier access, the two components of the vector are public members.

T x
x component of the vector
T y
y component of the vector

Assignment

void set (const T &value)
Assign from a scalar.
void set (const T &vx, const T &vy)
Assign the vector components.
void set (const TVector2 &vector)
Assign from another TVector2.
TVector2 & operator= (const TVector2 &v)
Assignment operator.
TVector2 & operator= (const T &value)
Assignment operator.
TVector2 & operator= (const T *ptr) throw (Exception::NullPointer)
Array assignment operator.
T getLength () const
Return the length of the vector.
T getSquareLength () const
Return the squared length of the vector.
TVector2 & normalize () throw (Exception::DivisionByZero)
Normalize the vector.
TVector2 & negate ()
Negate the vector.
T & operator[] (Position position) throw (Exception::IndexOverflow)
Mutable array-like access to the components.
const T & operator[] (Position position) const throw (Exception::IndexOverflow)
Constant array-like access to the components.
static const TVector2 & getZero ()
Return a vector with all components 0.
static const TVector2 & getUnit ()
Return a vector with all components 1.

Detailed Description

template<typename T>
class BALL::TVector2< T >

Generic Two-Dimensional Vector.

Constructor & Destructor Documentation

template<typename T >
BALL::TVector2< T >::TVector2 ( )

Default constructor.

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

template<typename T>
BALL::TVector2< T >::TVector2 ( const T & value ) [explicit]

Scalar constructor.

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

Parameters:
value the value of all components

template<typename T>
BALL::TVector2< T >::TVector2 ( const T & vx,
const T & vy
)

Detailed constructor.

Create a new TVector2 object from two variables of type T.

Parameters:
vx assigned to x
vy assigned to y

template<typename T>
BALL::TVector2< T >::TVector2 ( const TVector2< T > & vector )

Copy constructor.

Create a new TVector2 object from another.

Parameters:
vector the TVector2 object to be copied

template<typename T>
BALL::TVector2< T >::TVector2 ( const T * ptr ) throw (Exception::NullPointer)

Array constructor.

This constructor creates a TVector3 object from the first two elements pointed to by ptr.

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

template<typename T >
BALL::TVector2< T >::~TVector2 ( ) [virtual]

Destructor.

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


Member Function Documentation

template<typename T >
void BALL::TVector2< T >::dump ( std::ostream & s = std::cout,
Size depth = 0
) const

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

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
T BALL::TVector2< T >::getLength ( ) const

Return the length of the vector.

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

Returns:
T, the vector length

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
T BALL::TVector2< T >::getSquareLength ( ) const

Return the squared length of the vector.

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

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

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
const TVector2< T > & BALL::TVector2< T >::getUnit ( ) [static]

Return a vector with all components 1.

Returns:
: TVector4(1, 1, 1, 1)

template<typename T >
bool BALL::TVector2< T >::isValid ( ) const [virtual]

Test if instance is valid.

Always returns true.

Returns:
bool true

Reimplemented from BALL::Object.

template<typename T >
bool BALL::TVector2< T >::isZero ( ) const

Zero predicate.

The function Maths::isZero is used to compare the values with zero. Maths::isZero

References BALL::Maths::isZero(), BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

Referenced by BALL::TVector2< T >::isOrthogonalTo().

template<typename T >
TVector2< T > & BALL::TVector2< T >::negate ( )

Negate the vector.

Negate the two components of the vector

Returns:
T, a reference to {*this} vector

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
TVector2< T > & BALL::TVector2< T >::normalize ( ) throw (Exception::DivisionByZero)

Normalize the vector.

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

Returns:
T, a reference to the normalized vector
Exceptions:
DivisionByZero if the length of the vector is 0

References BALL::Maths::isZero(), BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
bool BALL::TVector2< T >::operator!= ( const TVector2< T > & vector ) const

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

References BALL::Maths::isNotEqual(), BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T>
T BALL::TVector2< T >::operator* ( const TVector2< T > & vector ) const

Dot product.

Return the dot product of this vector and vector.

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T>
TVector2< T > BALL::TVector2< T >::operator* ( const T & scalar ) const

Scalar product.

Return TVector2(x * scalar, y * scalar). The symmetric case is a global function.

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

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T>
TVector2< T > & BALL::TVector2< T >::operator*= ( const T & scalar )

Multiply by a scalar.

Multiply all components of the vector by a scalar value.

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

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
TVector2< T > & BALL::TVector2< T >::operator+= ( const TVector2< T > & vector )

Add a vector to this vector.

Add the components of vector to this vector.

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

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
TVector2< T > & BALL::TVector2< T >::operator-= ( const TVector2< T > & vector )

Subtract a vector from this vector.

Parameters:
vector the vector to subtract
Returns:
TVector2&, {*this}

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T>
TVector2< T > BALL::TVector2< T >::operator/ ( const T & lambda ) const throw (Exception::DivisionByZero)

Fraction of a vector.

Return TVector2(x / lambda, y / lambda).

Parameters:
lambda the scalar value to divide by
Returns:
TVector2&
Exceptions:
Exception::DivisionByZero if lambda == (T)0

template<typename T>
TVector2< T > & BALL::TVector2< T >::operator/= ( const T & lambda ) throw (Exception::DivisionByZero)

Divide a vector by a scalar.

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

template<typename T>
TVector2< T > & BALL::TVector2< T >::operator= ( const T * ptr ) throw (Exception::NullPointer)

Array assignment operator.

Assigns the first two elements of an array to the vector components.

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

template<typename T>
TVector2< T > & BALL::TVector2< T >::operator= ( const T & value )

Assignment operator.

Assign a constant value to the two vector components.

Parameters:
value the constant to assign to x, y

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
TVector2< T > & BALL::TVector2< T >::operator= ( const TVector2< T > & v )

Assignment operator.

Assign the vector components from another vector.

Parameters:
v the vector to assign from

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T >
bool BALL::TVector2< T >::operator== ( const TVector2< T > & vector ) const

Equality operator.

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

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

References BALL::Maths::isEqual(), BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

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

Constant array-like access to the components.

Exceptions:
Exception::IndexOverflow if index > 1

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

Mutable array-like access to the components.

Exceptions:
Exception::IndexOverflow if index > 1

template<typename T >
void BALL::TVector2< T >::persistentRead ( PersistenceManager & pm ) throw (Exception::GeneralException) [virtual]

Persistent reading.

Reads a TVector2 object from a persistent stream.

Parameters:
pm the persistence manager

Reimplemented from BALL::PersistentObject.

template<typename T >
void BALL::TVector2< T >::persistentWrite ( PersistenceManager & pm,
const char * name = 0
) const throw (Exception::GeneralException) [virtual]

Persistent writing.

Writes a TVector2 object to a persistent stream.

Parameters:
pm the persistence manager

Reimplemented from BALL::PersistentObject.

template<typename T>
void BALL::TVector2< T >::set ( const TVector2< T > & vector )

Assign from another TVector2.

Parameters:
vector the TVector2 object to assign from

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T>
void BALL::TVector2< T >::set ( const T & vx,
const T & vy
)

Assign the vector components.

Parameters:
vx the new x component
vy the new y component

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

template<typename T>
void BALL::TVector2< T >::set ( const T & value )

Assign from a scalar.

Assign value to the two vector components.

Parameters:
value the new value of the components

References BALL::TVector2< T >::x, and BALL::TVector2< T >::y.

Referenced by BALL::TRegularData2D< ValueType >::clear(), and BALL::TFFT2D< ComplexTraits >::getGridCoordinates().


Generated on Thu Aug 6 18:30:35 2009 for BALL by doxygen 1.5.8