OverSim
Vector2D Class Reference

#include <Vector2D.h>

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.

{
x = 0.0;
y = 0.0;
}
Vector2D::Vector2D ( double  x,
double  y 
)

Definition at line 33 of file Vector2D.cc.

{
this->x = x;
this->y = y;
}

Member Function Documentation

double Vector2D::cosAngle ( const Vector2D v) const

Definition at line 62 of file Vector2D.cc.

Referenced by MovementGenerator::flock().

{
return (x * v.x + y * v.y) / (sqrt(x * x + y * y) * sqrt(v.x * v.x + v.y * v.y));
}
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
vthe target point
Returns
the quadrant v is in in

Definition at line 78 of file Vector2D.cc.

Referenced by Quon::classifySites(), and NTreeNode::getChildForPos().

{
int quad = 0;
// v.y <= this.y -> quadrant 1 or 2
if( v.y <= y ) quad = 1;
// v.x <= this.x -> quadrant 2 or 3
if( v.x <= x ) quad ^= 3;
return quad;
}
void Vector2D::netPack ( cCommBuffer *  b)

Definition at line 184 of file Vector2D.cc.

Referenced by doPacking().

{
//cMessage::netPack(b);
doPacking(b, this->x);
doPacking(b, this->y);
}
void Vector2D::netUnpack ( cCommBuffer *  b)

Definition at line 191 of file Vector2D.cc.

Referenced by doUnpacking().

{
//cMessage::netUnpack(b);
doUnpacking(b, this->x);
doUnpacking(b, this->y);
}
void Vector2D::normalize ( )

Definition at line 39 of file Vector2D.cc.

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

{
double temp;
temp = sqrt(x * x + y * y);
if(temp != 0.0) {
x /= temp;
y /= temp;
}
}
bool Vector2D::operator!= ( const Vector2D v) const

Definition at line 163 of file Vector2D.cc.

{
if(x != v.x || y != v.y)
return true;
else
return false;
}
Vector2D Vector2D::operator* ( const double  s) const

Definition at line 139 of file Vector2D.cc.

{
Vector2D temp;
temp.x = x * s;
temp.y = y * s;
return temp;
}
Vector2D & Vector2D::operator*= ( const double  s)

Definition at line 109 of file Vector2D.cc.

{
x *= s;
y *= s;
return *this;
}
Vector2D Vector2D::operator+ ( const Vector2D v) const

Definition at line 123 of file Vector2D.cc.

{
Vector2D temp;
temp.x = x + v.x;
temp.y = y + v.y;
return temp;
}
Vector2D & Vector2D::operator+= ( const Vector2D v)

Definition at line 95 of file Vector2D.cc.

{
x += v.x;
y += v.y;
return *this;
}
Vector2D Vector2D::operator- ( const Vector2D v) const

Definition at line 131 of file Vector2D.cc.

{
Vector2D temp;
temp.x = x - v.x;
temp.y = y - v.y;
return temp;
}
Vector2D & Vector2D::operator-= ( const Vector2D v)

Definition at line 102 of file Vector2D.cc.

{
x -= v.x;
y -= v.y;
return *this;
}
Vector2D Vector2D::operator/ ( const double  s) const

Definition at line 147 of file Vector2D.cc.

{
Vector2D temp;
temp.x = x / s;
temp.y = y / s;
return temp;
}
Vector2D & Vector2D::operator/= ( const double  s)

Definition at line 116 of file Vector2D.cc.

{
x /= s;
y /= s;
return *this;
}
Vector2D & Vector2D::operator= ( const Vector2D v)

Definition at line 88 of file Vector2D.cc.

{
x = v.x;
y = v.y;
return *this;
}
bool Vector2D::operator== ( const Vector2D v) const

Definition at line 155 of file Vector2D.cc.

{
if(x == v.x && y == v.y)
return true;
else
return false;
}
double Vector2D::xyMaxDistance ( const Vector2D  v) const

Definition at line 57 of file Vector2D.cc.

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

{
return std::max(fabs(x - v.x), fabs(y - v.y));
}

Friends And Related Function Documentation

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

Definition at line 171 of file Vector2D.cc.

{
if(a.y == b.y)
return a.x < b.x;
else
return a.y < b.y;
}
std::ostream& operator<< ( std::ostream &  Stream,
const Vector2D v 
)
friend

Definition at line 179 of file Vector2D.cc.

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

Member Data Documentation


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