microcad_core/geo3d/
mod.rs

1// Copyright © 2024-2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! 3D Geometry
5
6mod bounds;
7mod collection;
8mod extrude;
9mod geometry;
10mod mesh;
11mod triangle;
12mod vertex;
13
14pub use bounds::*;
15pub use collection::*;
16pub use extrude::*;
17pub use geometry::*;
18pub use manifold_rs::Manifold;
19pub use mesh::TriangleMesh;
20pub use vertex::Vertex;
21
22use crate::BooleanOp;
23
24impl From<&BooleanOp> for manifold_rs::BooleanOp {
25    fn from(op: &BooleanOp) -> Self {
26        match op {
27            BooleanOp::Union => manifold_rs::BooleanOp::Union,
28            BooleanOp::Intersect => manifold_rs::BooleanOp::Intersection,
29            BooleanOp::Subtract => manifold_rs::BooleanOp::Difference,
30            _ => unimplemented!(),
31        }
32    }
33}
34
35#[test]
36fn test_mesh_volume() {
37    let manifold = Manifold::sphere(1.0, 512);
38    let mesh = TriangleMesh::from(manifold.to_mesh());
39
40    let volume = mesh.volume();
41    assert!((volume - 4.0 / 3.0 * std::f64::consts::PI).abs() < 1e-3);
42}