Conform Shape.intersect to None | ShapeList

This commit is contained in:
Jonathan Wagenet 2025-10-28 23:56:29 -04:00
parent 315605f485
commit 069b691964

View file

@ -1327,7 +1327,7 @@ class Shape(NodeMixin, Generic[TOPODS]):
def intersect( def intersect(
self, *to_intersect: Shape | Vector | Location | Axis | Plane self, *to_intersect: Shape | Vector | Location | Axis | Plane
) -> None | Self | ShapeList[Self]: ) -> None | ShapeList[Self]:
"""Intersection of the arguments and this shape """Intersection of the arguments and this shape
Args: Args:
@ -1335,8 +1335,8 @@ class Shape(NodeMixin, Generic[TOPODS]):
intersect with intersect with
Returns: Returns:
Self | ShapeList[Self]: Resulting object may be of a different class than self None | ShapeList[Self]: Resulting ShapeList may contain different class
or a ShapeList if multiple non-Compound object created than self
""" """
def _to_vertex(vec: Vector) -> Vertex: def _to_vertex(vec: Vector) -> Vertex:
@ -1380,15 +1380,12 @@ class Shape(NodeMixin, Generic[TOPODS]):
# Find the shape intersections # Find the shape intersections
intersect_op = BRepAlgoAPI_Common() intersect_op = BRepAlgoAPI_Common()
shape_intersections = self._bool_op((self,), objs, intersect_op) intersections = self._bool_op((self,), objs, intersect_op)
if isinstance(shape_intersections, ShapeList) and not shape_intersections: if isinstance(intersections, ShapeList):
return None return intersections or None
if ( if isinstance(intersections, Shape) and not intersections.is_null:
not isinstance(shape_intersections, ShapeList) return ShapeList([intersections])
and shape_intersections.is_null return None
):
return None
return shape_intersections
def is_equal(self, other: Shape) -> bool: def is_equal(self, other: Shape) -> bool:
"""Returns True if two shapes are equal, i.e. if they share the same """Returns True if two shapes are equal, i.e. if they share the same