Vector2D Class Reference

#include <Vector2D.h>

List of all members.

Public Member Functions

 Vector2D ()
 Vector2D (double x, double y)
void normalize ()
double distanceSqr (const Vector2D v) const
double xyMaxDistance (const Vector2D v) const
double cosAngle (const Vector2D &v) const
int getQuadrant (const Vector2D &v) const
 Determine the Quarant a point is contained in.
Vector2Doperator= (const Vector2D &v)
Vector2Doperator+= (const Vector2D &v)
Vector2Doperator-= (const Vector2D &v)
Vector2Doperator*= (const double s)
Vector2Doperator/= (const double s)
Vector2D operator+ (const Vector2D &v) const
Vector2D operator- (const Vector2D &v) const
Vector2D operator* (const double s) const
Vector2D operator/ (const double s) const
bool operator== (const Vector2D &v) const
bool operator!= (const Vector2D &v) const
void netPack (cCommBuffer *b)
void netUnpack (cCommBuffer *b)

Public Attributes

double x
double y

Friends

bool operator< (const Vector2D &a, const Vector2D &b)
std::ostream & operator<< (std::ostream &Stream, const Vector2D &v)

Detailed Description

Definition at line 31 of file Vector2D.h.


Constructor & Destructor Documentation

Vector2D::Vector2D (  ) 

Definition at line 27 of file Vector2D.cc.

00028 {
00029     x = 0.0;
00030     y = 0.0;
00031 }

Vector2D::Vector2D ( double  x,
double  y 
)

Definition at line 33 of file Vector2D.cc.

00034 {
00035     this->x = x;
00036     this->y = y;
00037 }


Member Function Documentation

double Vector2D::cosAngle ( const Vector2D v  )  const

Definition at line 62 of file Vector2D.cc.

Referenced by MovementGenerator::flock().

00063 {
00064     return (x * v.x + y * v.y) / (sqrt(x * x + y * y) * sqrt(v.x * v.x + v.y * v.y));
00065 }

double Vector2D::distanceSqr ( const Vector2D  v  )  const
int Vector2D::getQuadrant ( const Vector2D v  )  const

Determine the Quarant a point is contained in.

Return the quadrant of this point that containes point v. Upper right quadrant is 0, lower right is 1, lower left is 2 and upper left is 3

Parameters:
v the target point
Returns:
the quadrant v is in in

Definition at line 78 of file Vector2D.cc.

Referenced by Quon::classifySites().

00079 {
00080     int quad = 0;
00081     // v.y <= this.y -> quadrant 1 or 2
00082     if( v.y <= y ) quad = 1;
00083     // v.x <= this.x -> quadrant 2 or 3
00084     if( v.x <= x ) quad ^= 3;
00085     return quad;
00086 }

void Vector2D::netPack ( cCommBuffer *  b  ) 

Definition at line 184 of file Vector2D.cc.

Referenced by doPacking().

00185 {
00186     //cMessage::netPack(b);
00187     doPacking(b, this->x);
00188     doPacking(b, this->y);
00189 }

void Vector2D::netUnpack ( cCommBuffer *  b  ) 

Definition at line 191 of file Vector2D.cc.

Referenced by doUnpacking().

00192 {
00193     //cMessage::netUnpack(b);
00194     doUnpacking(b, this->x);
00195     doUnpacking(b, this->y);
00196 }

void Vector2D::normalize (  ) 

Definition at line 39 of file Vector2D.cc.

Referenced by MovementGenerator::flock(), MovementGenerator::MovementGenerator(), traverseRoaming::traverseRoaming(), and SimpleGameClient::updateNeighbors().

00040 {
00041     double temp;
00042     temp = sqrt(x * x + y * y);
00043     if(temp != 0.0) {
00044         x /= temp;
00045         y /= temp;
00046     }
00047 }

bool Vector2D::operator!= ( const Vector2D v  )  const

Definition at line 163 of file Vector2D.cc.

00164 {
00165     if(x != v.x || y != v.y)
00166         return true;
00167     else
00168         return false;
00169 }

Vector2D Vector2D::operator* ( const double  s  )  const

Definition at line 139 of file Vector2D.cc.

00140 {
00141     Vector2D temp;
00142     temp.x = x * s;
00143     temp.y = y * s;
00144     return temp;
00145 }

Vector2D & Vector2D::operator*= ( const double  s  ) 

Definition at line 109 of file Vector2D.cc.

00110 {
00111     x *= s;
00112     y *= s;
00113     return *this;
00114 }

Vector2D Vector2D::operator+ ( const Vector2D v  )  const

Definition at line 123 of file Vector2D.cc.

00124 {
00125     Vector2D temp;
00126     temp.x = x + v.x;
00127     temp.y = y + v.y;
00128     return temp;
00129 }

Vector2D & Vector2D::operator+= ( const Vector2D v  ) 

Definition at line 95 of file Vector2D.cc.

00096 {
00097     x += v.x;
00098     y += v.y;
00099     return *this;
00100 }

Vector2D Vector2D::operator- ( const Vector2D v  )  const

Definition at line 131 of file Vector2D.cc.

00132 {
00133     Vector2D temp;
00134     temp.x = x - v.x;
00135     temp.y = y - v.y;
00136     return temp;
00137 }

Vector2D & Vector2D::operator-= ( const Vector2D v  ) 

Definition at line 102 of file Vector2D.cc.

00103 {
00104     x -= v.x;
00105     y -= v.y;
00106     return *this;
00107 }

Vector2D Vector2D::operator/ ( const double  s  )  const

Definition at line 147 of file Vector2D.cc.

00148 {
00149     Vector2D temp;
00150     temp.x = x / s;
00151     temp.y = y / s;
00152     return temp;
00153 }

Vector2D & Vector2D::operator/= ( const double  s  ) 

Definition at line 116 of file Vector2D.cc.

00117 {
00118     x /= s;
00119     y /= s;
00120     return *this;
00121 }

Vector2D & Vector2D::operator= ( const Vector2D v  ) 

Definition at line 88 of file Vector2D.cc.

00089 {
00090     x = v.x;
00091     y = v.y;
00092     return *this;
00093 }

bool Vector2D::operator== ( const Vector2D v  )  const

Definition at line 155 of file Vector2D.cc.

00156 {
00157     if(x == v.x && y == v.y)
00158         return true;
00159     else
00160         return false;
00161 }

double Vector2D::xyMaxDistance ( const Vector2D  v  )  const

Definition at line 57 of file Vector2D.cc.

Referenced by Quon::classifySites(), and QuonAOI::collide().

00058 {
00059     return std::max(abs(x - v.x), abs(y - v.y));
00060 }


Friends And Related Function Documentation

bool operator< ( const Vector2D a,
const Vector2D b 
) [friend]

Definition at line 171 of file Vector2D.cc.

00172 {
00173     if(a.y == b.y)
00174         return a.x < b.x;
00175     else
00176         return a.y < b.y;
00177 }

std::ostream& operator<< ( std::ostream &  Stream,
const Vector2D v 
) [friend]

Definition at line 179 of file Vector2D.cc.

00180 {
00181     return Stream << std::fixed << "[" << v.x << ", " << v.y << "]";
00182 }


Member Data Documentation

double Vector2D::x
double Vector2D::y

The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:19 2010 for OverSim by  doxygen 1.6.3