Skip to content

Commit

Permalink
Merge pull request #1891 from hannobraun/operations
Browse files Browse the repository at this point in the history
Add `Merge` operation
  • Loading branch information
hannobraun authored Jun 19, 2023
2 parents 4232b5a + ba3c26e commit 1d233e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/build/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait BuildSolid {
services: &mut Services,
) -> Tetrahedron {
let shell = Shell::tetrahedron(points, services).insert(services);
let solid = Solid::empty().add_shell(shell.shell.clone());
let solid = Solid::empty().add_shells([shell.shell.clone()]);

Tetrahedron { solid, shell }
}
Expand Down
15 changes: 15 additions & 0 deletions crates/fj-core/src/operations/merge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::objects::Solid;

use super::UpdateSolid;

/// Merge two [`Solid`]s
pub trait Merge {
/// Merge this solid with another
fn merge(&self, other: &Self) -> Self;
}

impl Merge for Solid {
fn merge(&self, other: &Self) -> Self {
self.add_shells(other.shells().cloned())
}
}
2 changes: 2 additions & 0 deletions crates/fj-core/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod build;
mod insert;
mod join;
mod merge;
mod reverse;
mod update;

Expand All @@ -19,6 +20,7 @@ pub use self::{
},
insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes},
join::cycle::JoinCycle,
merge::Merge,
reverse::Reverse,
update::{
cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace,
Expand Down
12 changes: 9 additions & 3 deletions crates/fj-core/src/operations/update/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ use crate::{
/// Update a [`Solid`]
pub trait UpdateSolid {
/// Add a shell to the solid
fn add_shell(&self, shell: Handle<Shell>) -> Solid;
fn add_shells(
&self,
shells: impl IntoIterator<Item = Handle<Shell>>,
) -> Solid;
}

impl UpdateSolid for Solid {
fn add_shell(&self, shell: Handle<Shell>) -> Solid {
let shells = self.shells().cloned().chain([shell]);
fn add_shells(
&self,
shells: impl IntoIterator<Item = Handle<Shell>>,
) -> Solid {
let shells = self.shells().cloned().chain(shells);
Solid::new(shells)
}
}

0 comments on commit 1d233e7

Please sign in to comment.