Skip to content

Commit

Permalink
Re-add the intersect function (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
bschwind authored Nov 23, 2023
1 parent 0adabcb commit 46767f6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/opencascade-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 17 additions & 0 deletions crates/opencascade/src/primitives/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: AsRef<Path>>(&self, path: P) -> Result<(), Error> {
self.write_stl_with_tolerance(path, 0.001)
}
Expand Down
20 changes: 20 additions & 0 deletions crates/opencascade/src/primitives/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 46767f6

Please sign in to comment.