BWAPI
Public Member Functions | Public Attributes | Friends
Vector Class Reference

#include <Vector.h>

List of all members.

Public Member Functions

 Vector ()
 Vector (const float x, const float y)
 Vector (const int x, const int y)
 Vector (const Vector &v)
 Vector (const Position &p)
 Vector (const TilePosition &p)
 operator Position ()
 operator TilePosition ()
Vectoroperator= (const float scalar)
bool operator== (const Vector &v) const
bool operator!= (const Vector &v) const
Vector operator+ (const Vector &v) const
Vector operator- (const Vector &v) const
Vector operator* (const float &scalar) const
Vector operator* (const Vector &v) const
Vector operator/ (const float &scalar) const
Vector operator/ (const Vector &v) const
Vector operator+ () const
Vector operator- () const
Vectoroperator+= (const Vector &v)
Vectoroperator+= (const float scalar)
Vectoroperator-= (const Vector &v)
Vectoroperator-= (const float scalar)
Vectoroperator*= (const float scalar)
Vectoroperator*= (const Vector &v)
Vectoroperator/= (const float scalar)
Vectoroperator/= (const Vector &v)
float length () const
float squaredLength () const
float distance (const Vector &v) const
float squaredDistance (const Vector &v) const
float dotProduct (const Vector &v) const
float normalise ()
Vector midPoint (const Vector &v) const
bool operator< (const Vector &v) const
bool operator> (const Vector &v) const
void makeFloor (const Vector &v)
void makeCeil (const Vector &v)
Vector perpendicular () const
float crossProduct (const Vector &v) const
Vector randomDeviant (float angle) const
bool isZeroLength () const
Vector normalisedCopy () const
Vector reflect (const Vector &normal) const

Public Attributes

float x
float y

Friends

Vector operator* (const float scalar, const Vector &v)
Vector operator/ (const float scalar, const Vector &v)
Vector operator+ (const Vector &lhs, const float rhs)
Vector operator+ (const float lhs, const Vector &rhs)
Vector operator- (const Vector &lhs, const float rhs)
Vector operator- (const float lhs, const Vector &rhs)

Detailed Description

Definition at line 7 of file Vector.h.


Constructor & Destructor Documentation

Vector::Vector ( ) [inline]

Definition at line 12 of file Vector.h.

Referenced by midPoint(), operator*(), operator+(), operator-(), operator/(), perpendicular(), randomDeviant(), and reflect().

                : x(0), y(0)
        { }

Here is the caller graph for this function:

Vector::Vector ( const float  x,
const float  y 
) [inline]

Definition at line 16 of file Vector.h.

                : x(x), y(y)
        { }
Vector::Vector ( const int  x,
const int  y 
) [inline]

Definition at line 20 of file Vector.h.

                : x(float(x)), y(float(y))
        { }
Vector::Vector ( const Vector v) [inline]

Definition at line 24 of file Vector.h.

                : x(v.x), y(v.y)
        { }
Vector::Vector ( const Position p) [inline]

Definition at line 28 of file Vector.h.

                : x( float(p.x()) ), y( float(p.y()) )
        { }
Vector::Vector ( const TilePosition p) [inline]

Definition at line 32 of file Vector.h.

                : x( float(p.x() * 32) ), y( float(p.y() * 32) )
        { }

Member Function Documentation

float Vector::crossProduct ( const Vector v) const [inline]

Definition at line 274 of file Vector.h.

References x, and y.

        {
                return x * v.y - y * v.x;
        }
float Vector::distance ( const Vector v) const [inline]

Definition at line 208 of file Vector.h.

        {
                return (*this - v).length();
        }
float Vector::dotProduct ( const Vector v) const [inline]

Definition at line 218 of file Vector.h.

References x, and y.

Referenced by TerrainAnaysisClass::findChokePoint(), and reflect().

        {
                return x * v.x + y * v.y;
        }

Here is the caller graph for this function:

bool Vector::isZeroLength ( ) const [inline]

Definition at line 287 of file Vector.h.

References x, and y.

        {
                return (x == 0 && y == 0);
        }
