Added Keep.ALL to split

This commit is contained in:
gumyr 2025-01-17 10:09:23 -05:00
parent 3b34c50f4e
commit eebd82d06a
3 changed files with 21 additions and 2 deletions

View file

@ -179,11 +179,12 @@ class Intrinsic(Enum):
class Keep(Enum):
"""Split options"""
TOP = auto()
ALL = auto()
BOTTOM = auto()
BOTH = auto()
INSIDE = auto()
OUTSIDE = auto()
BOTH = auto()
TOP = auto()
def __repr__(self):
return f"<{self.__class__.__name__}.{self.name}>"

View file

@ -898,6 +898,10 @@ class Mixin1D(Shape):
) -> Self | list[Self] | None:
"""split and keep inside or outside"""
@overload
def split(self, tool: TrimmingTool, keep: Literal[Keep.ALL]) -> list[Self]:
"""split and return the unordered pieces"""
@overload
def split(self, tool: TrimmingTool, keep: Literal[Keep.BOTH]) -> tuple[
Self | list[Self] | None,
@ -958,6 +962,14 @@ class Mixin1D(Shape):
if isinstance(split_result, TopoDS_Compound):
split_result = unwrap_topods_compound(split_result, True)
# For speed the user may just want all the objects which they
# can sort more efficiently then the generic algoritm below
if keep == Keep.ALL:
return ShapeList(
self.__class__.cast(part)
for part in get_top_level_topods_shapes(split_result)
)
if not isinstance(tool, Plane):
# Get a TopoDS_Face to work with from the tool
if isinstance(trim_tool, TopoDS_Shell):

View file

@ -3248,6 +3248,12 @@ class TestShape(DirectApiTestCase):
outer_vol = 5 * 5
self.assertAlmostEqual(split.volume, outer_vol - inner_vol)
def test_split_keep_all(self):
shape = Box(1, 1, 1)
split_shape = shape.split(Plane.XY, keep=Keep.ALL)
self.assertTrue(isinstance(split_shape, ShapeList))
self.assertEqual(len(split_shape), 2)
def test_split_edge_by_shell(self):
edge = Edge.make_line((-5, 0, 0), (5, 0, 0))
tool = Wire.make_rect(4, 4)