This commit is contained in:
Dmytry 2025-11-25 23:53:50 +01:00 committed by GitHub
commit e0fb09c273
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View file

@ -1804,9 +1804,12 @@ class Location:
@overload
def __mul__(self, other: Iterable[Location]) -> list[Location]: ...
@overload
def __mul__(self, other: Iterable[Shape]) -> list[Shape]: ...
def __mul__(
self, other: Shape | Location | Iterable[Location]
) -> Shape | Location | list[Location]:
self, other: Shape | Location | Iterable[Location | Shape | Iterable]
) -> Shape | Location | list[Location] | list[Shape]:
"""Combine locations"""
if self.wrapped is None:
raise ValueError("Cannot move a shape at an empty location")
@ -1841,14 +1844,10 @@ class Location:
raise ValueError("Can't multiply by empty location")
return Location(self.wrapped * other.wrapped)
# other is a list of Locations
# other is a list
if isinstance(other, Iterable):
others = list(other)
if not all(isinstance(o, Location) for o in others):
raise ValueError("other must be a list of Locations")
if any(o.wrapped is None for o in others):
raise ValueError("Can't multiple by empty Locations")
return [Location(self.wrapped * loc.wrapped) for loc in others]
return [self * loc for loc in others]
raise ValueError(f"Invalid input {other}")

View file

@ -795,6 +795,10 @@ class AlgebraTests(unittest.TestCase):
class LocationTests(unittest.TestCase):
def test_list_mul(self):
a = Rot(45) * (GridLocations(10, 10, 2, 2) * Cylinder(2, 3))
self.assertEqual(len(a), 4)
def test_wheel(self):
plane = Plane.ZX