use crate::{AnalyticSurface, BrepSolid, KernelRefusal};
pub(super) fn exact_single_sphere(solid: &BrepSolid) -> bool {
if solid.shells.len() != 1 || solid.shells[0].faces.len() != 1 {
return false;
}
let face = &solid.shells[0].faces[0];
if face.loops.len() != 1 || !solid.validate().is_empty() {
return false;
}
matches!(
crate::analytic_surface::recognize(&face.surface),
Some(AnalyticSurface::Sphere { radius, .. }) if radius.is_finite() && radius > 0.0
)
}
pub(super) fn accept_offset_result(solid: BrepSolid) -> Result<BrepSolid, KernelRefusal> {
let enabled = std::env::var("BREP_OFFSET_SPHERE_ACCEPT")
.map_or(true, |value| value == "1" || value == "on");
accept_offset_result_with_certificate(solid, enabled)
}
pub(super) fn accept_offset_result_with_certificate(
solid: BrepSolid,
enabled: bool,
) -> Result<BrepSolid, KernelRefusal> {
if enabled && exact_single_sphere(&solid) {
if crate::imprint::profile_enabled() {
eprintln!("offset_accept.profile certificate=single_sphere faces=1");
}
return Ok(solid);
}
crate::accept_sound(solid, "offsetShell")
}