Skip to main content

egml_core/model/geometry/primitives/
ring_kind.rs

1use crate::impl_abstract_ring_traits;
2use crate::model::geometry::primitives::{
3    AbstractRing, AsAbstractRing, AsAbstractRingMut, LinearRing,
4};
5use crate::model::geometry::{DirectPosition, Envelope};
6use nalgebra::Isometry3;
7
8/// Discriminated union of all concrete ring implementations.
9#[derive(Debug, Clone, PartialEq)]
10pub enum RingKind {
11    /// A [`LinearRing`] ring.
12    LinearRing(LinearRing),
13
14    RingKind(Box<RingKind>),
15}
16
17impl AsAbstractRing for RingKind {
18    fn abstract_ring(&self) -> &AbstractRing {
19        match self {
20            Self::LinearRing(x) => x.abstract_ring(),
21            Self::RingKind(x) => x.abstract_ring(),
22        }
23    }
24}
25
26impl AsAbstractRingMut for RingKind {
27    fn abstract_ring_mut(&mut self) -> &mut AbstractRing {
28        match self {
29            Self::LinearRing(x) => x.abstract_ring_mut(),
30            Self::RingKind(x) => x.abstract_ring_mut(),
31        }
32    }
33}
34
35impl_abstract_ring_traits!(RingKind);
36
37impl RingKind {
38    pub fn compute_envelope(&self) -> Envelope {
39        match self {
40            Self::LinearRing(x) => x.compute_envelope(),
41            Self::RingKind(x) => x.compute_envelope(),
42        }
43    }
44
45    pub fn points(&self) -> &[DirectPosition] {
46        match self {
47            Self::LinearRing(x) => x.points(),
48            Self::RingKind(x) => x.points(),
49        }
50    }
51
52    pub fn apply_transform(&mut self, m: &Isometry3<f64>) {
53        match self {
54            Self::LinearRing(x) => x.apply_transform(m),
55            Self::RingKind(x) => x.apply_transform(m),
56        }
57    }
58
59    pub fn area_3d(&self) -> f64 {
60        match self {
61            Self::LinearRing(x) => x.area_3d(),
62            Self::RingKind(x) => x.area_3d(),
63        }
64    }
65}