Tidy geometry and zero_d intersection typing and docstrings.

This commit is contained in:
Jonathan Wagenet 2025-09-16 12:42:47 -04:00
parent d313ebda60
commit 4b8a4e92c1
3 changed files with 60 additions and 48 deletions

View file

@ -527,18 +527,22 @@ class Vector:
@overload
def intersect(self, location: Location) -> Vector | None:
"""Find intersection of location and vector"""
"""Find intersection of vector and location"""
@overload
def intersect(self, axis: Axis) -> Vector | None:
"""Find intersection of axis and vector"""
"""Find intersection of vector and axis"""
@overload
def intersect(self, plane: Plane) -> Vector | None:
"""Find intersection of plane and vector"""
"""Find intersection of vector and plane"""
@overload
def intersect(self, shape: Shape) -> Shape | None:
"""Find intersection of vector and shape"""
def intersect(self, *args, **kwargs):
"""Find intersection of geometric objects and vector"""
"""Find intersection of vector and geometric object or shape"""
axis, plane, vector, location, shape = _parse_intersect_args(*args, **kwargs)
if axis is not None:
@ -906,11 +910,11 @@ class Axis(metaclass=AxisMeta):
@overload
def intersect(self, vector: VectorLike) -> Vector | None:
"""Find intersection of vector and axis"""
"""Find intersection of axis and vector"""
@overload
def intersect(self, location: Location) -> Vector | Location | None:
"""Find intersection of location and axis"""
"""Find intersection of axis and location"""
@overload
def intersect(self, axis: Axis) -> Vector | Axis | None:
@ -918,10 +922,14 @@ class Axis(metaclass=AxisMeta):
@overload
def intersect(self, plane: Plane) -> Vector | Axis | None:
"""Find intersection of plane and axis"""
"""Find intersection of axis and plane"""
@overload
def intersect(self, shape: Shape) -> Shape | None:
"""Find intersection of axis and shape"""
def intersect(self, *args, **kwargs):
"""Find intersection of geometric object and axis"""
"""Find intersection of axis and geometric object or shape"""
axis, plane, vector, location, shape = _parse_intersect_args(*args, **kwargs)
if axis is not None:
@ -1929,7 +1937,7 @@ class Location:
@overload
def intersect(self, vector: VectorLike) -> Vector | None:
"""Find intersection of vector and location"""
"""Find intersection of location and vector"""
@overload
def intersect(self, location: Location) -> Vector | Location | None:
@ -1937,14 +1945,18 @@ class Location:
@overload
def intersect(self, axis: Axis) -> Vector | Location | None:
"""Find intersection of axis and location"""
"""Find intersection of location and axis"""
@overload
def intersect(self, plane: Plane) -> Vector | Location | None:
"""Find intersection of plane and location"""
"""Find intersection of location and plane"""
@overload
def intersect(self, shape: Shape) -> Shape | None:
"""Find intersection of location and shape"""
def intersect(self, *args, **kwargs):
"""Find intersection of geometric object and location"""
"""Find intersection of location and geometric object or shape"""
axis, plane, vector, location, shape = _parse_intersect_args(*args, **kwargs)
if axis is not None:
@ -3131,15 +3143,15 @@ class Plane(metaclass=PlaneMeta):
@overload
def intersect(self, vector: VectorLike) -> Vector | None:
"""Find intersection of vector and plane"""
"""Find intersection of plane and vector"""
@overload
def intersect(self, location: Location) -> Vector | Location | None:
"""Find intersection of location and plane"""
"""Find intersection of plane and location"""
@overload
def intersect(self, axis: Axis) -> Vector | Axis | None:
"""Find intersection of axis and plane"""
"""Find intersection of plane and axis"""
@overload
def intersect(self, plane: Plane) -> Axis | Plane | None:
@ -3150,7 +3162,7 @@ class Plane(metaclass=PlaneMeta):
"""Find intersection of plane and shape"""
def intersect(self, *args, **kwargs):
"""Find intersection of geometric object and shape"""
"""Find intersection of plane and geometric object or shape"""
axis, plane, vector, location, shape = _parse_intersect_args(*args, **kwargs)

View file

@ -1326,7 +1326,7 @@ class Shape(NodeMixin, Generic[TOPODS]):
)
def intersect(
self, *to_intersect: Shape | Axis | Plane
self, *to_intersect: Shape | Vector | Location | Axis | Plane
) -> None | Self | ShapeList[Self]:
"""Intersection of the arguments and this shape

View file

@ -169,41 +169,41 @@ class Vertex(Shape[TopoDS_Vertex]):
raise NotImplementedError("Vertices can't be created by extrusion")
def intersect(
self, *to_intersect: Shape | Vector | Location | Axis | Plane
) -> None | ShapeList[Vertex]:
"""Intersection of the arguments and this shape
self, *to_intersect: Shape | Vector | Location | Axis | Plane
) -> ShapeList[Vertex] | None:
"""Intersection of vertex and geometric objects or shapes.
Args:
to_intersect (sequence of Union[Shape, Axis, Plane]): Shape(s) to
intersect with
Args:
to_intersect (sequence of [Shape | Vector | Location | Axis | Plane]):
Objects(s) to intersect with
Returns:
ShapeList[Shape]: Resulting object may be of a ShapeList of multiple
non-Compound object created
"""
points_sets: list[set] = []
for obj in to_intersect:
# Treat as Vector, otherwise call intersection from Shape
match obj:
case Vertex():
result = Vector(self).intersect(Vector(obj))
case Vector() | Location() | Axis() | Plane():
result = obj.intersect(Vector(self))
case _ if issubclass(type(obj), Shape):
result = obj.intersect(self)
case _:
raise ValueError(f"Unknown object type: {type(obj)}")
Returns:
ShapeList[Vertex] | None: Vertex intersection in a ShapeList or None
"""
points_sets: list[set] = []
result: Shape | ShapeList[Shape] | Vector | None
for obj in to_intersect:
# Treat as Vector, otherwise call intersection from Shape
match obj:
case Vertex():
result = Vector(self).intersect(Vector(obj))
case Vector() | Location() | Axis() | Plane():
result = obj.intersect(Vector(self))
case _ if issubclass(type(obj), Shape):
result = obj.intersect(self)
case _:
raise ValueError(f"Unknown object type: {type(obj)}")
if isinstance(result, Vector):
points_sets.append(set([result]))
else:
points_sets.append(set())
common_points = set.intersection(*points_sets)
if common_points:
return ShapeList([Vertex(p) for p in common_points])
if isinstance(result, Vector):
points_sets.append(set([result]))
else:
return None
points_sets.append(set())
common_points = set.intersection(*points_sets)
if common_points:
return ShapeList([Vertex(p) for p in common_points])
return None
# ---- Instance Methods ----