Skip to content
Merged
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",
]
37 changes: 35 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,45 @@ def split(
Split one shape with another.
"""

builder = BRepAlgoAPI_Splitter()
_bool_op(s1, s2, builder, tol)
builder = BOPAlgo_Splitter()
Comment thread
adam-urbanczyk marked this conversation as resolved.
_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.
"""

Comment thread
adam-urbanczyk marked this conversation as resolved.
builder = BOPAlgo_MakerVolume()
# ignore non-intersecting internal faces
builder.SetAvoidInternalShapes(True)
_set_builder_options(builder, tol)

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

builder.Perform()
Comment thread
adam-urbanczyk marked this conversation as resolved.

_update_history(history, name, shapes, builder)

return _compound_or_shape(builder.Shape())


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

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


def test_split():

c = cylinder(2, 10)
p = plane(2, 2).moved(z=1)

res = split(c, p)

assert res.isValid()
assert res.solids().size() == 2


def test_enclose():

c = cylinder(2, 10).face("%CYLINDER")
p1 = plane(3, 3)
p2 = plane(2, 2).moved(z=1)
p3 = plane(0.1, 0.1).moved(z=1.5) # internal face to be ignored

res = enclose(c, p1, p2, p3)

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

res = enclose(c, p1)

assert isinstance(res, Compound)
assert res.size() == 0


def test_imprint():

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