position.py#

class sc2.position.Pointlike(iterable=(), /)[source]#
closest(ps: Iterable[_TPosLike]) _TPosLike[source]#

This function assumes the 2d distance is meant

Parameters:

ps (Iterable[TypeVar(_TPosLike, bound= Union[HasPosition2D, tuple[float, float], tuple[float, ...]])])

Return type:

TypeVar(_TPosLike, bound= Union[HasPosition2D, tuple[float, float], tuple[float, ...]])

distance_to(target: HasPosition2D | tuple[float, float] | tuple[float, ...]) float[source]#

Calculate a single distance from a point or unit to another point or unit

Parameters:

target (Union[HasPosition2D, tuple[float, float], tuple[float, ...]])

Return type:

float

distance_to_closest(ps: Iterable[_TPosLike]) float[source]#

This function assumes the 2d distance is meant :type ps: Iterable[TypeVar(_TPosLike, bound= Union[HasPosition2D, tuple[float, float], tuple[float, ...]])] :param ps:

Return type:

float

distance_to_furthest(ps: Iterable[HasPosition2D | tuple[float, float] | tuple[float, ...]]) float[source]#

This function assumes the 2d distance is meant

Parameters:

ps (Iterable[Union[HasPosition2D, tuple[float, float], tuple[float, ...]]])

Return type:

float

distance_to_point2(p: tuple[float, float] | tuple[float, ...]) float[source]#

Same as the function above, but should be a bit faster because of the dropped asserts and conversion.

Parameters:

p (Union[tuple[float, float], tuple[float, ...]])

Return type:

float

furthest(ps: Iterable[_TPosLike]) _TPosLike[source]#

This function assumes the 2d distance is meant

Parameters:

ps (Iterable[TypeVar(_TPosLike, bound= Union[HasPosition2D, tuple[float, float], tuple[float, ...]])]) – Units object, or iterable of Unit or Point2

Return type:

TypeVar(_TPosLike, bound= Union[HasPosition2D, tuple[float, float], tuple[float, ...]])

offset(p: _PointLike) T[source]#
Parameters:
  • p (_PointLike)

  • self (T)

Return type:

T

sort_by_distance(ps: Iterable[_TPosLike]) list[_TPosLike][source]#

This returns the target points sorted as list. You should not pass a set or dict since those are not sortable. If you want to sort your units towards a point, use ‘units.sorted_by_distance_to(point)’ instead.

Parameters:

ps (Iterable[TypeVar(_TPosLike, bound= Union[HasPosition2D, tuple[float, float], tuple[float, ...]])])

Return type:

list[TypeVar(_TPosLike, bound= Union[HasPosition2D, tuple[float, float], tuple[float, ...]])]

towards(p: _PosLike, distance: float = 1, limit: bool = False) T[source]#
Parameters:
  • p (_PosLike)

  • distance (float)

  • limit (bool)

  • self (T)

Return type:

T

unit_axes_towards(p: _PointLike) T[source]#
Parameters:
  • p (_PointLike)

  • self (T)

Return type:

T

class sc2.position.Point2(iterable=(), /)[source]#
property as_PointI: PointI#

Represents points on the minimap. Values must be between 0 and 64.

static center(points: list[Point2]) Point2[source]#

Returns the central point for points in list

Parameters:

points (list[Point2])

Return type:

Point2

circle_intersection(p: Point2, r: float) set[Point2][source]#

self is point1, p is point2, r is the radius for circles originating in both points Used in ramp finding

Parameters:
Return type:

set[Point2]

direction_vector(other: Point2) Point2[source]#

Converts a vector to a direction that can face vertically, horizontally or diagonal or be zero, e.g. (0, 0), (1, -1), (1, 0)

Parameters:

other (Point2)

Return type:

Point2

classmethod from_proto(data: Point | Point2D | Size2DI | PointI | Point2 | Point3) Point2[source]#
Parameters:

data (Point | Point2D | Size2DI | PointI | Point2 | Point3)

Return type:

Point2

property length: float#

This property exists in case Point2 is used as a vector.

manhattan_distance(other: Point2) float[source]#
Parameters:

other (Point2)

Return type:

float

property normalized: Point2#

This property exists in case Point2 is used as a vector.

Parameters:

self (Point2 | Point3)

offset(p: _PointLike) T[source]#
Parameters:
  • p (_PointLike)

  • self (T)

Return type:

T

round(decimals: int) Point2[source]#

Rounds each number in the tuple to the amount of given decimals.

Parameters:

decimals (int)

Return type:

Point2

class sc2.position.Point3(iterable=(), /)[source]#
classmethod from_proto(data: Point | Point3) Point3[source]#
Parameters:

data (Point | Point3)

Return type:

Point3

class sc2.position.Size(iterable=(), /)[source]#
classmethod from_proto(data: Point | Point2D | Size2DI | PointI | Point2) Size[source]#
Parameters:

data (Point | Point2D | Size2DI | PointI | Point2)

Return type:

Size

class sc2.position.Rect(iterable=(), /)[source]#
property center: Point2#

Returns the central point for points in list

Parameters:

points

classmethod from_proto(data: RectangleI) Rect[source]#
Parameters:

data (RectangleI)

Return type:

Rect

offset(p: tuple[float, float] | tuple[float, ...]) Rect[source]#
Parameters:

p (Union[tuple[float, float], tuple[float, ...]])

Return type:

Rect

property right: float#

Returns the x-coordinate of the rectangle of its right side.

property top: float#

Returns the y-coordinate of the rectangle of its top side.