Skip to content

Commit

Permalink
Remove infallible accessor for Point::coord (#880)
Browse files Browse the repository at this point in the history
This forces the use of `PointTrait::coord`, which returns
`Option<Coord>`, which is `None` if the point is empty.
  • Loading branch information
kylebarron authored Nov 27, 2024
1 parent 5b0e100 commit c792efa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 3 additions & 3 deletions rust/geoarrow/src/algorithm/native/map_coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::trait_::ArrayAccessor;
use crate::NativeArray;
use geo_traits::{
CoordTrait, GeometryCollectionTrait, GeometryTrait, GeometryType, LineStringTrait,
MultiLineStringTrait, MultiPointTrait, MultiPolygonTrait, PolygonTrait, RectTrait,
MultiLineStringTrait, MultiPointTrait, MultiPolygonTrait, PointTrait, PolygonTrait, RectTrait,
};

/// Note: this will currently always create a _two-dimensional_ output array because it returns a [`geo::Coord`].
Expand Down Expand Up @@ -52,7 +52,7 @@ impl MapCoords for Point<'_> {
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
GeoArrowError: From<E>,
{
Ok(geo::Point(map_op(&self.coord())?))
Ok(geo::Point(map_op(&self.coord().unwrap())?))
}
}

Expand Down Expand Up @@ -229,7 +229,7 @@ impl MapCoords for PointArray {
);
for maybe_geom in self.iter() {
if let Some(geom) = maybe_geom {
let result = geom.coord().try_map_coords(&map_op)?;
let result = geom.coord().unwrap().try_map_coords(&map_op)?;
builder.push_coord(Some(&result));
} else {
builder.push_null()
Expand Down
4 changes: 0 additions & 4 deletions rust/geoarrow/src/scalar/point/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ impl<'a> Point<'a> {
Point { coords, geom_index }
}

pub fn coord(&self) -> Coord {
self.coords.value(self.geom_index)
}

pub fn into_owned_inner(self) -> (CoordBuffer, usize) {
let coords = self.coords.owned_slice(self.geom_index, 1);
(coords, self.geom_index)
Expand Down
4 changes: 2 additions & 2 deletions rust/geoarrow/src/trait_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ pub trait ArrayAccessor<'a>: ArrayBase {
/// let point = geo::point!(x: 1., y: 2.);
/// let array: PointArray = (vec![point].as_slice(), Dimension::XY).into();
/// let value = array.value(0); // geoarrow::scalar::Point
/// assert_eq!(value.coord().x(), 1.);
/// assert_eq!(value.coord().y(), 2.);
/// assert_eq!(value.coord().unwrap().x(), 1.);
/// assert_eq!(value.coord().unwrap().y(), 2.);
/// ```
///
/// # Panics
Expand Down

0 comments on commit c792efa

Please sign in to comment.