axiolid_exact_compile_contract/contract.rs
1//! Graph-to-exact-B-rep capability.
2
3use axiolid_brep::ExactBRep;
4use axiolid_contracts::{Backend, ExecutionOptions, GeomResult, OutputBound, ScratchRequirement};
5use axiolid_model::{GeometryGraph, NodeId};
6
7/// Backend able to lower graph roots to exact B-reps, or refuse.
8///
9/// The contract is deliberately narrow. An implementation returns
10/// [`axiolid_contracts::GeomError::UnsupportedInput`] naming the unsupported
11/// node family when it cannot preserve exactness. It must never substitute a
12/// tessellation: callers wanting triangles ask
13/// `axiolid_mesh_compile_contract::MeshCompiler` instead.
14pub trait ExactCompiler: Backend {
15 /// Scratch needed beyond the graph and the produced results.
16 ///
17 /// Defaults to unbounded: an unaudited compiler is treated as unbudgetable
18 /// rather than silently assumed cheap.
19 fn scratch_requirement(&self) -> ScratchRequirement {
20 ScratchRequirement::Unbounded
21 }
22
23 /// Outputs produced per requested root.
24 fn output_bound(&self) -> OutputBound {
25 OutputBound::OneToOne
26 }
27
28 /// Compile one root to an exact B-rep, or refuse.
29 fn compile_exact(
30 &self,
31 graph: &GeometryGraph,
32 root: NodeId,
33 options: &ExecutionOptions,
34 ) -> GeomResult<ExactBRep>;
35
36 /// Compile roots into a caller-provided buffer.
37 ///
38 /// Results append in root order. Implementations override this seam to
39 /// share a per-request exact-result cache across roots.
40 fn compile_exact_batch_into(
41 &self,
42 graph: &GeometryGraph,
43 roots: &[NodeId],
44 options: &ExecutionOptions,
45 destination: &mut Vec<ExactBRep>,
46 ) -> GeomResult<()> {
47 destination.reserve(roots.len());
48 for &root in roots {
49 destination.push(self.compile_exact(graph, root, options)?);
50 }
51 Ok(())
52 }
53
54 /// Compile roots as an ordered exact-result batch.
55 fn compile_exact_batch(
56 &self,
57 graph: &GeometryGraph,
58 roots: &[NodeId],
59 options: &ExecutionOptions,
60 ) -> GeomResult<Vec<ExactBRep>> {
61 let mut destination = Vec::with_capacity(roots.len());
62 self.compile_exact_batch_into(graph, roots, options, &mut destination)?;
63 Ok(destination)
64 }
65}