Skip to content

Commit

Permalink
Merge replace_with_multiple into replace
Browse files Browse the repository at this point in the history
Having two different versions of the same method is not justified, in my
opinion:

- The convenience of having a single-replacement special version is so
  minimal, it doesn't justify any additional complexity.
- The minimal win in convenience is more than made up for by the
  inconvenience of a longer name for the general version.

Having a single, general `replace` method is much better.
  • Loading branch information
hannobraun committed Nov 8, 2023
1 parent a77fe73 commit bf66e1e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 33 deletions.
24 changes: 1 addition & 23 deletions crates/fj-core/src/objects/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,7 @@ impl<T> Handles<T> {
///
/// Panics, if the update results in a duplicate item.
#[must_use]
pub fn replace(
&self,
original: &Handle<T>,
replacement: Handle<T>,
) -> Option<Self>
where
T: Debug + Ord,
{
self.replace_with_multiple(original, [replacement])
}

/// Create a new instance in which the provided item has been replaced
///
/// Returns `None`, if the provided item is not present.
///
/// This is a more general version of [`Handles::replace`] which can replace
/// a single item with multiple others.
///
/// # Panics
///
/// Panics, if the replacement results in a duplicate item.
#[must_use]
pub fn replace_with_multiple<const N: usize>(
pub fn replace<const N: usize>(
&self,
original: &Handle<T>,
replacements: [Handle<T>; N],
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/update/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl UpdateCycle for Cycle {
) -> Self {
let edges = self
.half_edges()
.replace(handle, update(handle))
.replace(handle, [update(handle)])
.expect("Half-edge not found");
Cycle::new(edges)
}
Expand All @@ -72,7 +72,7 @@ impl UpdateCycle for Cycle {
) -> Self {
let edges = self
.half_edges()
.replace_with_multiple(handle, replace(handle))
.replace(handle, replace(handle))
.expect("Half-edge not found");
Cycle::new(edges)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/update/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl UpdateRegion for Region {
) -> Self {
let interiors = self
.interiors()
.replace(handle, update(handle))
.replace(handle, [update(handle)])
.expect("Cycle not found");
Region::new(self.exterior().clone(), interiors, self.color())
}
Expand All @@ -87,7 +87,7 @@ impl UpdateRegion for Region {
) -> Self {
let interiors = self
.interiors()
.replace_with_multiple(handle, replace(handle))
.replace(handle, replace(handle))
.expect("Cycle not found");
Region::new(self.exterior().clone(), interiors, self.color())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/update/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl UpdateShell for Shell {
) -> Self {
let faces = self
.faces()
.replace(handle, update(handle))
.replace(handle, [update(handle)])
.expect("Face not found");
Shell::new(faces)
}
Expand All @@ -70,7 +70,7 @@ impl UpdateShell for Shell {
) -> Self {
let faces = self
.faces()
.replace_with_multiple(handle, replace(handle))
.replace(handle, replace(handle))
.expect("Face not found");
Shell::new(faces)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/update/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl UpdateSketch for Sketch {
) -> Self {
let regions = self
.regions()
.replace(handle, update(handle))
.replace(handle, [update(handle)])
.expect("Region not found");
Sketch::new(regions)
}
Expand All @@ -65,7 +65,7 @@ impl UpdateSketch for Sketch {
) -> Self {
let regions = self
.regions()
.replace_with_multiple(handle, replace(handle))
.replace(handle, replace(handle))
.expect("Region not found");
Sketch::new(regions)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/update/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl UpdateSolid for Solid {
) -> Self {
let shells = self
.shells()
.replace(handle, update(handle))
.replace(handle, [update(handle)])
.expect("Shell not found");
Solid::new(shells)
}
Expand All @@ -72,7 +72,7 @@ impl UpdateSolid for Solid {
) -> Self {
let shells = self
.shells()
.replace_with_multiple(handle, replace(handle))
.replace(handle, replace(handle))
.expect("Shell not found");
Solid::new(shells)
}
Expand Down

0 comments on commit bf66e1e

Please sign in to comment.