Skip to content

Commit

Permalink
Fix minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnySc2 authored and aiseeq committed Oct 3, 2018
1 parent ad54022 commit 7993697
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sc2/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def _distance_squared(self, p2: "Point2") -> Union[int, float]:
""" Function used to not take the square root as the distances will stay proportionally the same. This is to speed up the sorting process. """
return ((self[0]-p2[0])**2 + (self[1]-p2[1])**2)

def sort_by_distance(self, ps: Union["Units", List["Point2"]]):
""" This returns the target points sorted. You should not pass a set or dict since those are not sortable. """
def sort_by_distance(self, ps: Union["Units", List["Point2"]]) -> List["Point2"]:
""" 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. """
if ps and all(isinstance(p, Point2) for p in ps):
return sorted(ps, key=lambda p: self._distance_squared(p))
return sorted(ps, key=lambda p: self.distance_to(p))
Expand Down Expand Up @@ -71,7 +72,7 @@ def distance_to_closest(self, ps: Union["Units", List["Point2"], Set["Point2"]])
def furthest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union["Unit", "Pointlike"]:
""" This function assumes the 2d distance is meant """
assert len(ps) > 0
furthest_distance_squared = 0
furthest_distance_squared = -math.inf
for p2 in ps:
p2pos = p2
if not isinstance(p2pos, Point2):
Expand All @@ -85,7 +86,7 @@ def furthest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union["
def distance_to_furthest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union[int, float]:
""" This function assumes the 2d distance is meant """
assert len(ps) > 0
furthest_distance_squared = 0
furthest_distance_squared = -math.inf
for p2 in ps:
if not isinstance(p2, Point2):
p2 = p2.position
Expand All @@ -101,6 +102,7 @@ def unit_axes_towards(self, p):
return self.__class__(_sign(b - a) for a, b in itertools.zip_longest(self, p[:len(self)], fillvalue=0))

def towards(self, p: Union["Unit", "Pointlike"], distance: Union[int, float]=1, limit: bool=False) -> "Pointlike":
p = p.position
assert self != p
d = self.distance_to(p)
if limit:
Expand Down

0 comments on commit 7993697

Please sign in to comment.