fj_kernel/objects/full/
solid.rs

1use std::collections::BTreeSet;
2
3use crate::{
4    objects::{Face, Shell},
5    storage::Handle,
6};
7
8/// A 3-dimensional shape, built from [`Shell`]s. Many Solids will contains only
9/// one shell, but if the Solid contains cavities they will be represented by a
10/// shell each, as well as a shell for the outside.
11///
12/// # Implementation Note
13///
14/// The shells that form the boundaries of the solid must not intersect. This is
15/// not currently validated.
16#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
17pub struct Solid {
18    shells: BTreeSet<Handle<Shell>>,
19}
20
21impl Solid {
22    /// Construct an empty instance of `Solid`
23    pub fn new(shells: impl IntoIterator<Item = Handle<Shell>>) -> Self {
24        Self {
25            shells: shells.into_iter().collect(),
26        }
27    }
28
29    /// Access the solid's shells
30    pub fn shells(&self) -> impl Iterator<Item = &Handle<Shell>> {
31        self.shells.iter()
32    }
33
34    /// Find the given face in the solid
35    pub fn find_face(&self, face: &Handle<Face>) -> Option<Handle<Face>> {
36        for shell in self.shells() {
37            if let Some(face) = shell.find_face(face) {
38                return Some(face);
39            }
40        }
41
42        None
43    }
44}