Skip to main content

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