use geo_traits::PointTrait;
use geoarrow_schema::Dimension;
use crate::array::CoordBuffer;
use crate::eq::point_eq;
use crate::scalar::Coord;
#[derive(Debug, Clone)]
pub struct Point<'a> {
coords: &'a CoordBuffer,
geom_index: usize,
}
impl<'a> Point<'a> {
pub(crate) fn new(coords: &'a CoordBuffer, geom_index: usize) -> Self {
Point { coords, geom_index }
}
pub(crate) fn native_dim(&self) -> Dimension {
self.coords.dim()
}
}
impl<'a> PointTrait for Point<'a> {
type CoordType<'b>
= Coord<'a>
where
Self: 'b;
fn coord(&self) -> Option<Self::CoordType<'_>> {
let coord = self.coords.value(self.geom_index);
if coord.is_nan() { None } else { Some(coord) }
}
}
impl<'a> PointTrait for &Point<'a> {
type CoordType<'b>
= Coord<'a>
where
Self: 'b;
fn coord(&self) -> Option<Self::CoordType<'_>> {
let coord = self.coords.value(self.geom_index);
if coord.is_nan() { None } else { Some(coord) }
}
}
impl<G: PointTrait<T = f64>> PartialEq<G> for Point<'_> {
fn eq(&self, other: &G) -> bool {
point_eq(self, other)
}
}