1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use fj_math::Scalar;

use crate::{
    algorithms::transform::TransformObject,
    objects::{Face, Shell, Surface},
    stores::Stores,
};

/// API for building a [`Shell`]
///
/// Also see [`Shell::builder`].
pub struct ShellBuilder<'a> {
    /// The stores that the created objects are put in
    pub stores: &'a Stores,
}

impl<'a> ShellBuilder<'a> {
    /// Create a cube from the length of its edges
    pub fn build_cube_from_edge_length(
        self,
        edge_length: impl Into<Scalar>,
    ) -> Shell {
        // Let's define a short-hand for half the edge length. We're going to
        // need it a lot.
        let h = edge_length.into() / 2.;

        let points = [[-h, -h], [h, -h], [h, h], [-h, h]];

        const Z: Scalar = Scalar::ZERO;
        let planes = [
            Surface::xy_plane().translate([Z, Z, -h], self.stores), // bottom
            Surface::xy_plane().translate([Z, Z, h], self.stores),  // top
            Surface::xz_plane().translate([Z, -h, Z], self.stores), // front
            Surface::xz_plane().translate([Z, h, Z], self.stores),  // back
            Surface::yz_plane().translate([-h, Z, Z], self.stores), // left
            Surface::yz_plane().translate([h, Z, Z], self.stores),  // right
        ];

        let faces = planes.map(|plane| {
            Face::builder(self.stores, plane)
                .with_exterior_polygon_from_points(points)
                .build()
        });

        Shell::new().with_faces(faces)
    }
}