Skip to main content

egml_core/model/common/
triangulate.rs

1use crate::Error;
2use crate::model::geometry::primitives::TriangulatedSurface;
3
4pub trait Triangulate {
5    fn triangulate(&self) -> Result<Triangulation, Error>;
6}
7
8/// The result of triangulating something that tolerates non-fatal member
9/// failures: the combined surface, plus the errors from any members that
10/// were skipped along the way (e.g. a degenerate ring). Mirrors
11/// rust-analyzer's `Parse<T>` / oxc's `ParserReturn`.
12#[derive(Debug, Clone, PartialEq)]
13pub struct Triangulation {
14    surface: TriangulatedSurface,
15    skipped: Vec<Error>,
16}
17
18impl Triangulation {
19    pub fn new(surface: TriangulatedSurface, skipped: Vec<Error>) -> Self {
20        Self { surface, skipped }
21    }
22
23    pub fn surface(&self) -> &TriangulatedSurface {
24        &self.surface
25    }
26
27    pub fn into_surface(self) -> TriangulatedSurface {
28        self.surface
29    }
30
31    pub fn skipped(&self) -> &[Error] {
32        &self.skipped
33    }
34
35    pub fn has_skipped(&self) -> bool {
36        !self.skipped.is_empty()
37    }
38
39    pub fn into_parts(self) -> (TriangulatedSurface, Vec<Error>) {
40        (self.surface, self.skipped)
41    }
42}