diff --git a/crates/opencascade-sys/src/lib.rs b/crates/opencascade-sys/src/lib.rs index 62814356..bf37fdd1 100644 --- a/crates/opencascade-sys/src/lib.rs +++ b/crates/opencascade-sys/src/lib.rs @@ -792,6 +792,7 @@ pub mod ffi { pub fn Shape(self: Pin<&mut BRepAlgoAPI_Common>) -> &TopoDS_Shape; pub fn Build(self: Pin<&mut BRepAlgoAPI_Common>, progress: &Message_ProgressRange); pub fn IsDone(self: &BRepAlgoAPI_Common) -> bool; + pub fn SectionEdges(self: Pin<&mut BRepAlgoAPI_Common>) -> &TopTools_ListOfShape; type BRepAlgoAPI_Section; diff --git a/crates/opencascade/src/primitives/shape.rs b/crates/opencascade/src/primitives/shape.rs index 0cb135fb..dd3e7b6b 100644 --- a/crates/opencascade/src/primitives/shape.rs +++ b/crates/opencascade/src/primitives/shape.rs @@ -479,6 +479,23 @@ impl Shape { BooleanShape { shape, new_edges } } + #[must_use] + pub fn intersect(&self, other: &Shape) -> BooleanShape { + let mut fuse_operation = ffi::BRepAlgoAPI_Common_ctor(&self.inner, &other.inner); + let edge_list = fuse_operation.pin_mut().SectionEdges(); + let vec = ffi::shape_list_to_vector(edge_list); + + let mut new_edges = vec![]; + for shape in vec.iter() { + let edge = ffi::TopoDS_cast_to_edge(shape); + new_edges.push(Edge::from_edge(edge)); + } + + let shape = Self::from_shape(fuse_operation.pin_mut().Shape()); + + BooleanShape { shape, new_edges } + } + pub fn write_stl>(&self, path: P) -> Result<(), Error> { self.write_stl_with_tolerance(path, 0.001) } diff --git a/crates/opencascade/src/primitives/solid.rs b/crates/opencascade/src/primitives/solid.rs index 79400652..1c90d6eb 100644 --- a/crates/opencascade/src/primitives/solid.rs +++ b/crates/opencascade/src/primitives/solid.rs @@ -99,6 +99,26 @@ impl Solid { BooleanShape { shape, new_edges } } + #[must_use] + pub fn intersect(&self, other: &Solid) -> BooleanShape { + let inner_shape = ffi::cast_solid_to_shape(&self.inner); + let other_inner_shape = ffi::cast_solid_to_shape(&other.inner); + + let mut fuse_operation = ffi::BRepAlgoAPI_Common_ctor(inner_shape, other_inner_shape); + let edge_list = fuse_operation.pin_mut().SectionEdges(); + let vec = ffi::shape_list_to_vector(edge_list); + + let mut new_edges = vec![]; + for shape in vec.iter() { + let edge = ffi::TopoDS_cast_to_edge(shape); + new_edges.push(Edge::from_edge(edge)); + } + + let shape = Shape::from_shape(fuse_operation.pin_mut().Shape()); + + BooleanShape { shape, new_edges } + } + /// Purposefully underpowered for now, this simply takes a list of points, /// creates a face out of them, and then extrudes it by h in the positive Z /// direction.