Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cadquery/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
chamfer2D,
draft,
History,
enclose,
)

__all__ = [
Expand Down Expand Up @@ -124,4 +125,5 @@
"fillet2D",
"draft",
"History",
"enclose",
]
35 changes: 33 additions & 2 deletions cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@
BOPAlgo_FUSE,
BOPAlgo_CUT,
BOPAlgo_COMMON,
BOPAlgo_MakerVolume,
BOPAlgo_Splitter,
)

from OCP.IFSelect import IFSelect_ReturnStatus
Expand Down Expand Up @@ -6879,14 +6881,43 @@ def split(
Split one shape with another.
"""

builder = BRepAlgoAPI_Splitter()
_bool_op(s1, s2, builder, tol)
builder = BOPAlgo_Splitter()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not really understand the implications of dropping from BRepAlgoAPI_Splitter to BOPAlgo_Splitter, but I did notice that there does not seem to be a test for split() to catch an issue that this might introduce.

_set_builder_options(builder, tol)

builder.AddArgument(s1.wrapped)
builder.AddTool(s2.wrapped)

builder.Perform()

_update_history(history, name, [s1, s2], builder)

return _compound_or_shape(builder.Shape())


def enclose(
*shapes: Shape,
tol: float = 0.0,
history: History | None = None,
name: str | None = None,
) -> Shape:
"""
Build a solid enclosed by the specified faces. Faces can intersect or touch.
If all faces are touching, solid() has better performance.
"""

builder = BOPAlgo_MakerVolume()
_set_builder_options(builder, tol)

for s in shapes:
builder.AddArgument(s.wrapped)

builder.Perform()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if the faces are non-intersecting and non-overlapping (i.e. two separate parallel faces or two crossing planes), you get a Compound of 0 solids and 0 faces back. Should the code raise an error instead of returning an empty result?


_update_history(history, name, shapes, builder)

return Shape.cast(builder.Shape())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the form of this return deviate from the other free function method returns (fuse, cut, split, etc)?

return _compound_or_shape(builder.Shape())



def imprint(
*shapes: Shape,
tol: float = 0.0,
Expand Down
14 changes: 14 additions & 0 deletions tests/test_free_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
_shape_to_faces_shells,
_get_faces,
_combine_hist_dict,
enclose,
)

from OCP.BOPAlgo import BOPAlgo_CheckStatus
Expand Down Expand Up @@ -592,6 +593,19 @@ def test_operators():
assert len(intersect(b1, b3, tol=1e-3).Faces()) == 6


def test_enclose():

c = cylinder(2, 10).face("%CYLINDER")
p1 = plane(3, 3)
p2 = plane(2, 2).moved(z=1)

res = enclose(c, p1, p2)

assert res.isValid()
assert res.ShapeType() == "Solid"
assert res.Volume() == approx(pi)


def test_imprint():

b1 = box(1, 1, 1)
Expand Down