mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 10:41:20 -08:00
Added Keep.ALL to split
This commit is contained in:
parent
3b34c50f4e
commit
eebd82d06a
3 changed files with 21 additions and 2 deletions
|
|
@ -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}>"
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue