fj_core/operations/sweep/face.rs
1use fj_math::Vector;
2
3use crate::{
4 objects::{Face, Shell},
5 operations::{insert::Insert, presentation::GetColor},
6 storage::Handle,
7 Core,
8};
9
10use super::{SweepCache, SweepRegion};
11
12/// # Sweep a [`Face`]
13///
14/// See [module documentation] for more information.
15///
16/// [module documentation]: super
17pub trait SweepFace {
18 /// # Sweep the [`Face`] into a [`Shell`]
19 fn sweep_face(
20 &self,
21 path: impl Into<Vector<3>>,
22 cache: &mut SweepCache,
23 core: &mut Core,
24 ) -> Shell;
25}
26
27impl SweepFace for Handle<Face> {
28 fn sweep_face(
29 &self,
30 path: impl Into<Vector<3>>,
31 cache: &mut SweepCache,
32 core: &mut Core,
33 ) -> Shell {
34 // Please note that this function uses the words "bottom" and "top" in a
35 // specific sense:
36 //
37 // - "Bottom" refers to the origin of the sweep. The bottom face is the
38 // original face, or a face in the same place.
39 // - "Top" refers to the location of the face that was created by
40 // translating the bottom face along the path.
41 // - "Side" refers to new faces created in between bottom and top.
42 //
43 // These words are specifically *not* meant in the sense of z-axis
44 // locations, and depending on the direction of `path`, the two meanings
45 // might actually be opposite.
46
47 let path = path.into();
48
49 let bottom_face = self;
50 let other_faces = bottom_face
51 .region()
52 .sweep_region(
53 bottom_face.surface(),
54 bottom_face.region().get_color(core),
55 path,
56 cache,
57 core,
58 )
59 .all_faces()
60 .map(|side_face| side_face.insert(core));
61
62 let mut faces = Vec::new();
63 faces.push(bottom_face.clone());
64 faces.extend(other_faces);
65
66 Shell::new(faces)
67 }
68}