From 835bafb082fde6303a845343d99496d0da5edffe Mon Sep 17 00:00:00 2001 From: adam-urbanczyk <13981538+adam-urbanczyk@users.noreply.github.com> Date: Sun, 5 Jul 2026 14:35:27 +0200 Subject: [PATCH 1/2] Add enclose --- cadquery/occ_impl/shapes.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 86af4afe9..073d1df41 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -266,6 +266,8 @@ BOPAlgo_FUSE, BOPAlgo_CUT, BOPAlgo_COMMON, + BOPAlgo_MakerVolume, + BOPAlgo_Splitter, ) from OCP.IFSelect import IFSelect_ReturnStatus @@ -6879,14 +6881,43 @@ def split( Split one shape with another. """ - builder = BRepAlgoAPI_Splitter() - _bool_op(s1, s2, builder, tol) + builder = BOPAlgo_Splitter() + _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() + + _update_history(history, name, shapes, builder) + + return Shape.cast(builder.Shape()) + + def imprint( *shapes: Shape, tol: float = 0.0, From 9b1e7b4651cfa8404e0ec443f1e305ba4e413a37 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk <13981538+adam-urbanczyk@users.noreply.github.com> Date: Wed, 8 Jul 2026 08:19:10 +0200 Subject: [PATCH 2/2] Add test and expose enclose --- cadquery/func.py | 2 ++ tests/test_free_functions.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cadquery/func.py b/cadquery/func.py index 949bc809b..3e7d929ed 100644 --- a/cadquery/func.py +++ b/cadquery/func.py @@ -59,6 +59,7 @@ chamfer2D, draft, History, + enclose, ) __all__ = [ @@ -124,4 +125,5 @@ "fillet2D", "draft", "History", + "enclose", ] diff --git a/tests/test_free_functions.py b/tests/test_free_functions.py index 958363254..bbeaec911 100644 --- a/tests/test_free_functions.py +++ b/tests/test_free_functions.py @@ -66,6 +66,7 @@ _shape_to_faces_shells, _get_faces, _combine_hist_dict, + enclose, ) from OCP.BOPAlgo import BOPAlgo_CheckStatus @@ -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)