syBR::Core::Vector2D Class Reference

2D vector class More...

#include <Vector2D.hpp>

List of all members.

Public Member Functions

 Vector2D ()
 Constructor #1.
 Vector2D (float x, float y)
 Constructor #2.
 Vector2D (const Vector2D &vector)
 Copy constructor.
const float getX () const
 Get the x coordinate of the vector.
const float getY () const
 Get the y coordinate of the vector.
void set (const float x, const float y)
 Set the coordinates of the vector.
void setX (const float x)
 Set the x coordinate of the vector.
void setY (const float y)
 Set the y coordinate of the vector.
void from2Array (const float array[2])
 Set the coordinates of the vector from a 2-element array.
const float getLength () const
 Calculate the length (magnitude) of the vector.
Vector2D normalize () const
 Return a normalized vector which have the same directions as this vector.
Vector2Doperator= (const Vector2D &arg)
 Set the vector coordinates using an "=" operator.
Vector2D operator+ (const Vector2D &arg) const
 Add a vector using a "+" operator.
Vector2D operator- (const Vector2D &arg) const
 Substract a vector using a "-" operator.
Vector2D operator * (const float arg) const
 Multiply coordinates by a scalar using a "*" operator.
Vector2D operator/ (const float arg) const
 Divide coordinates by a scalar using a "/" operator.
void operator+= (const Vector2D &arg)
 Add the coordinates of a vector to those of this using a "+=" operator.
void operator-= (const Vector2D &arg)
 Substract the coordinates of a vector from those of this using a "-=" operator.
void operator *= (const float arg)
 Multiply the coordinates of this by a scalar using a "*=" operator.
void operator/= (const float arg)
 Divide the coordinates of this by a scalar using a "/=" operator.
bool operator== (const Vector2D &arg) const
 Compare a vector to this.
bool operator!= (const Vector2D &arg) const
 Compare a vector to this.

Private Attributes

float m_x
 x coordinate of the vector
float m_y
 y coordinate of the vector
float m_length
 Length of the vector (0 if not calculated yet).
bool m_lengthChanged
 Indicate if length has been changed since last time it was calculated (it avoids to re-calculate the length too many times).


Detailed Description

2D vector class

Constructor & Destructor Documentation

syBR::Core::Vector2D::Vector2D (  ) 

Constructor #1.

Initialize vector to (0,0)

syBR::Core::Vector2D::Vector2D ( float  x,
float  y 
)

Constructor #2.

Initialize vector to specific coordinates

Parameters:
x X coordinate of the vector
y Y coordinate of the vector

syBR::Core::Vector2D::Vector2D ( const Vector2D vector  ) 

Copy constructor.

Parameters:
vector 2D vector from which coordinates must be copied


Member Function Documentation

const float syBR::Core::Vector2D::getX (  )  const [inline]

Get the x coordinate of the vector.

Returns:
x coordinate

const float syBR::Core::Vector2D::getY (  )  const [inline]

Get the y coordinate of the vector.

Returns:
y coordinate

void syBR::Core::Vector2D::set ( const float  x,
const float  y 
)

Set the coordinates of the vector.

Parameters:
x X coordinate of the vector
y Y coordinate of the vector

void syBR::Core::Vector2D::setX ( const float  x  ) 

Set the x coordinate of the vector.

Parameters:
x X coordinate of the vector

void syBR::Core::Vector2D::setY ( const float  y  ) 

Set the y coordinate of the vector.

Parameters:
y Y coordinate of the vector

void syBR::Core::Vector2D::from2Array ( const float  array[2]  ) 

Set the coordinates of the vector from a 2-element array.

Parameters:
array Array containing the (x,y) coordinates

const float syBR::Core::Vector2D::getLength (  )  const

Calculate the length (magnitude) of the vector.

Returns:
Length/magnitude of the vector
Note:
If called twice without modifying coordinates, it won't calculate it again (it stores the result).

Vector2D syBR::Core::Vector2D::normalize (  )  const

Return a normalized vector which have the same directions as this vector.

Returns:
One of these:
  • Corresponding normalized vector if length is not null
  • Same vector otherwise

Vector2D & syBR::Core::Vector2D::operator= ( const Vector2D arg  ) 

Set the vector coordinates using an "=" operator.

Parameters:
arg New coordinates to set
Returns:
Vector containing the new coordinates (a reference to *this)

Vector2D syBR::Core::Vector2D::operator+ ( const Vector2D arg  )  const

Add a vector using a "+" operator.

Parameters:
arg Coordinates to add
Returns:
New vector which coordinates are the sum of the coordinates of this and arg

Vector2D syBR::Core::Vector2D::operator- ( const Vector2D arg  )  const

Substract a vector using a "-" operator.

Parameters:
arg Coordinates to substract
Returns:
New vector which coordinates are the difference of the coordinates of this and arg

Vector2D syBR::Core::Vector2D::operator * ( const float  arg  )  const

Multiply coordinates by a scalar using a "*" operator.

Parameters:
arg Scalar to multiply by
Returns:
New vector which coordinates are those of this multiplied by arg

Vector2D syBR::Core::Vector2D::operator/ ( const float  arg  )  const

Divide coordinates by a scalar using a "/" operator.

Parameters:
arg Scalar to divide by
Returns:
New vector which coordinates are those of this divided by arg
Note:
Nothing is done if arg is 0 or 1.

void syBR::Core::Vector2D::operator+= ( const Vector2D arg  ) 

Add the coordinates of a vector to those of this using a "+=" operator.

Parameters:
arg Coordinates to add

void syBR::Core::Vector2D::operator-= ( const Vector2D arg  ) 

Substract the coordinates of a vector from those of this using a "-=" operator.

Parameters:
arg Coordinates to substract

void syBR::Core::Vector2D::operator *= ( const float  arg  ) 

Multiply the coordinates of this by a scalar using a "*=" operator.

Parameters:
arg Coordinates to multiply by

void syBR::Core::Vector2D::operator/= ( const float  arg  ) 

Divide the coordinates of this by a scalar using a "/=" operator.

Parameters:
arg Scalar to divide by
Note:
Nothing is done if arg is 0 or 1.

bool syBR::Core::Vector2D::operator== ( const Vector2D arg  )  const

Compare a vector to this.

Parameters:
arg Vector to compare to
Returns:
true if they are equal, false otherwise
Note:
The comparison takes rounding errors in account by using the Math::EPSILON() constant.

bool syBR::Core::Vector2D::operator!= ( const Vector2D arg  )  const

Compare a vector to this.

Parameters:
arg Vector to compare to
Returns:
true if they are different, false otherwise
Note:
The comparison takes rounding errors in account by using the Math::EPSILON constant.


Member Data Documentation

float syBR::Core::Vector2D::m_x [private]

x coordinate of the vector

float syBR::Core::Vector2D::m_y [private]

y coordinate of the vector

float syBR::Core::Vector2D::m_length [private]

Length of the vector (0 if not calculated yet).

bool syBR::Core::Vector2D::m_lengthChanged [private]

Indicate if length has been changed since last time it was calculated (it avoids to re-calculate the length too many times).


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

Copyright © 2008 by Sebastien Frippiat
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.
Last modified Tue Dec 30 17:57:33 2008