Skip to content

Commit

Permalink
Add UpdateCycle::replace_edge
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 27, 2023
1 parent 7990e85 commit 03be493
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions crates/fj-core/src/operations/update/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ pub trait UpdateCycle {
edge: &Handle<Edge>,
update: impl FnOnce(&Handle<Edge>) -> Handle<Edge>,
) -> 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<const N: usize>(
&self,
edge: &Handle<Edge>,
replace: impl FnOnce(&Handle<Edge>) -> [Handle<Edge>; N],
) -> Self;
}

impl UpdateCycle for Cycle {
Expand All @@ -38,4 +55,13 @@ impl UpdateCycle for Cycle {
let edges = self.edges().update(edge, update);
Cycle::new(edges)
}

fn replace_edge<const N: usize>(
&self,
edge: &Handle<Edge>,
replace: impl FnOnce(&Handle<Edge>) -> [Handle<Edge>; N],
) -> Self {
let edges = self.edges().replace(edge, replace);
Cycle::new(edges)
}
}

0 comments on commit 03be493

Please sign in to comment.