ifc_lite_geometry_runtime/
worker_empty.rs

1// SPDX-License-Identifier: MPL-2.0
2//! Sealed empty outcomes, certified by the actual retained solid. An empty
3//! retained Boolean result is a valid numerical value, not a worker failure.
4use super::{BrepHandle, SmlibWorker, TessellatedMesh, WorkerError};
5use crate::protocol::KernelCommand;
6
7/// Adapter capability bit of the semantic empty query (opcode 19).
8const SEMANTIC_EMPTY: u32 = 32;
9
10/// Classification of a strict tessellation, sealed from the actual retained
11/// solid. Zero counts alone are no proof: an all-zero mesh is accepted only
12/// with the solid's own semantic empty certificate. Grants no result authority.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum NumericalOutcome {
15    NonEmpty,
16    Empty,
17}
18
19impl SmlibWorker {
20    /// Semantic emptiness of the actual retained solid: no boundary topology
21    /// and only known-void regions. A zero volume or mesh is no such proof.
22    pub fn is_empty(&mut self, solid: BrepHandle) -> Result<bool, WorkerError> {
23        if self.capabilities()? & SEMANTIC_EMPTY == 0 {
24            return Err(self.poison("semantic empty query unavailable"));
25        }
26        let solid = self.wire(solid)?;
27        let bytes = self.call(KernelCommand::IsEmpty {
28            session: self.session,
29            solid,
30        })?;
31        match u32::from_le_bytes(self.fixed(bytes)?) {
32            0 => Ok(false),
33            1 => Ok(true),
34            _ => Err(self.poison("invalid semantic empty result")),
35        }
36    }
37
38    /// An all-zero strict mesh of `solid` is sealed empty only with the
39    /// solid's own certificate; otherwise the adapter broke its contract.
40    pub(super) fn certify_empty(
41        &mut self,
42        solid: BrepHandle,
43    ) -> Result<TessellatedMesh, WorkerError> {
44        if !self.is_empty(solid)? {
45            return Err(self.poison("zero tessellation of a nonempty solid"));
46        }
47        Ok(TessellatedMesh::empty())
48    }
49}