mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 02:30:55 -08:00
Merge 4ffec78728 into a8fc16b344
This commit is contained in:
commit
e0fb09c273
2 changed files with 11 additions and 8 deletions
|
|
@ -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}")
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue