Loading...
Searching...
No Matches
BALL::TVector2< T > Class Template Reference

`#include <BALL/MATHS/vector2.h>`

Inheritance diagram for BALL::TVector2< T >:

## Public Member Functions

Constructors and Destructors
| TVector2 ()
| TVector2 (const T &value)
| TVector2 (const T &vx, const T &vy)
| TVector2 (const TVector2 &vector)
| TVector2 (const T *ptr)
virtual | ~TVector2 ()
virtual void | clear ()
Persistence
virtual void | persistentWrite (PersistenceManager &pm, const char *name=0) const
virtual void | persistentRead (PersistenceManager &pm)
Arithmetic operators
const TVector2 & | operator+ () const
TVector2 | operator- () const
TVector2 | operator+ (const TVector2 &b) const
TVector2 | operator- (const TVector2 &b) const
TVector2 & | operator+= (const TVector2 &vector)
TVector2 & | operator-= (const TVector2 &vector)
TVector2 | operator* (const T &scalar) const
TVector2 & | operator*= (const T &scalar)
TVector2 | operator/ (const T &lambda) const
TVector2 & | operator/= (const T &lambda)
T | operator* (const TVector2 &vector) const
Geometric properties
T | getDistance (const TVector2 &vector) const
T | getSquareDistance (const TVector2 &vector) const
Predicates
bool | operator== (const TVector2 &vector) const
bool | operator!= (const TVector2 &vector) const
bool | isZero () const
bool | isOrthogonalTo (TVector2 &vector) const
Debugging and Diagnostics
void | dump (std::ostream &s=std::cout, Size depth=0) const
bool | isValid () const
Public Member Functions inherited from BALL::PersistentObject
| PersistentObject ()
virtual | ~PersistentObject ()
PersistenceManager & | operator>> (PersistenceManager &pm) const
virtual void | finalize ()
Public Member Functions inherited from BALL::Object
| Object ()
| Default constructor.
| Object (const Object &object)
| Copy constructor.
virtual | ~Object ()
| Destructor.
const Object & | operator= (const Object &)
bool | operator== (const Object &object) const
bool | operator!= (const Object &object) const
bool | operator< (const Object &object) const
bool | operator<= (const Object &object) const
bool | operator>= (const Object &object) const
bool | operator> (const Object &object) const
int | compare (const Object &object) const
virtual void | dump (::std::ostream &s=std::cout, Size depth=0) const
Handle | getHandle () const
Public Member Functions inherited from BALL::AutoDeletable
virtual | ~AutoDeletable ()
void * | operator new (size_t size)
void | operator delete (void *ptr)
void * | operator new (size_t size, void *ptr)
void | operator delete (void *ptr, void *)
bool | isAutoDeletable () const
void | setAutoDeletable (bool enable)

## Public Attributes

Vector components
For easier access, the two components of the vector are public members.
T | x
T | y

## Assignment

void | set (const T &value)
void | set (const T &vx, const T &vy)
void | set (const TVector2 &vector)
TVector2 & | operator= (const TVector2 &v)
TVector2 & | operator= (const T &value)
TVector2 & | operator= (const T *ptr)
T | getLength () const
T | getSquareLength () const
TVector2 & | normalize ()
TVector2 & | negate ()
T & | operator[] (Position position)
const T & | operator[] (Position position) const
static const TVector2 & | getZero ()
static const TVector2 & | getUnit ()

## Additional Inherited Members

static Handle | getNextHandle ()
static Handle | getNewHandle ()
static void | clearLastPtr ()
| AutoDeletable ()
| AutoDeletable (const AutoDeletable &auto_deletable, bool deep=false)

## Detailed Description

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

Generic Two-Dimensional Vector.

Definition at line 61 of file vector2.h.

## Constructor & Destructor Documentation

## TVector2() [1/5]

template<typename T>

BALL::TVector2< T >::TVector2 | ( |  | ) |

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

Definition at line 386 of file vector2.h.

## TVector2() [2/5]

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

Definition at line 394 of file vector2.h.

## TVector2() [3/5]

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

Definition at line 402 of file vector2.h.

## TVector2() [4/5]

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

Definition at line 410 of file vector2.h.

## TVector2() [5/5]

template<typename T>

BALL_INLINE BALL::TVector2< T >::TVector2 | ( | const T * | ptr | ) |

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

Definition at line 424 of file vector2.h.

## ~TVector2()

template<typename T>

BALL::TVector2< T >::~TVector2 | ( |  | ) |

virtual

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

Definition at line 418 of file vector2.h.

## Member Function Documentation

## clear()

template<typename T>

void BALL::TVector2< T >::clear | ( |  | ) |

virtual

Clear method The values are set to 0.

Reimplemented from BALL::Object.

Definition at line 436 of file vector2.h.

## dump()

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

Definition at line 754 of file vector2.h.

## getDistance()

template<typename T>

BALL_INLINE T BALL::TVector2< T >::getDistance | ( | const TVector2< T > & | vector | ) | const

Return the distance to another vector.

Definition at line 700 of file vector2.h.

## getLength()

template<typename T>

BALL_INLINE T BALL::TVector2< T >::getLength | ( |  | ) | const

Return the length of the vector. The length of the vector is calculated as .

Returns
  T, the vector length

Definition at line 517 of file vector2.h.

## getSquareDistance()

template<typename T>

BALL_INLINE T BALL::TVector2< T >::getSquareDistance | ( | const TVector2< T > & | vector | ) | const

Return the squared distance to another vector.

Definition at line 710 of file vector2.h.

## getSquareLength()

template<typename T>

BALL_INLINE 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,

Definition at line 524 of file vector2.h.

## getUnit()

template<typename T>

BALL_INLINE const TVector2< T > & BALL::TVector2< T >::getUnit | ( |  | ) |

static

Return a vector with all components 1.

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

Definition at line 563 of file vector2.h.

## getZero()

template<typename T>

BALL_INLINE const TVector2< T > & BALL::TVector2< T >::getZero | ( |  | ) |

static

Return a vector with all components 0.

Definition at line 555 of file vector2.h.

## isOrthogonalTo()

template<typename T>

BALL_INLINE bool BALL::TVector2< T >::isOrthogonalTo | ( | TVector2< T > & | vector | ) | const

Orthogonality predicate.

Definition at line 734 of file vector2.h.

## isValid()

template<typename T>

BALL_INLINE bool BALL::TVector2< T >::isValid | ( |  | ) | const

virtual

Test if instance is valid. Always returns true.

Returns
  bool true

Reimplemented from BALL::Object.

Definition at line 741 of file vector2.h.

## isZero()

template<typename T>

BALL_INLINE bool BALL::TVector2< T >::isZero | ( |  | ) | const

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

Definition at line 748 of file vector2.h.

## negate()

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

Definition at line 546 of file vector2.h.

## normalize()

template<typename T>

TVector2< T > & BALL::TVector2< T >::normalize | ( |  | ) |

Normalize the vector. The vector is scaled with its length: .

Returns
  T, a reference to the normalized vector

Exceptions

  DivisionByZero | if the length of the vector is 0

Definition at line 530 of file vector2.h.

## operator!=()

template<typename T>

BALL_INLINE 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

Definition at line 727 of file vector2.h.

## operator*() [1/2]

template<typename T>

BALL_INLINE 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

Definition at line 653 of file vector2.h.

## operator*() [2/2]

template<typename T>

BALL_INLINE T BALL::TVector2< T >::operator* | ( | const TVector2< T > & | vector | ) | const

Dot product. Return the dot product of this vector and vector.

Definition at line 693 of file vector2.h.

## operator*=()

template<typename T>

BALL_INLINE 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}

Definition at line 660 of file vector2.h.

## operator+() [1/2]

template<typename T>

BALL_INLINE const TVector2< T > & BALL::TVector2< T >::operator+ | ( |  | ) | const

Positive sign.

Definition at line 605 of file vector2.h.

## operator+() [2/2]

template<typename T>

BALL_INLINE TVector2< T > BALL::TVector2< T >::operator+ | ( | const TVector2< T > & | b | ) | const

