def subtract(shape1, shape2): """Boolean difference of two shapes. Parameters ---------- shape1, shape2 : TopoDS_Shape Surfaces. Returns ------- difference : TopoDS_Shape The set difference :code:`shape1 \ shape2`. Notes ----- The implementation follows the following sources: - https://techoverflow.net/2019/06/14/how-to-fuse-topods_shapes-in-opencascade-boolean-and/ - https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_boolean_fuzzy_cut_emmenthaler.py#L41-L54 For Boolean operations in Open CASCADE, see its `documentation <https://dev.opencascade.org/doc/overview/html/specification__boolean_operations.html>`_. """ arguments = TopTools_ListOfShape() arguments.Append(shape1) tools = TopTools_ListOfShape() tools.Append(shape2) difference = BRepAlgoAPI_Cut() difference.SetTools(tools) difference.SetArguments(arguments) difference.Build() return difference.Shape()
def fuzzy_cut(shape_A, shape_B, tol=5e-5, parallel=False): """ returns shape_A - shape_B """ cut = BRepAlgoAPI_Cut() L1 = TopTools_ListOfShape() L1.Append(shape_A) L2 = TopTools_ListOfShape() L2.Append(shape_B) cut.SetArguments(L1) cut.SetTools(L2) cut.SetFuzzyValue(tol) cut.SetRunParallel(parallel) cut.Build() return cut.Shape()