Skip to content

Commit

Permalink
Merge update_shell and replace_shell
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Feb 9, 2024
1 parent 4c66edb commit 9d27be1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 39 deletions.
39 changes: 5 additions & 34 deletions crates/fj-core/src/operations/update/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,10 @@ pub trait UpdateSolid {
///
/// Panics, if the update results in a duplicate object.
#[must_use]
fn update_shell(
fn update_shell<const N: usize>(
&self,
handle: &Handle<Shell>,
update: impl FnOnce(&Handle<Shell>) -> Handle<Shell>,
) -> Self;

/// Replace a shell of the solid
///
/// This is a more general version of [`UpdateSolid::update_shell`] which
/// can replace a single edge with multiple others.
///
/// # Panics
///
/// Panics, if the object can't be found.
///
/// Panics, if the update results in a duplicate object.
#[must_use]
fn replace_shell<const N: usize>(
&self,
handle: &Handle<Shell>,
replace: impl FnOnce(&Handle<Shell>) -> [Handle<Shell>; N],
update: impl FnOnce(&Handle<Shell>) -> [Handle<Shell>; N],
) -> Self;
}

Expand All @@ -53,26 +36,14 @@ impl UpdateSolid for Solid {
Solid::new(shells)
}

fn update_shell(
&self,
handle: &Handle<Shell>,
update: impl FnOnce(&Handle<Shell>) -> Handle<Shell>,
) -> Self {
let shells = self
.shells()
.replace(handle, [update(handle)])
.expect("Shell not found");
Solid::new(shells)
}

fn replace_shell<const N: usize>(
fn update_shell<const N: usize>(
&self,
handle: &Handle<Shell>,
replace: impl FnOnce(&Handle<Shell>) -> [Handle<Shell>; N],
update: impl FnOnce(&Handle<Shell>) -> [Handle<Shell>; N],
) -> Self {
let shells = self
.shells()
.replace(handle, replace(handle))
.replace(handle, update(handle))
.expect("Shell not found");
Solid::new(shells)
}
Expand Down
2 changes: 1 addition & 1 deletion models/color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ pub fn model(core: &mut fj::core::Instance) -> Solid {
shell
};

shell.insert(&mut core.services)
[shell.insert(&mut core.services)]
})
}
4 changes: 2 additions & 2 deletions models/holes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn model(
.nth(5)
.expect("Expected shell to have top face");

shell
[shell
.add_through_hole(
[
HoleLocation {
Expand All @@ -55,6 +55,6 @@ pub fn model(
radius,
core,
)
.insert(&mut core.services)
.insert(&mut core.services)]
})
}
4 changes: 2 additions & 2 deletions models/split/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub fn model(

let (shell, [face, _]) = shell.split_face(face, line, core);

shell
[shell
.sweep_face_of_shell(face, [0., 0., -size / 2.], core)
.insert(&mut core.services)
.insert(&mut core.services)]
})
}

0 comments on commit 9d27be1

Please sign in to comment.