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 std::collections::BTreeSet;

use fj_math::Scalar;

use crate::{
    insert::Insert,
    objects::{Objects, Shell, Solid},
    services::Service,
    storage::Handle,
};

/// API for building a [`Solid`]
///
/// Also see [`Solid::builder`].
pub struct SolidBuilder {
    /// The shells that make up the [`Solid`]
    pub shells: BTreeSet<Handle<Shell>>,
}

impl SolidBuilder {
    /// Build the [`Solid`] with the provided shells
    pub fn with_shells(
        mut self,
        shells: impl IntoIterator<Item = Handle<Shell>>,
    ) -> Self {
        self.shells.extend(shells);
        self
    }

    /// Create a cube from the length of its edges
    pub fn with_cube_from_edge_length(
        mut self,
        edge_length: impl Into<Scalar>,
        objects: &mut Service<Objects>,
    ) -> Self {
        let shell = Shell::builder()
            .with_cube_from_edge_length(edge_length, objects)
            .build(objects);
        self.shells.insert(shell);
        self
    }

    /// Build the [`Solid`]
    pub fn build(self, objects: &mut Service<Objects>) -> Handle<Solid> {
        Solid::new(self.shells).insert(objects)
    }
}