fj_kernel/operations/update/
shell.rs

1use crate::{
2    objects::{Face, Shell},
3    storage::Handle,
4};
5
6/// Update a [`Shell`]
7pub trait UpdateShell {
8    /// Update a face of the shell
9    fn replace_face(
10        &self,
11        original: &Handle<Face>,
12        replacement: Handle<Face>,
13    ) -> Shell;
14
15    /// Remove a face from the shell
16    fn remove_face(&self, handle: &Handle<Face>) -> Shell;
17}
18
19impl UpdateShell for Shell {
20    fn replace_face(
21        &self,
22        original: &Handle<Face>,
23        replacement: Handle<Face>,
24    ) -> Shell {
25        let faces = self.faces().into_iter().map(|face| {
26            if face.id() == original.id() {
27                replacement.clone()
28            } else {
29                face.clone()
30            }
31        });
32
33        Shell::new(faces)
34    }
35
36    fn remove_face(&self, handle: &Handle<Face>) -> Shell {
37        let faces = self
38            .faces()
39            .into_iter()
40            .filter(|face| face.id() == handle.id())
41            .cloned();
42
43        Shell::new(faces)
44    }
45}