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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::collections::BTreeSet;
use fj_math::Scalar;
use crate::algorithms::TransformObject;
use super::{Face, Surface};
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Solid {
faces: BTreeSet<Face>,
}
impl Solid {
pub fn from_faces(faces: impl IntoIterator<Item = Face>) -> Self {
let faces = faces.into_iter().collect();
Self { faces }
}
pub fn cube_from_edge_length(edge_length: impl Into<Scalar>) -> Self {
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]),
Surface::xy_plane().translate([Z, Z, h]),
Surface::xz_plane().translate([Z, -h, Z]),
Surface::xz_plane().translate([Z, h, Z]),
Surface::yz_plane().translate([-h, Z, Z]),
Surface::yz_plane().translate([h, Z, Z]),
];
let faces = planes.map(|plane| {
Face::builder(plane).with_exterior_polygon(points).build()
});
Solid::from_faces(faces)
}
pub fn faces(&self) -> impl Iterator<Item = &Face> {
self.faces.iter()
}
pub fn into_faces(self) -> BTreeSet<Face> {
self.faces
}
}