float Vector::length ( ) const [inline]

Definition at line 198 of file Vector.h.

References x, and y.

        {
                return sqrt(x * x + y * y);
        }
void Vector::makeCeil ( const Vector v) [inline]

Definition at line 263 of file Vector.h.

References x, and y.

        {
                if(v.x > x) x = v.x;
                if(v.y > y) y = v.y;
        }
void Vector::makeFloor ( const Vector v) [inline]

Definition at line 257 of file Vector.h.

References x, and y.

        {
                if(v.x < x) x = v.x;
                if(v.y < y) y = v.y;
        }
Vector Vector::midPoint ( const Vector v) const [inline]

Definition at line 236 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector((x + v.x) * 0.5f, (y + v.y ) * 0.5f);
        }

Here is the call graph for this function:

float Vector::normalise ( ) [inline]

Definition at line 223 of file Vector.h.

References x, and y.

Referenced by TerrainAnaysisClass::findChokePoint(), normalisedCopy(), stayAtRange(), PsiStormAction::update(), and WorkerScoutTask::update().

        {
                float iLength = sqrt( x * x + y * y );

                if(iLength > 0)
                {
                        x /= iLength;
                        y /= iLength;
                }

                return iLength;
        }

Here is the caller graph for this function:

Vector Vector::normalisedCopy ( ) const [inline]

Definition at line 292 of file Vector.h.

References normalise().

        {
                Vector ret = *this;
                ret.normalise();
                return ret;
        }

Here is the call graph for this function:

Vector::operator Position ( ) [inline]

Definition at line 36 of file Vector.h.

References x, and y.

        {
                return Position( int(x), int(y) );
        }
Vector::operator TilePosition ( ) [inline]

Definition at line 41 of file Vector.h.

References x, and y.

        {
                return TilePosition( int(x / 32), int(y / 32) );
        }
bool Vector::operator!= ( const Vector v) const [inline]

Definition at line 59 of file Vector.h.

References x, and y.

        {
                return !(x == v.x && y == v.y);
        }
Vector Vector::operator* ( const float &  scalar) const [inline]

Definition at line 74 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector(x * scalar, y * scalar);
        }

Here is the call graph for this function:

Vector Vector::operator* ( const Vector v) const [inline]

Definition at line 79 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector(x * v.x, y * v.y);
        }

Here is the call graph for this function:

Vector& Vector::operator*= ( const float  scalar) [inline]

Definition at line 166 of file Vector.h.

References x, and y.

        {
                x *= scalar;
                y *= scalar;

                return *this;
        }
Vector& Vector::operator*= ( const Vector v) [inline]

Definition at line 174 of file Vector.h.

References x, and y.

        {
                x *= v.x;
                y *= v.y;

                return *this;
        }
Vector Vector::operator+ ( const Vector v) const [inline]

Definition at line 64 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector(x + v.x, y + v.y);
        }

Here is the call graph for this function:

Vector Vector::operator+ ( ) const [inline]

Definition at line 94 of file Vector.h.

        {
                return *this;
        }
Vector& Vector::operator+= ( const Vector v) [inline]

Definition at line 134 of file Vector.h.

References x, and y.

        {
                x += v.x;
                y += v.y;

                return *this;
        }
Vector& Vector::operator+= ( const float  scalar) [inline]

Definition at line 142 of file Vector.h.

References x, and y.

        {
                x += scalar;
                y += scalar;

                return *this;
        }
Vector Vector::operator- ( const Vector v) const [inline]

Definition at line 69 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector(x - v.x, y - v.y);
        }

Here is the call graph for this function:

Vector Vector::operator- ( ) const [inline]

Definition at line 99 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector(-x, -y);
        }

Here is the call graph for this function:

Vector& Vector::operator-= ( const Vector v) [inline]

Definition at line 150 of file Vector.h.

References x, and y.

        {
                x -= v.x;
                y -= v.y;

                return *this;
        }
Vector& Vector::operator-= ( const float  scalar) [inline]

Definition at line 158 of file Vector.h.

References x, and y.

        {
                x -= scalar;
                y -= scalar;

                return *this;
        }
Vector Vector::operator/ ( const float &  scalar) const [inline]

Definition at line 84 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector(x / scalar, y / scalar);
        }

Here is the call graph for this function:

Vector Vector::operator/ ( const Vector v) const [inline]

Definition at line 89 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector(x / v.x, y / v.y);
        }

Here is the call graph for this function:

Vector& Vector::operator/= ( const float  scalar) [inline]

Definition at line 182 of file Vector.h.

References x, and y.

        {
                x /= scalar;
                y /= scalar;

                return *this;
        }
Vector& Vector::operator/= ( const Vector v) [inline]

Definition at line 190 of file Vector.h.

References x, and y.

        {
                x /= v.x;
                y /= v.y;

                return *this;
        }
bool Vector::operator< ( const Vector v) const [inline]

Definition at line 241 of file Vector.h.

References x, and y.

        {
                if(x == v.x)
                        return y < v.y;

                return x < v.x;
        }
Vector& Vector::operator= ( const float  scalar) [inline]

Definition at line 46 of file Vector.h.

References x, and y.

        {
                x = scalar;
                y = scalar;

                return *this;
        }
bool Vector::operator== ( const Vector v) const [inline]

Definition at line 54 of file Vector.h.

References x, and y.

        {
                return (x == v.x && y == v.y);
        }
bool Vector::operator> ( const Vector v) const [inline]

Definition at line 249 of file Vector.h.

References x, and y.

        {
                if(x == v.x)
                        return y > v.y;

                return x > v.x;
        }
Vector Vector::perpendicular ( ) const [inline]

Definition at line 269 of file Vector.h.

References Vector(), x, and y.

        {
                return Vector(-y, x);
        }

Here is the call graph for this function:

Vector Vector::randomDeviant ( float  angle) const [inline]

Definition at line 279 of file Vector.h.

References Vector(), x, and y.

        {
                angle *= (float(rand()) / float(RAND_MAX)) * 3.1415f * 2.0f;
                float cosa = cos(angle);
                float sina = sin(angle);
                return Vector(cosa * x - sina * y, sina * x + cosa * y);
        }

Here is the call graph for this function:

Vector Vector::reflect ( const Vector normal) const [inline]

Definition at line 299 of file Vector.h.

References dotProduct(), and Vector().

        {
                return Vector( *this - ( 2.0f * dotProduct(normal) * normal ) );
        }

Here is the call graph for this function:

float Vector::squaredDistance ( const Vector v) const [inline]

Definition at line 213 of file Vector.h.

        {
                return (*this - v).squaredLength();
        }
float Vector::squaredLength ( ) const [inline]

Definition at line 203 of file Vector.h.

References x, and y.

        {
                return x * x + y * y;
        }

Friends And Related Function Documentation

Vector operator* ( const float  scalar,
const Vector v 
) [friend]

Definition at line 104 of file Vector.h.

        {
                return Vector(scalar * v.x, scalar * v.y);
        }
Vector operator+ ( const Vector lhs,
const float  rhs 
) [friend]

Definition at line 114 of file Vector.h.

        {
                return Vector(lhs.x + rhs, lhs.y + rhs);
        }
Vector operator+ ( const float  lhs,
const Vector rhs 
) [friend]

Definition at line 119 of file Vector.h.

        {
                return Vector(lhs + rhs.x, lhs + rhs.y);
        }
Vector operator- ( const Vector lhs,
const float  rhs 
) [friend]

Definition at line 124 of file Vector.h.

        {
                return Vector(lhs.x - rhs, lhs.y - rhs);
        }
Vector operator- ( const float  lhs,
const Vector rhs 
) [friend]

Definition at line 129 of file Vector.h.

        {
                return Vector(lhs - rhs.x, lhs - rhs.y);
        }
Vector operator/ ( const float  scalar,
const Vector v 
) [friend]

Definition at line 109 of file Vector.h.

        {
                return Vector(scalar / v.x, scalar / v.y);
        }

Member Data Documentation

float Vector::x
float Vector::y

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines