axiolid_mesh_section_contract/
contract.rs1use axiolid_contracts::{
4 Backend, CancellationGranularity, ExecutionOptions, GeomResult, ScratchRequirement,
5};
6use axiolid_core::{Frame3, Point2};
7use axiolid_mesh::TriMesh;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub struct SectionLimits {
12 pub max_source_vertices: usize,
14 pub max_source_triangles: usize,
16 pub max_output_vertices: usize,
18 pub max_contours: usize,
20}
21
22impl SectionLimits {
23 pub const fn new(
25 max_source_vertices: usize,
26 max_source_triangles: usize,
27 max_output_vertices: usize,
28 max_contours: usize,
29 ) -> Self {
30 Self {
31 max_source_vertices,
32 max_source_triangles,
33 max_output_vertices,
34 max_contours,
35 }
36 }
37}
38
39#[derive(Debug, Clone, PartialEq)]
43pub struct SectionContour {
44 pub points: Vec<Point2>,
46 closed: bool,
48}
49
50impl SectionContour {
51 pub fn new(points: Vec<Point2>) -> Self {
54 Self {
55 points,
56 closed: true,
57 }
58 }
59
60 pub const fn is_closed(&self) -> bool {
62 self.closed
63 }
64}
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq)]
68#[non_exhaustive]
69pub enum SectionSource {
70 InputMesh,
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76pub struct SectionEvidence {
77 pub source: SectionSource,
79 pub source_triangles: usize,
81 pub output_vertices: usize,
83 pub output_contours: usize,
85}
86
87impl SectionEvidence {
88 pub const fn input_mesh(
90 source_triangles: usize,
91 output_vertices: usize,
92 output_contours: usize,
93 ) -> Self {
94 Self {
95 source: SectionSource::InputMesh,
96 source_triangles,
97 output_vertices,
98 output_contours,
99 }
100 }
101
102 pub const fn is_derived_from_input_mesh(self) -> bool {
104 matches!(self.source, SectionSource::InputMesh)
105 }
106}
107
108#[derive(Debug, Clone, PartialEq)]
110pub struct SectionOutcome {
111 pub frame: Frame3,
113 pub contours: Vec<SectionContour>,
115 pub evidence: SectionEvidence,
117}
118
119impl SectionOutcome {
120 pub fn new(frame: Frame3, contours: Vec<SectionContour>, evidence: SectionEvidence) -> Self {
122 Self {
123 frame,
124 contours,
125 evidence,
126 }
127 }
128}
129
130pub trait MeshPlaneSection: Backend {
132 fn scratch_requirement(&self) -> ScratchRequirement {
134 ScratchRequirement::Unbounded
135 }
136
137 fn cancellation_granularity(&self) -> CancellationGranularity {
139 CancellationGranularity::None
140 }
141
142 fn section(
145 &self,
146 mesh: &TriMesh,
147 frame: Frame3,
148 limits: SectionLimits,
149 options: &ExecutionOptions,
150 ) -> GeomResult<SectionOutcome>;
151}