Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More boolean ops for Face and CompoundFace #195

Merged
merged 2 commits into from
Jan 19, 2025
Merged
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
56 changes: 56 additions & 0 deletions crates/opencascade/src/primitives/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ impl Face {
CompoundFace::from_compound(compound)
}

#[must_use]
pub fn intersect(&self, other: &Face) -> CompoundFace {
let inner_shape = ffi::cast_face_to_shape(&self.inner);
let other_inner_shape = ffi::cast_face_to_shape(&other.inner);

let mut common_operation = ffi::BRepAlgoAPI_Common_ctor(inner_shape, other_inner_shape);

let common_shape = common_operation.pin_mut().Shape();

let compound = ffi::TopoDS_cast_to_compound(common_shape);

CompoundFace::from_compound(compound)
}

pub fn subtract(&self, other: &Face) -> CompoundFace {
let inner_shape = ffi::cast_face_to_shape(&self.inner);
let other_inner_shape = ffi::cast_face_to_shape(&other.inner);
Expand Down Expand Up @@ -403,6 +417,48 @@ impl CompoundFace {
Shape::from_shape(revolved_shape)
}

#[must_use]
pub fn union(&self, other: &CompoundFace) -> CompoundFace {
let inner_shape = ffi::cast_compound_to_shape(&self.inner);
let other_inner_shape = ffi::cast_compound_to_shape(&other.inner);

let mut fuse_operation = ffi::BRepAlgoAPI_Fuse_ctor(inner_shape, other_inner_shape);

let fuse_shape = fuse_operation.pin_mut().Shape();

let compound = ffi::TopoDS_cast_to_compound(fuse_shape);

CompoundFace::from_compound(compound)
}

#[must_use]
pub fn intersect(&self, other: &CompoundFace) -> CompoundFace {
let inner_shape = ffi::cast_compound_to_shape(&self.inner);
let other_inner_shape = ffi::cast_compound_to_shape(&other.inner);

let mut common_operation = ffi::BRepAlgoAPI_Common_ctor(inner_shape, other_inner_shape);

let common_shape = common_operation.pin_mut().Shape();

let compound = ffi::TopoDS_cast_to_compound(common_shape);

CompoundFace::from_compound(compound)
}

#[must_use]
pub fn subtract(&self, other: &CompoundFace) -> CompoundFace {
let inner_shape = ffi::cast_compound_to_shape(&self.inner);
let other_inner_shape = ffi::cast_compound_to_shape(&other.inner);

let mut fuse_operation = ffi::BRepAlgoAPI_Cut_ctor(inner_shape, other_inner_shape);

let cut_shape = fuse_operation.pin_mut().Shape();

let compound = ffi::TopoDS_cast_to_compound(cut_shape);

CompoundFace::from_compound(compound)
}

pub fn set_global_translation(&mut self, translation: DVec3) {
let shape = ffi::cast_compound_to_shape(&self.inner);
let mut shape = Shape::from_shape(shape);
Expand Down
Loading