boolmesh/
lib.rs

1//--- Copyright (C) 2025 Saki Komikado <komietty@gmail.com>,
2//--- This Source Code Form is subject to the terms of the Mozilla Public License v.2.0.
3
4mod manifold;
5mod triangulation;
6mod simplification;
7mod common;
8mod boolean03;
9mod boolean45;
10mod compose;
11mod tests;
12
13use crate::boolean03::boolean03;
14use crate::boolean45::boolean45;
15use crate::simplification::simplify_topology;
16use crate::triangulation::triangulate;
17use crate::common::*;
18use crate::manifold::*;
19
20pub use crate::common::{Real, Vec2, Vec3, Vec4, Mat3, K_PRECISION};
21
22pub mod prelude {
23    pub use crate::common::OpType;
24    pub use crate::manifold::Manifold;
25    pub use crate::compute_boolean;
26    pub use crate::compose::{compose, translate, scale, rotate, fractal};
27}
28
29pub fn compute_boolean(
30    mp: &Manifold,
31    mq: &Manifold,
32    op: OpType,
33) -> Result<Manifold, String> {
34    let eps = mp.eps.max(mq.eps);
35    let tol = mp.tol.max(mq.tol);
36
37    let     b03 = boolean03(mp, mq, &op);
38    let mut b45 = boolean45(mp, mq, &b03, &op);
39    let mut trg = triangulate(mp, mq, &b45, eps)?;
40
41    simplify_topology(
42        &mut trg.hs,
43        &mut b45.ps,
44        &mut trg.ns,
45        &mut trg.rs,
46        b45.nv_from_p,
47        b45.nv_from_q,
48        eps
49    );
50
51    cleanup_unused_verts(
52        &mut b45.ps,
53        &mut trg.hs
54    );
55
56    Manifold::new_impl(
57        b45.ps,
58        trg.hs.chunks(3).map(|hs| Vec3u::new(hs[0].tail, hs[1].tail, hs[2].tail)).collect(),
59        Some(eps),
60        Some(tol)
61    )
62}
63
64//pub fn compute_boolean_from_raw_data(
65//    pos0: &[Real],
66//    idx0: &[usize],
67//    pos1: &[Real],
68//    idx1: &[usize],
69//    op_type: usize
70//) -> Result<Manifold, String>{
71//    let mp = Manifold::new(&pos0, &idx0)?;
72//    let mq = Manifold::new(&pos1, &idx1)?;
73//    let op = match op_type {
74//        0 => OpType::Add,
75//        1 => OpType::Subtract,
76//        2 => OpType::Intersect,
77//        _ => return Err("Invalid op_type".into())
78//    };
79//    compute_boolean(&mp, &mq, op)
80//}
81
82
83
84
85