axiolid_construct/
result.rs

1//! Explicit output-model contracts for solid generation.
2//!
3//! Analytic B-rep and mesh tessellation are deliberately different requests and
4//! result variants. An exact generator may return `ExactBRep` only for an
5//! [`GenerationRequest::ExactBRep`] request; it must return `Unsupported` rather
6//! than discretising that request. Tessellation is an explicit request carrying
7//! the caller's tolerance.
8
9use axiolid_brep::ExactBRep;
10use axiolid_core::Tolerance;
11use axiolid_mesh::TriMesh;
12use axiolid_tessellation_contract::TessellatedMesh;
13
14/// Requested result model for a generation operation.
15#[derive(Debug, Clone, Copy, PartialEq)]
16pub enum GenerationRequest {
17    /// Preserve analytic supports, trim spans, and typed topology.
18    ExactBRep,
19    /// Produce a triangle mesh within the stated explicit tolerance policy.
20    Tessellation(TessellationRequest),
21}
22
23impl GenerationRequest {
24    /// Whether this request must be satisfied by an analytic B-rep or refused.
25    ///
26    /// A mesh is never a valid fallback for this request.
27    pub const fn requires_exact_brep(self) -> bool {
28        matches!(self, Self::ExactBRep)
29    }
30}
31
32/// Explicit tolerance policy for a tessellation request.
33///
34/// There is no default: mesh accuracy is a caller decision and must not become
35/// an implicit replacement for exact construction.
36#[derive(Debug, Clone, Copy, PartialEq)]
37pub struct TessellationRequest {
38    tolerance: Tolerance,
39}
40
41impl TessellationRequest {
42    /// Construct an explicit tessellation request.
43    pub const fn new(tolerance: Tolerance) -> Self {
44        Self { tolerance }
45    }
46
47    /// Requested tolerance policy.
48    pub const fn tolerance(self) -> Tolerance {
49        self.tolerance
50    }
51
52    /// Bind a generated mesh to this request's tolerance.
53    #[must_use]
54    pub const fn bind(self, mesh: TriMesh) -> TessellatedMesh {
55        TessellatedMesh::new(mesh, self.tolerance)
56    }
57}
58
59/// Geometry produced by a generation operation.
60///
61/// The variant must match the caller's [`GenerationRequest`]. This sum type is
62/// intentionally not coercible: consumers must acknowledge whether they hold
63/// analytic B-rep or a discrete mesh.
64///
65/// `ExactBRep` remains inline for public API compatibility and to avoid an
66/// infallible boxing allocation on certified construction paths.
67#[allow(clippy::large_enum_variant)]
68#[derive(Debug, Clone, PartialEq)]
69#[non_exhaustive]
70pub enum GeneratedGeometry {
71    /// Analytic boundary representation with explicit topology and trims.
72    ExactBRep(ExactBRep),
73    /// Explicitly requested triangle tessellation with tolerance provenance.
74    Tessellation(TessellatedMesh),
75}
76
77/// Coarse output-model classification for capabilities and diagnostics.
78#[derive(Debug, Clone, Copy, PartialEq, Eq)]
79pub enum GenerationOutput {
80    /// Analytic B-rep result.
81    ExactBRep,
82    /// Triangle mesh result.
83    Tessellation,
84}
85
86impl GeneratedGeometry {
87    /// Result model actually produced.
88    pub const fn output(&self) -> GenerationOutput {
89        match self {
90            Self::ExactBRep(_) => GenerationOutput::ExactBRep,
91            Self::Tessellation(_) => GenerationOutput::Tessellation,
92        }
93    }
94}