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 crate::builder::SolidBuilder;
use super::Face;
/// A 3-dimensional shape
///
/// # Implementation Note
///
/// The faces that make up the solid must form a closed shape. This is not
/// currently validated.
///
/// In fact, solids could be made up of several closed shells. One outer shell,
/// and multiple inner ones (cavities within the solid). There should probably
/// a separate `Shell` object that is a collection of faces, and validates that
/// those faces form a closed shape. `Solid` should be a collection of such
/// `Shell`s, and validate that those `Shell`s don't intersect.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Solid {
faces: BTreeSet<Face>,
}
impl Solid {
/// Construct a solid from faces
pub fn from_faces(
faces: impl IntoIterator<Item = impl Into<Face>>,
) -> Self {
let faces = faces.into_iter().map(Into::into).collect();
Self { faces }
}
/// Build a solid using [`SolidBuilder`]
pub fn build() -> SolidBuilder {
SolidBuilder
}
/// Access the solid's faces
pub fn faces(&self) -> impl Iterator<Item = &Face> {
self.faces.iter()
}
/// Convert the solid into a list of faces
pub fn into_faces(self) -> BTreeSet<Face> {
self.faces
}
}