use super::{BooleanOperation, BrepSolid, KernelRefusal};
pub type DedicatedBoolean = fn(&BrepSolid, &BrepSolid, BooleanOperation) -> Option<Result<BrepSolid, KernelRefusal>>;
static ROUTES: std::sync::RwLock<Vec<DedicatedBoolean>> = std::sync::RwLock::new(Vec::new());
pub fn register_dedicated_boolean(route: DedicatedBoolean) {
if let Ok(mut routes) = ROUTES.write() {
if !routes.iter().any(|known| *known as usize == route as usize) {
routes.push(route);
}
}
}
pub fn dedicated_booleans_on() -> bool {
crate::switch!("BREP_SWEEP_TUBE_BOOLEAN", false)
}
pub(super) fn dedicated(first: &BrepSolid, second: &BrepSolid, operation: BooleanOperation) -> Option<Result<BrepSolid, KernelRefusal>> {
if !dedicated_booleans_on() {
return None;
}
let routes: Vec<DedicatedBoolean> = ROUTES.read().ok()?.clone();
routes.into_iter().find_map(|route| route(first, second, operation))
}