brep_boolean/csg/boolean/
dedicated.rs1use super::{BooleanOperation, BrepSolid, KernelRefusal};
7
8pub type DedicatedBoolean = fn(&BrepSolid, &BrepSolid, BooleanOperation) -> Option<Result<BrepSolid, KernelRefusal>>;
10
11static ROUTES: std::sync::RwLock<Vec<DedicatedBoolean>> = std::sync::RwLock::new(Vec::new());
12
13pub fn register_dedicated_boolean(route: DedicatedBoolean) {
15 if let Ok(mut routes) = ROUTES.write() {
16 if !routes.iter().any(|known| *known as usize == route as usize) {
17 routes.push(route);
18 }
19 }
20}
21
22pub fn dedicated_booleans_on() -> bool {
26 crate::switch!("BREP_SWEEP_TUBE_BOOLEAN", false)
27}
28
29pub(super) fn dedicated(first: &BrepSolid, second: &BrepSolid, operation: BooleanOperation) -> Option<Result<BrepSolid, KernelRefusal>> {
31 if !dedicated_booleans_on() {
32 return None;
33 }
34 let routes: Vec<DedicatedBoolean> = ROUTES.read().ok()?.clone();
35 routes.into_iter().find_map(|route| route(first, second, operation))
36}