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

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

Template parameters
T The underlying type of the x and y values. BWAPI uses int.
Scale The 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.

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.

Consider the following:

class VectorPos : public BWAPI::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)

Public types

using list = std::deque<Point<T, Scale>>

Constructors, destructors, conversion operators

Point() defaulted
template<typename FromT, int FromScale>
Point(const Point<FromT, FromScale>& pt) explicit
A conversion copy constructor to convert positions of different scales to one another.
template<typename FromT>
Point(const Point<FromT, Scale>& pt)
A copy constructor for positions with different underlying types.
Point(T _x, T _y)

Public functions

auto getApproxDistance(const Point<T, Scale>& position) const -> int
Retrieves the approximate distance using an algorithm from Starcraft: Broodwar.
auto getDistance(const Point<T, Scale>& position) const -> double
Gets an accurate distance measurement from this point to the given position.
auto getLength() const -> double
Gets the length of this point from the top left corner of the map.
auto operator!=(const Point<T, Scale>& pos) const -> bool
auto operator%(const T& v) const -> Point<T, Scale>
auto operator%=(const T& val) -> Point<T, Scale>&
auto operator&(const T& v) const -> Point<T, Scale>
auto operator&=(const T& v) -> Point<T, Scale>&
auto operator*(const T& v) const -> Point<T, Scale>
auto operator*=(const T& v) -> Point<T, Scale>&
auto operator+(const Point<T, Scale>& p) const -> Point<T, Scale>
auto operator+=(const Point<T, Scale>& p) -> Point<T, Scale>&
auto operator-(const Point<T, Scale>& p) const -> Point<T, Scale>
auto operator-=(const Point<T, Scale>& p) -> Point<T, Scale>&
auto operator/(const T& v) const -> Point<T, Scale>
auto operator/=(const T& val) -> Point<T, Scale>&
auto operator<(const Point<T, Scale>& position) const -> bool
A less than operator that enables positions to be used by additional STL containers.
auto operator==(const Point<T, Scale>& pos) const -> bool
auto operator^(const T& v) const -> Point<T, Scale>
auto operator^=(const T& v) -> Point<T, Scale>&
auto operator|(const T& v) const -> Point<T, Scale>
auto operator|=(const T& v) -> Point<T, Scale>&
auto setMax(const Point<T, Scale>& max) -> Point&
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
auto setMax(T max_x, T max_y) -> Point&
Sets the maximum x and y values.
auto setMin(const Point<T, Scale>& min) -> Point&
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
auto setMin(T min_x, T min_y) -> Point&
Sets the minimum x and y values.

Public variables

T x
The x and y members for this class.
T y

Friends

auto operator<<(std::ostream& os, const Point<T, Scale>& pt) -> std::ostream&
Ouput stream operator overload.
auto operator<<(std::wostream& os, const Point<T, Scale>& pt) -> std::wostream&
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
auto operator>>(std::istream& in, Point<T, Scale>& pt) -> std::istream&
Input stream operator overload.
auto operator>>(std::wistream& in, Point<T, Scale>& pt) -> std::wistream&
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Function documentation

template<typename T, int Scale> template<typename FromT, int FromScale>
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
FromT The type that it is converting from.
FromScale The scale that it is converting from.

template<typename T, int Scale> template<typename FromT>
BWAPI::Point<T, Scale>::Point(const Point<FromT, Scale>& pt)

A copy constructor for positions with different underlying types.

Template parameters
FromT The type being converted to type T.
Parameters
pt The Point to receive data from.

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

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

Parameters
position The target point to measure the distance to.
Returns An integer representing the distance between this point and position.

template<typename T, int Scale>
double BWAPI::Point<T, Scale>::getDistance(const Point<T, Scale>& position) const

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

Parameters
position The target position to get the distance to.
Returns A double representing the distance between this point and position.

template<typename T, int Scale>
double BWAPI::Point<T, Scale>::getLength() const

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

Returns A double representing the length of this point from (0,0).

template<typename T, int Scale>
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.

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

Sets the maximum x and y values.

Parameters
max_x Maximum x value.
max_y Maximum y value.
Returns A reference to itself.

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

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

Sets the minimum x and y values.

Parameters
min_x Minimum x value.
min_y Minimum y value.
Returns A reference to itself.

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

template<typename T, int Scale>
std::ostream& operator<<(std::ostream& os, const Point<T, Scale>& pt)

Ouput stream operator overload.

Parameters
os Output stream.
pt Point to output.
Returns Output stream out.

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

template<typename T, int Scale>
std::istream& operator>>(std::istream& in, Point<T, Scale>& pt)

Input stream operator overload.

Parameters
in The input stream.
pt The receiving variable.
Returns Input stream in.

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.

Variable documentation

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

The x and y members for this class.

Simply reference these members when retrieving a position's x and y values.