BWAPI  4.2.0
An API for interacting with Starcraft: Broodwar (1.16.1)
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
BWAPI::Point< T, Scale > Class Template Reference
Inheritance diagram for BWAPI::Point< T, Scale >:
Inheritance graph

Public Types

typedef std::deque< Point< T, Scale > > list

Public Member Functions

 Point ()=default
 Point (T _x, T _y)
template<typename FromT >
 Point (const Point< FromT, Scale > &pt)
template<typename FromT , int FromScale>
 Point (const Point< FromT, FromScale > &pt)
int getApproxDistance (const Point< T, Scale > &position) const
double getDistance (const Point< T, Scale > &position) const
double getLength () const
bool isValid () const
PointmakeValid ()
 operator bool () const
bool operator!= (const Point< T, Scale > &pos) const
Point< T, Scale > operator% (const T &v) const
Point< T, Scale > & operator%= (const T &val)
Point< T, Scale > operator& (const T &v) const
Point< T, Scale > & operator&= (const T &v)
Point< T, Scale > operator* (const T &v) const
Point< T, Scale > & operator*= (const T &v)
Point< T, Scale > operator+ (const Point< T, Scale > &p) const
Point< T, Scale > & operator+= (const Point< T, Scale > &p)
Point< T, Scale > operator- (const Point< T, Scale > &p) const
Point< T, Scale > & operator-= (const Point< T, Scale > &p)
Point< T, Scale > operator/ (const T &v) const
Point< T, Scale > & operator/= (const T &val)
bool operator< (const Point< T, Scale > &position) const
bool operator== (const Point< T, Scale > &pos) const
Point< T, Scale > operator^ (const T &v) const
Point< T, Scale > & operator^= (const T &v)
Point< T, Scale > operator| (const T &v) const
Point< T, Scale > & operator|= (const T &v)
PointsetMax (T max_x, T max_y)
PointsetMax (const Point< T, Scale > &max)
PointsetMin (T min_x, T min_y)
PointsetMin (const Point< T, Scale > &min)

Public Attributes

x = T{}
y = T{}

Friends

std::ostreamoperator<< (std::ostream &os, const Point< T, Scale > &pt)
std::wostreamoperator<< (std::wostream &os, const Point< T, Scale > &pt)
std::istreamoperator>> (std::istream &in, Point< T, Scale > &pt)
std::wistreamoperator>> (std::wistream &in, Point< T, Scale > &pt)

Detailed Description

template<typename T, int Scale>
class BWAPI::Point< T, Scale >

The Point class is a base class that implements convenience members and performs conversions for several different position scales.

It is intended to be inherited or typedef'd for use with BWAPI. Users can extend the Point class, and implement their own members, and it will remain compatible with BWAPI.

Template Parameters
TThe underlying type of the x and y values. BWAPI uses int.
ScaleThe underlying scale that this is intended to be used for. The smaller this value, the higher the precision. A value of 1 indicates the pixel level.

Consider the following:

class VectorPos : publicBWAPI::Point<double, 1> // Same as BWAPI::Position with underlying type double
{
public:
VectorPos(double x_, double y_) : BWAPI::Point<double,1>(x_, y_) {}
// ... whatever members that operate with the underling type double
};

It then follows that this code will work without incident:

BWAPI::Unit myUnit; // assume that the unit is valid and assigned elsewhere
VectorPos myPos{5.7, 8.2};
myUnit->move(myPos); // Automatic type conversion, unit is moved to (5,8)
Note
For full compatibility with BWAPI, T must have a precision of at least 16 bits and Scale must be a factor of 32.

Member Typedef Documentation

typedef std::deque< Point<T,Scale> > BWAPI::Point< T, Scale >::list

Constructor & Destructor Documentation

BWAPI::Point< T, Scale >::Point () default
BWAPI::Point< T, Scale >::Point (T _x, _y )
BWAPI::Point< T, Scale >::Point (const Point< FromT, Scale > & pt)

A copy constructor for positions with different underlying types.

Parameters
ptThe Point to receive data from.
Template Parameters
FromTThe type being converted to type T.

References BWAPI::Point< T, Scale >::Point(), BWAPI::Point< T, Scale >::x, and BWAPI::Point< T, Scale >::y.

BWAPI::Point< T, Scale >::Point (const Point< FromT, FromScale > & pt) explicit

A conversion copy constructor to convert positions of different scales to one another.

Template Parameters
FromTThe type that it is converting from.
FromScaleThe scale that it is converting from.

Member Function Documentation

BWAPI::Point< T, Scale >::operator bool () const explicit

A convenience for use with if statements to identify if a position is valid.

See also
isValid

References BWAPI::Point< T, Scale >::isValid().

bool BWAPI::Point< T, Scale >::operator== (const Point< T, Scale > & pos) const
bool BWAPI::Point< T, Scale >::operator!= (const Point< T, Scale > & pos) const
bool BWAPI::Point< T, Scale >::operator< (const Point< T, Scale > & position) const

A less than operator that enables positions to be used by additional STL containers.

Compares lexicographically the x position, followed by the y position.

References std::tie(), BWAPI::Point< T, Scale >::x, and BWAPI::Point< T, Scale >::y.

Point<T, Scale>& BWAPI::Point< T, Scale >::operator+= (const Point< T, Scale > & p)
Point<T, Scale> BWAPI::Point< T, Scale >::operator+ (const Point< T, Scale > & p) const
Point<T, Scale>& BWAPI::Point< T, Scale >::operator-= (const Point< T, Scale > & p)
Point<T, Scale> BWAPI::Point< T, Scale >::operator- (const Point< T, Scale > & p) const
Point<T, Scale>& BWAPI::Point< T, Scale >::operator*= (const T & v)
Point<T, Scale> BWAPI::Point< T, Scale >::operator* (const T & v) const
Point<T, Scale>& BWAPI::Point< T, Scale >::operator|= (const T & v)
Point<T, Scale> BWAPI::Point< T, Scale >::operator| (const T & v) const
Point<T, Scale>& BWAPI::Point< T, Scale >::operator&= (const T & v)
Point<T, Scale> BWAPI::Point< T, Scale >::operator& (const T & v) const
Point<T, Scale>& BWAPI::Point< T, Scale >::operator^= (const T & v)
Point<T, Scale> BWAPI::Point< T, Scale >::operator^ (const T & v) const
Point<T, Scale> BWAPI::Point< T, Scale >::operator/ (const T & v) const
Point<T, Scale>& BWAPI::Point< T, Scale >::operator/= (const T & val)
Point<T, Scale> BWAPI::Point< T, Scale >::operator% (const T & v) const
Point<T, Scale>& BWAPI::Point< T, Scale >::operator%= (const T & val)
bool BWAPI::Point< T, Scale >::isValid () const

Checks if this point is within the game's map bounds.

Note
If the Broodwar pointer is not initialized, this function will check validity against the largest (256x256) map size.
Return values
trueIf it is a valid position and on the map/playing field.
falseIf this is not a valid position.
See also
makeValid

Referenced by BWAPI::Point< T, Scale >::operator bool().

Point& BWAPI::Point< T, Scale >::makeValid ()

Checks if this point is within the game's map bounds, if not, then it will set the x and y values to be within map bounds.

For example, if x is less than 0, then x is set to 0.

Note
If the Broodwar pointer is not initialized, this function will check validity against the largest (256x256) map size.
Returns
A reference to itself.
See also
isValid
double BWAPI::Point< T, Scale >::getDistance (const Point< T, Scale > & position) const

Gets an accurate distance measurement from this point to the given position.

Note
This is a direct distance calculation that ignores all collision.
This function impedes performance. In most cases you should use getApproxDistance.
Parameters
positionThe target position to get the distance to.
Returns
A double representing the distance between this point and position.
See also
getApproxDistance
double BWAPI::Point< T, Scale >::getLength () const

Gets the length of this point from the top left corner of the map.

Note
This function impedes performance. In most cases you should use getApproxDistance.
Returns
A double representing the length of this point from (0,0).
See also
getApproxDistance

References BWAPI::Point< T, Scale >::x, and BWAPI::Point< T, Scale >::y.

int BWAPI::Point< T, Scale >::getApproxDistance (const Point< T, Scale > & position) const

Retrieves the approximate distance using an algorithm from Starcraft: Broodwar.

Note
This is a direct distance calculation that ignores all collision.
This function is desired because it uses the same "imperfect" algorithm used in Broodwar, so that calculations will be consistent with the game. It is also optimized for performance.
Parameters
positionThe target point to measure the distance to.
Returns
An integer representing the distance between this point and position.
See also
getDistance

References std::swap(), BWAPI::Point< T, Scale >::x, and BWAPI::Point< T, Scale >::y.

Point& BWAPI::Point< T, Scale >::setMax (T max_x, max_y )

Sets the maximum x and y values.

If the current x or y values exceed the given maximum, then values are set to the maximum.

Parameters
max_xMaximum x value.
max_yMaximum y value.
Returns
A reference to itself.
See also
setMin

References BWAPI::Point< T, Scale >::x, and BWAPI::Point< T, Scale >::y.

Referenced by BWAPI::Point< T, Scale >::setMax().

Point& BWAPI::Point< T, Scale >::setMax (const Point< T, Scale > & max)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References BWAPI::Point< T, Scale >::setMax().

Point& BWAPI::Point< T, Scale >::setMin (T min_x, min_y )

Sets the minimum x and y values.

If the current x or y values are below the given minimum, then values are set to the minimum.

Parameters
min_xMinimum x value.
min_yMinimum y value.
Returns
A reference to itself.
See also
setMax

References BWAPI::Point< T, Scale >::x, and BWAPI::Point< T, Scale >::y.

Referenced by BWAPI::Point< T, Scale >::setMin().

Point& BWAPI::Point< T, Scale >::setMin (const Point< T, Scale > & min)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References BWAPI::Point< T, Scale >::setMin().

Friends And Related Function Documentation

std::ostream& operator<< (std::ostreamos, const Point< T, Scale > & pt ) friend

Ouput stream operator overload.

Outputs the Point in the format "(x,y)" without quotations.

Parameters
osOutput stream.
ptPoint to output.
Returns
Output stream out.
std::wostream& operator<< (std::wostreamos, const Point< T, Scale > & pt ) friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

std::istream& operator>> (std::istreamin, Point< T, Scale > & pt ) friend

Input stream operator overload.

Reads the input in the form "x y" without quotations.

The x and y values are read as type T(typically int or float) and stored into pt.

Parameters
inThe input stream.
ptThe receiving variable.
Returns
Input stream in.
std::wistream& operator>> (std::wistreamin, Point< T, Scale > & pt ) friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Member Data Documentation

T BWAPI::Point< T, Scale >::x = T{}
T BWAPI::Point< T, Scale >::y = T{}