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
use fj_math::Scalar;
use crate::{
algorithms::TransformObject,
objects::{Face, Solid, Surface},
};
pub struct SolidBuilder;
impl SolidBuilder {
pub fn cube_from_edge_length(
&self,
edge_length: impl Into<Scalar>,
) -> Solid {
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::build(plane).polygon_from_points(points));
Solid::from_faces(faces)
}
}