Misc algebra related fixes

This commit is contained in:
Roger Maitland 2023-03-15 16:02:42 -04:00
parent cff6d9ff06
commit 91fb56dcd6
3 changed files with 19 additions and 8 deletions

View file

@ -366,9 +366,11 @@ class LocationList:
@property
def locations(self) -> list[Location]:
"""Current local locations globalized with current workplanes"""
context = WorkplaneList._get_context()
workplanes = context.workplanes if context else [Plane.XY]
global_locations = [
plane.to_location() * local_location
for plane in WorkplaneList._get_context().workplanes
for plane in workplanes
for local_location in self.local_locations
]
return global_locations

View file

@ -1217,20 +1217,29 @@ class Pos(Location):
"""Position by Vertex"""
@overload
def __init__(self, x: float = 0, y: float = 0, z: float = 0):
def __init__(self, X: float = 0, Y: float = 0, Z: float = 0):
"""Position by X, Y, Z"""
def __init__(self, *args):
def __init__(self, *args, **kwargs):
position = [0,0,0]
# VectorLike
if len(args) == 1 and isinstance(args[0], (tuple, Vector)):
super().__init__(args[0])
position = list(args[0])
# Vertex
elif len(args) == 1 and isinstance(args[0], Iterable):
super().__init__(*list(args[0]))
position = list(args[0])
# Values
elif 1 <= len(args) <= 3 and all([isinstance(v, (float, int)) for v in args]):
position = list(args) + [0] * (3 - len(args))
super().__init__(tuple(position))
if "X" in kwargs:
position[0] = kwargs["X"]
if "Y" in kwargs:
position[1] = kwargs["Y"]
if "Z" in kwargs:
position[2] = kwargs["Z"]
super().__init__(tuple(position))
class Rot(Location):

View file

@ -1097,7 +1097,7 @@ class Shape(NodeMixin):
joints: dict[str, Joint] = None,
parent: Compound = None,
children: list[Shape] = None,
is_alg: bool = False,
is_alg: bool = True,
):
self.wrapped = downcast(obj) if obj else None
self.for_construction = False
@ -3263,7 +3263,7 @@ class AlgebraMixin:
f"Cannot combine objects of different dimensionality: {self._dim} and {objs[0]._dim}"
)
if self._dim == 0: # Cover addition of empty BuildPart with another object
if not self.wrapped: # Cover addition of empty BuildPart with another object
if mode == Mode.ADD:
if len(objs) == 1:
compound = copy.deepcopy(objs[0])