ProtoBot
Loading...
Searching...
No Matches
VectorPos Class Reference

Custom Vector class that extends from BWAPI::Point, with added vector operations and functions. More...

#include <VectorPos.h>

Inheritance diagram for VectorPos:

Public Member Functions

 VectorPos (int _x, int _y)
 VectorPos (double _x, double _y)
 VectorPos (BWAPI::Position pos)
VectorPos normalized ()
 Uses L^2 normalization

Returns
Normalized VectorPos object

.

double dot (VectorPos other)
 Returns dot product of this vector and another vector.
double getSqDistance ()
 Returns squared distance of vector from origin (0, 0). Used for performance optimization instead of getLength() since sqrt is expensive and we only need to compare distances, not get the actual distance.
VectorPosoperator= (const VectorPos &other) noexcept(true)
VectorPosoperator= (const BWAPI::Point< int, 1 > other) noexcept(true)
VectorPosoperator= (const BWAPI::Point< double, 1 > other) noexcept(true)
VectorPos operator- (const VectorPos &rhs) const
VectorPos operator+ (const VectorPos &rhs) const
VectorPos operator* (const double &scalar) const
VectorPos operator/ (const double &scalar) const
bool operator== (const VectorPos &rhs) const
bool operator!= (const VectorPos &rhs) const
std::ostream & operator<< (std::ostream &out)

Detailed Description

Custom Vector class that extends from BWAPI::Point, with added vector operations and functions.

Since standard position classes such as BWAPI::Position and BWAPI::TilePosition automatically round values to integers, there is a loss of precision for vector calculations.
Extends from BWAPI::Point using a double template to allow for more precise calculations

Definition at line 10 of file VectorPos.h.

Constructor & Destructor Documentation

◆ VectorPos() [1/4]

VectorPos::VectorPos ( int _x,
int _y )
inline

Definition at line 12 of file VectorPos.h.

12 {
13 this->x = _x;
14 this->y = _y;
15 };

◆ VectorPos() [2/4]

VectorPos::VectorPos ( double _x,
double _y )
inline

Definition at line 16 of file VectorPos.h.

16 {
17 this->x = _x;
18 this->y = _y;
19 };

◆ VectorPos() [3/4]

VectorPos::VectorPos ( BWAPI::Position pos)
inline

Definition at line 21 of file VectorPos.h.

21 {
22 this->x = pos.x;
23 this->y = pos.y;
24 };

◆ VectorPos() [4/4]

VectorPos::VectorPos ( )
inline

Definition at line 26 of file VectorPos.h.

26 {
27 this->x = 0.0;
28 this->y = 0.0;
29 };

Member Function Documentation

◆ dot()

double VectorPos::dot ( VectorPos other)
inline

Returns dot product of this vector and another vector.

Parameters
otherOther VectorPos object
Returns
Dot product

Definition at line 50 of file VectorPos.h.

50 {
51 return this->x * other.x + this->y * other.y;
52 }

◆ getSqDistance()

double VectorPos::getSqDistance ( )
inline

Returns squared distance of vector from origin (0, 0). Used for performance optimization instead of getLength() since sqrt is expensive and we only need to compare distances, not get the actual distance.

Returns
Squared distance between vector and origin (0, 0).

Definition at line 58 of file VectorPos.h.

58 {
59 return pow(this->x, 2) + pow(this->y, 2);
60 }

◆ normalized()

VectorPos VectorPos::normalized ( )
inline

Uses L^2 normalization

Returns
Normalized VectorPos object

.

Definition at line 34 of file VectorPos.h.

34 {
35 // Using squared distance to save performance instead of using sqrt
36 const double mag = this->getLength();
37
38 if (mag == 0) {
39 return VectorPos(0, 0);
40 }
41
42 return VectorPos(this->x, this->y) / mag;
43 }

◆ operator!=()

bool VectorPos::operator!= ( const VectorPos & rhs) const
inline

Definition at line 93 of file VectorPos.h.

93 {
94 return !(this->x == rhs.x && this->y == rhs.y);
95 }

◆ operator*()

VectorPos VectorPos::operator* ( const double & scalar) const
inline

Definition at line 84 of file VectorPos.h.

84 {
85 return VectorPos(this->x * scalar, this->y * scalar);
86 }

◆ operator+()

VectorPos VectorPos::operator+ ( const VectorPos & rhs) const
inline

Definition at line 81 of file VectorPos.h.

81 {
82 return VectorPos(this->x + rhs.x, this->y + rhs.y);
83 }

◆ operator-()

VectorPos VectorPos::operator- ( const VectorPos & rhs) const
inline

Definition at line 78 of file VectorPos.h.

78 {
79 return VectorPos(this->x - rhs.x, this->y - rhs.y);
80 }

◆ operator/()

VectorPos VectorPos::operator/ ( const double & scalar) const
inline

Definition at line 87 of file VectorPos.h.

87 {
88 return VectorPos(this->x / scalar, this->y / scalar);
89 }

◆ operator<<()

std::ostream & VectorPos::operator<< ( std::ostream & out)
inline

Definition at line 97 of file VectorPos.h.

97 {
98 out << "VectorPos(" << this->x << ", " << this->y << ")";
99 return out; // Enable chaining
100 }

◆ operator=() [1/3]

VectorPos & VectorPos::operator= ( const BWAPI::Point< double, 1 > other)
inlinenoexcept

Definition at line 72 of file VectorPos.h.

72 {
73 this->x = other.x;
74 this->y = other.y;
75 return *this;
76 }

◆ operator=() [2/3]

VectorPos & VectorPos::operator= ( const BWAPI::Point< int, 1 > other)
inlinenoexcept

Definition at line 67 of file VectorPos.h.

67 {
68 this->x = other.x;
69 this->y = other.y;
70 return *this;
71 }

◆ operator=() [3/3]

VectorPos & VectorPos::operator= ( const VectorPos & other)
inlinenoexcept

Definition at line 62 of file VectorPos.h.

62 {
63 this->x = other.x;
64 this->y = other.y;
65 return *this;
66 }

◆ operator==()

bool VectorPos::operator== ( const VectorPos & rhs) const
inline

Definition at line 90 of file VectorPos.h.

90 {
91 return this->x == rhs.x && this->y == rhs.y;
92 }

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