Removing asserts for some Units filter functions
@@ -255,7 +255,8 @@ class Units(list):
:param distance:
:param position:
"""
- assert self, "Units object is empty"
+ if not self:
+ return self
if isinstance(position, Unit):
distance_squared = distance ** 2
return self.subgroup(
@@ -281,7 +282,8 @@ class Units(list):
:param distance:
:param position:
"""
- assert self, "Units object is empty"
+ if not self:
+ return self
if isinstance(position, Unit):
distance_squared = distance ** 2
return self.subgroup(
@@ -310,7 +312,8 @@ class Units(list):
:param distance1:
:param distance2:
"""
- assert self, "Units object is empty"
+ if not self:
+ return self
if isinstance(position, Unit):
distance1_squared = distance1 ** 2
distance2_squared = distance2 ** 2
@@ -339,7 +342,8 @@ class Units(list):
:param position:
:param n:
"""
- assert self, "Units object is empty"
+ if not self:
+ return self
return self.subgroup(self._list_sorted_by_distance_to(position)[:n])
def furthest_n_units(self, position: Union[Unit, Point2, np.ndarray], n: int) -> Units:
@@ -357,7 +361,8 @@ class Units(list):
:param position:
:param n:
"""
- assert self, "Units object is empty"
+ if not self:
+ return self
return self.subgroup(self._list_sorted_by_distance_to(position)[-n:])
def in_distance_of_group(self, other_units: Units, distance: float) -> Units:
