use crate::LatLng;
use std::{fmt, ops::Deref};
const MAX_BNDRY_VERTS: usize = 10;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Default)]
pub struct Boundary {
points: [LatLng; MAX_BNDRY_VERTS],
count: u8,
}
impl Boundary {
#[must_use]
#[doc(hidden)]
pub fn new() -> Self {
Self::default()
}
#[doc(hidden)]
pub fn push(&mut self, ll: LatLng) {
self.points[usize::from(self.count)] = ll;
self.count += 1;
}
}
impl Deref for Boundary {
type Target = [LatLng];
fn deref(&self) -> &Self::Target {
&self.points[..self.count.into()]
}
}
impl fmt::Display for Boundary {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"[{}]",
self.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("-")
)
}
}
#[cfg(feature = "geo")]
impl From<Boundary> for geo::LineString {
fn from(value: Boundary) -> Self {
Self::new(value.iter().copied().map(geo::Coord::from).collect())
}
}