From 59c5a1f391029402ffce1156c227247ed0f03e9a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 27 Jun 2023 12:57:14 +0200 Subject: [PATCH 1/3] Add `BuildShell::empty` --- crates/fj-core/src/operations/build/shell.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index a40344324..2fdc55442 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -11,6 +11,11 @@ use crate::{ /// Build a [`Shell`] pub trait BuildShell { + /// Build an empty shell + fn empty() -> Shell { + Shell::new([]) + } + /// Build a tetrahedron from the provided points /// /// Accepts 4 points, naturally. For the purposes of the following From 63539c4a5b3366fbdb6786bf4321dce5a384bcb9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 3 Jul 2023 09:15:48 +0200 Subject: [PATCH 2/3] Return `Self` from all update methods This makes no difference for most implementations, but provides more flexibility for implementations of specific wrapper types. Some of the update traits already did this, so this just brings the stragglers in line, making things consistent again. --- crates/fj-core/src/operations/update/cycle.rs | 12 ++++++------ crates/fj-core/src/operations/update/edge.rs | 8 ++++---- crates/fj-core/src/operations/update/shell.rs | 8 ++++---- crates/fj-core/src/operations/update/solid.rs | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index 5315ea684..c2b47f488 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -9,7 +9,7 @@ pub trait UpdateCycle { fn add_half_edges( &self, half_edges: impl IntoIterator>, - ) -> Cycle; + ) -> Self; /// Replace the provided half-edge /// @@ -20,7 +20,7 @@ pub trait UpdateCycle { &self, original: &Handle, replacement: Handle, - ) -> Cycle; + ) -> Self; /// Update the half-edge at the given index /// @@ -31,14 +31,14 @@ pub trait UpdateCycle { &self, index: usize, f: impl FnMut(&Handle) -> Handle, - ) -> Cycle; + ) -> Self; } impl UpdateCycle for Cycle { fn add_half_edges( &self, half_edges: impl IntoIterator>, - ) -> Cycle { + ) -> Self { let half_edges = self.half_edges().cloned().chain(half_edges); Cycle::new(half_edges) } @@ -47,7 +47,7 @@ impl UpdateCycle for Cycle { &self, original: &Handle, replacement: Handle, - ) -> Cycle { + ) -> Self { let mut num_replacements = 0; let half_edges = self.half_edges().map(|half_edge| { @@ -73,7 +73,7 @@ impl UpdateCycle for Cycle { &self, index: usize, mut f: impl FnMut(&Handle) -> Handle, - ) -> Cycle { + ) -> Self { let mut num_replacements = 0; let half_edges = self.half_edges().enumerate().map(|(i, half_edge)| { diff --git a/crates/fj-core/src/operations/update/edge.rs b/crates/fj-core/src/operations/update/edge.rs index 758fd0293..c1def62b4 100644 --- a/crates/fj-core/src/operations/update/edge.rs +++ b/crates/fj-core/src/operations/update/edge.rs @@ -6,14 +6,14 @@ use crate::{ /// Update a [`HalfEdge`] pub trait UpdateHalfEdge { /// Update the start vertex of the half-edge - fn replace_start_vertex(&self, start_vertex: Handle) -> HalfEdge; + fn replace_start_vertex(&self, start_vertex: Handle) -> Self; /// Update the global form of the half-edge - fn replace_global_form(&self, global_form: Handle) -> HalfEdge; + fn replace_global_form(&self, global_form: Handle) -> Self; } impl UpdateHalfEdge for HalfEdge { - fn replace_start_vertex(&self, start_vertex: Handle) -> HalfEdge { + fn replace_start_vertex(&self, start_vertex: Handle) -> Self { HalfEdge::new( self.curve(), self.boundary(), @@ -22,7 +22,7 @@ impl UpdateHalfEdge for HalfEdge { ) } - fn replace_global_form(&self, global_form: Handle) -> HalfEdge { + fn replace_global_form(&self, global_form: Handle) -> Self { HalfEdge::new( self.curve(), self.boundary(), diff --git a/crates/fj-core/src/operations/update/shell.rs b/crates/fj-core/src/operations/update/shell.rs index 3133b2d83..a311ff3eb 100644 --- a/crates/fj-core/src/operations/update/shell.rs +++ b/crates/fj-core/src/operations/update/shell.rs @@ -10,10 +10,10 @@ pub trait UpdateShell { &self, original: &Handle, replacement: Handle, - ) -> Shell; + ) -> Self; /// Remove a face from the shell - fn remove_face(&self, handle: &Handle) -> Shell; + fn remove_face(&self, handle: &Handle) -> Self; } impl UpdateShell for Shell { @@ -21,7 +21,7 @@ impl UpdateShell for Shell { &self, original: &Handle, replacement: Handle, - ) -> Shell { + ) -> Self { let faces = self.faces().into_iter().map(|face| { if face.id() == original.id() { replacement.clone() @@ -33,7 +33,7 @@ impl UpdateShell for Shell { Shell::new(faces) } - fn remove_face(&self, handle: &Handle) -> Shell { + fn remove_face(&self, handle: &Handle) -> Self { let faces = self .faces() .into_iter() diff --git a/crates/fj-core/src/operations/update/solid.rs b/crates/fj-core/src/operations/update/solid.rs index a6135207e..db2979a91 100644 --- a/crates/fj-core/src/operations/update/solid.rs +++ b/crates/fj-core/src/operations/update/solid.rs @@ -9,14 +9,14 @@ pub trait UpdateSolid { fn add_shells( &self, shells: impl IntoIterator>, - ) -> Solid; + ) -> Self; } impl UpdateSolid for Solid { fn add_shells( &self, shells: impl IntoIterator>, - ) -> Solid { + ) -> Self { let shells = self.shells().cloned().chain(shells); Solid::new(shells) } From 2927aa1f2df9a1cdc834c8c71ae182cfa46fd121 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 3 Jul 2023 09:19:24 +0200 Subject: [PATCH 3/3] Add `UpdateShell::add_faces` --- crates/fj-core/src/operations/update/shell.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/fj-core/src/operations/update/shell.rs b/crates/fj-core/src/operations/update/shell.rs index a311ff3eb..8d5291805 100644 --- a/crates/fj-core/src/operations/update/shell.rs +++ b/crates/fj-core/src/operations/update/shell.rs @@ -5,6 +5,9 @@ use crate::{ /// Update a [`Shell`] pub trait UpdateShell { + /// Add faces to the shell + fn add_faces(&self, faces: impl IntoIterator>) -> Self; + /// Update a face of the shell fn replace_face( &self, @@ -17,6 +20,11 @@ pub trait UpdateShell { } impl UpdateShell for Shell { + fn add_faces(&self, faces: impl IntoIterator>) -> Self { + let faces = self.faces().into_iter().cloned().chain(faces); + Shell::new(faces) + } + fn replace_face( &self, original: &Handle,