geoarrow_array/scalar/
point.rs1use geo_traits::PointTrait;
2use geoarrow_schema::Dimension;
3
4use crate::array::CoordBuffer;
5use crate::eq::point_eq;
6use crate::scalar::Coord;
7
8#[derive(Debug, Clone)]
12pub struct Point<'a> {
13 coords: &'a CoordBuffer,
14 geom_index: usize,
15}
16
17impl<'a> Point<'a> {
18 pub(crate) fn new(coords: &'a CoordBuffer, geom_index: usize) -> Self {
19 Point { coords, geom_index }
20 }
21
22 pub(crate) fn native_dim(&self) -> Dimension {
23 self.coords.dim()
24 }
25}
26
27impl<'a> PointTrait for Point<'a> {
28 type CoordType<'b>
29 = Coord<'a>
30 where
31 Self: 'b;
32
33 fn coord(&self) -> Option<Self::CoordType<'_>> {
34 let coord = self.coords.value(self.geom_index);
35 if coord.is_nan() { None } else { Some(coord) }
36 }
37}
38
39impl<'a> PointTrait for &Point<'a> {
40 type CoordType<'b>
41 = Coord<'a>
42 where
43 Self: 'b;
44
45 fn coord(&self) -> Option<Self::CoordType<'_>> {
46 let coord = self.coords.value(self.geom_index);
47 if coord.is_nan() { None } else { Some(coord) }
48 }
49}
50
51impl<G: PointTrait<T = f64>> PartialEq<G> for Point<'_> {
52 fn eq(&self, other: &G) -> bool {
53 point_eq(self, other)
54 }
55}
56
57