From 03be493579b740df9c0d6de7f95f5baab93ad1a8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 27 Sep 2023 11:13:57 +0200 Subject: [PATCH] Add `UpdateCycle::replace_edge` --- crates/fj-core/src/operations/update/cycle.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index 3a67bf54b..ba34205e4 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -22,6 +22,23 @@ pub trait UpdateCycle { edge: &Handle, update: impl FnOnce(&Handle) -> Handle, ) -> Self; + + /// Replace the provided edge + /// + /// This is a more general version of [`UpdateCycle::update_edge`] which can + /// replace a single edge with multiple others. + /// + /// # Panics + /// + /// Uses [`Handles::update`] internally, and panics for the same reasons. + /// + /// [`Handles::update`]: crate::objects::Handles::update + #[must_use] + fn replace_edge( + &self, + edge: &Handle, + replace: impl FnOnce(&Handle) -> [Handle; N], + ) -> Self; } impl UpdateCycle for Cycle { @@ -38,4 +55,13 @@ impl UpdateCycle for Cycle { let edges = self.edges().update(edge, update); Cycle::new(edges) } + + fn replace_edge( + &self, + edge: &Handle, + replace: impl FnOnce(&Handle) -> [Handle; N], + ) -> Self { + let edges = self.edges().replace(edge, replace); + Cycle::new(edges) + } }