use crate::{
geo::{Coord, Polygon},
Elev, Tile, C,
};
pub struct Sample<'a> {
pub(crate) tile: &'a Tile,
pub(crate) index: usize,
}
#[allow(clippy::must_use_candidate)]
impl<'a> Sample<'a> {
#[inline]
pub fn elevation(&self) -> Elev {
self.tile.samples.get_linear_unchecked(self.index)
}
#[inline]
pub fn polygon(&self) -> Polygon {
self.tile.xy_to_polygon(self.xy())
}
#[inline]
pub fn index(&self) -> usize {
self.index
}
#[inline]
pub fn xy(&self) -> (usize, usize) {
self.tile.linear_to_xy(self.index)
}
#[inline]
pub fn geo(&self) -> Coord<C> {
self.tile.xy_to_geo(self.xy())
}
}
impl<'a> std::cmp::PartialEq for Sample<'a> {
fn eq(&self, other: &Self) -> bool {
self.index == other.index && std::ptr::eq(self, other)
}
}
impl<'a> std::cmp::Eq for Sample<'a> {}