use super::MonotoneChainLineString;
use crate::GeoNum;
use crate::geometry::Polygon;
pub struct MonotoneChainPolygon<'a, T: GeoNum> {
geometry: &'a Polygon<T>,
exterior: MonotoneChainLineString<'a, T>,
interiors: Vec<MonotoneChainLineString<'a, T>>,
}
impl<'a, T: GeoNum> MonotoneChainPolygon<'a, T> {
pub fn geometry(&self) -> &'a Polygon<T> {
self.geometry
}
pub fn exterior(&self) -> &MonotoneChainLineString<'a, T> {
&self.exterior
}
pub fn interiors(&self) -> &[MonotoneChainLineString<'a, T>] {
&self.interiors
}
}
impl<'a, T: GeoNum> From<&'a Polygon<T>> for MonotoneChainPolygon<'a, T> {
fn from(polygon: &'a Polygon<T>) -> Self {
Self {
geometry: polygon,
exterior: polygon.exterior().into(),
interiors: polygon.interiors().iter().map(|ring| ring.into()).collect(),
}
}
}
impl<'a, T: GeoNum> From<MonotoneChainPolygon<'a, T>> for &'a Polygon<T> {
fn from(val: MonotoneChainPolygon<'a, T>) -> Self {
val.geometry
}
}