Addition.

Definition at line 619 of file vector2.h.

## operator+=()

template<typename T>

BALL_INLINE 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}

Definition at line 633 of file vector2.h.

## operator-() [1/2]

template<typename T>

BALL_INLINE TVector2< T > BALL::TVector2< T >::operator- | ( |  | ) | const

Negative sign.

Definition at line 612 of file vector2.h.

## operator-() [2/2]

template<typename T>

BALL_INLINE TVector2< T > BALL::TVector2< T >::operator- | ( | const TVector2< T > & | b | ) | const

Subtraction.

Definition at line 626 of file vector2.h.

## operator-=()

template<typename T>

BALL_INLINE 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}

Definition at line 643 of file vector2.h.

## operator/()

template<typename T>

TVector2< T > BALL::TVector2< T >::operator/ | ( | const T & | lambda | ) | const

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

Definition at line 669 of file vector2.h.

## operator/=()

template<typename T>

TVector2< T > & BALL::TVector2< T >::operator/= | ( | const T & | lambda | ) |

Divide a vector by a scalar.

Parameters

  lambda | the scalar value to divide by

Returns
  TVector2&, {*this}

Exceptions

  Exception::DivisionByZero | if lambda == (T)0

Definition at line 679 of file vector2.h.

## operator=() [1/3]

template<typename T>

BALL_INLINE 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

Definition at line 507 of file vector2.h.

## operator=() [2/3]

template<typename T>

BALL_INLINE TVector2< T > & BALL::TVector2< T >::operator= | ( | const T * | ptr | ) |

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

Parameters

  ptr | the array

Exceptions

  NullPointer | if ptr == 0

Definition at line 493 of file vector2.h.

## operator=() [3/3]

template<typename T>

BALL_INLINE 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

Definition at line 483 of file vector2.h.

## operator==()

template<typename T>

BALL_INLINE 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

Definition at line 720 of file vector2.h.

## operator[]() [1/2]

template<typename T>

BALL_INLINE T & BALL::TVector2< T >::operator[] | ( | Position | position | ) |

Mutable array-like access to the components.

Exceptions

  Exception::IndexOverflow | if index > 1

Definition at line 571 of file vector2.h.

## operator[]() [2/2]

template<typename T>

BALL_INLINE const T & BALL::TVector2< T >::operator[] | ( | Position | position | ) | const

Constant array-like access to the components.

Exceptions

  Exception::IndexOverflow | if index > 1

Definition at line 588 of file vector2.h.

## persistentRead()

template<typename T>

void BALL::TVector2< T >::persistentRead | ( | PersistenceManager & | pm | ) |

virtual

Persistent reading. Reads a TVector2 object from a persistent stream.

Parameters

  pm | the persistence manager

Exceptions

  Exception::GeneralException |

Reimplemented from BALL::PersistentObject.

Definition at line 451 of file vector2.h.

## persistentWrite()

template<typename T>

void BALL::TVector2< T >::persistentWrite | ( | PersistenceManager & | pm,
|  | const char * | name = 0 ) const

virtual

Persistent writing. Writes a TVector2 object to a persistent stream.

Parameters

  pm | the persistence manager

Reimplemented from BALL::PersistentObject.

Definition at line 442 of file vector2.h.

## set() [1/3]

template<typename T>

BALL_INLINE 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

Definition at line 459 of file vector2.h.

## set() [2/3]

template<typename T>

BALL_INLINE 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

Definition at line 467 of file vector2.h.

## set() [3/3]

template<typename T>

BALL_INLINE void BALL::TVector2< T >::set | ( | const TVector2< T > & | vector | ) |

Assign from another TVector2.

Parameters

  vector | the TVector2 object to assign from

Definition at line 475 of file vector2.h.

## Member Data Documentation

## x

template<typename T>

T BALL::TVector2< T >::x

x component of the vector

Definition at line 372 of file vector2.h.

## y

template<typename T>

T BALL::TVector2< T >::y

y component of the vector

Definition at line 376 of file vector2.h.