Skip to main content

geometry_model/
polyhedral_surface.rs

1//! Default polyhedral-surface model backed by a polygon vector.
2//!
3//! Mirrors `boost::geometry::model::polyhedral_surface<Polygon>` from
4//! `geometries/polyhedral_surface.hpp:37-85`.
5
6use alloc::vec::Vec;
7
8use geometry_tag::PolyhedralSurfaceTag;
9use geometry_trait::{Geometry, Polygon, PolyhedralSurface as PolyhedralSurfaceTrait};
10
11/// A contiguous collection of polygon faces in three-dimensional space.
12///
13/// Mirrors `model::polyhedral_surface<Polygon>` from
14/// `geometries/polyhedral_surface.hpp:48-83`. As in Boost, construction does
15/// not verify that faces are 3D or share boundary segments; those are validity
16/// concerns rather than storage invariants.
17#[derive(Debug, Clone, PartialEq)]
18#[repr(transparent)]
19pub struct PolyhedralSurface<Pg: Polygon>(pub Vec<Pg>);
20
21impl<Pg: Polygon> PolyhedralSurface<Pg> {
22    /// Construct an empty polyhedral surface.
23    ///
24    /// Mirrors the default constructor at
25    /// `geometries/polyhedral_surface.hpp:74-76`.
26    #[inline]
27    #[must_use]
28    pub const fn new() -> Self {
29        Self(Vec::new())
30    }
31
32    /// Wrap an existing ordered face vector.
33    ///
34    /// Mirrors the initializer-list constructor at
35    /// `geometries/polyhedral_surface.hpp:79-81`.
36    #[inline]
37    #[must_use]
38    pub const fn from_vec(faces: Vec<Pg>) -> Self {
39        Self(faces)
40    }
41
42    /// Append one polygon face.
43    #[inline]
44    pub fn push(&mut self, face: Pg) {
45        self.0.push(face);
46    }
47}
48
49impl<Pg: Polygon> Default for PolyhedralSurface<Pg> {
50    #[inline]
51    fn default() -> Self {
52        Self::new()
53    }
54}
55
56impl<Pg: Polygon> Geometry for PolyhedralSurface<Pg> {
57    type Kind = PolyhedralSurfaceTag;
58    type Point = Pg::Point;
59}
60
61impl<Pg: Polygon> PolyhedralSurfaceTrait for PolyhedralSurface<Pg> {
62    type Face = Pg;
63
64    #[inline]
65    fn faces(&self) -> impl ExactSizeIterator<Item = &Self::Face> {
66        self.0.iter()
67    }
68}