diff --git a/.gitignore b/.gitignore index de2107bb3..80d1df356 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.DS_Store +.idea # Generated by Cargo # will have compiled files and executables diff --git a/src/array/mixed/array.rs b/src/array/mixed/array.rs index c653d64dd..3c629c4bf 100644 --- a/src/array/mixed/array.rs +++ b/src/array/mixed/array.rs @@ -82,7 +82,6 @@ pub struct MixedGeometryArray { slice_offset: usize, } -// TODO: rename to "GeometryType"? #[derive(Debug, Clone, Copy, PartialEq)] pub enum GeometryType { Point = 0, diff --git a/src/io/geos/scalar/linearring.rs b/src/io/geos/scalar/linearring.rs index d90762cb7..a2e0092a5 100644 --- a/src/io/geos/scalar/linearring.rs +++ b/src/io/geos/scalar/linearring.rs @@ -1,4 +1,4 @@ -use crate::error::Result; +use crate::error::{GeoArrowError, Result}; use geos::{Geom, GeometryTypes}; pub struct GEOSConstLinearRing<'a, 'b>(pub(crate) geos::ConstGeometry<'a, 'b>); @@ -10,10 +10,13 @@ impl<'a, 'b> GEOSConstLinearRing<'a, 'b> { #[allow(dead_code)] pub fn try_new(geom: geos::ConstGeometry<'a, 'b>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::LinearRing)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::LinearRing) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be linear ring".to_string(), + )) + } } pub fn num_coords(&self) -> usize { diff --git a/src/io/geos/scalar/linestring.rs b/src/io/geos/scalar/linestring.rs index b754cf0c9..3b4075c90 100644 --- a/src/io/geos/scalar/linestring.rs +++ b/src/io/geos/scalar/linestring.rs @@ -50,12 +50,14 @@ impl<'a> GEOSLineString<'a> { pub fn new_unchecked(geom: geos::Geometry<'a>) -> Self { Self(geom) } - pub fn try_new(geom: geos::Geometry<'a>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::LineString)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::LineString) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be line string".to_string(), + )) + } } } @@ -114,10 +116,13 @@ impl<'a, 'b> GEOSConstLineString<'a, 'b> { #[allow(dead_code)] pub fn try_new(geom: geos::ConstGeometry<'a, 'b>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::LineString)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::LineString) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be line string".to_string(), + )) + } } } diff --git a/src/io/geos/scalar/multilinestring.rs b/src/io/geos/scalar/multilinestring.rs index 27284423f..68af5ac23 100644 --- a/src/io/geos/scalar/multilinestring.rs +++ b/src/io/geos/scalar/multilinestring.rs @@ -39,13 +39,13 @@ impl<'a> GEOSMultiLineString<'a> { #[allow(dead_code)] pub fn try_new(geom: geos::Geometry<'a>) -> Result { - // TODO: make Err - assert!(matches!( - geom.geometry_type(), - GeometryTypes::MultiLineString - )); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::MultiLineString) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be multi line string".to_string(), + )) + } } pub fn num_lines(&self) -> usize { diff --git a/src/io/geos/scalar/multipoint.rs b/src/io/geos/scalar/multipoint.rs index 23f2cc888..bb0cc1b59 100644 --- a/src/io/geos/scalar/multipoint.rs +++ b/src/io/geos/scalar/multipoint.rs @@ -38,10 +38,13 @@ impl<'a> GEOSMultiPoint<'a> { #[allow(dead_code)] pub fn try_new(geom: geos::Geometry<'a>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::MultiPoint)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::MultiPoint) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be multi point".to_string(), + )) + } } pub fn num_points(&self) -> usize { diff --git a/src/io/geos/scalar/multipolygon.rs b/src/io/geos/scalar/multipolygon.rs index 2ed490eb9..3c1b713ee 100644 --- a/src/io/geos/scalar/multipolygon.rs +++ b/src/io/geos/scalar/multipolygon.rs @@ -39,10 +39,13 @@ impl<'a> GEOSMultiPolygon<'a> { #[allow(dead_code)] pub fn try_new(geom: geos::Geometry<'a>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::MultiPolygon)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::MultiPolygon) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be multi polygon".to_string(), + )) + } } pub fn num_polygons(&self) -> usize { diff --git a/src/io/geos/scalar/point.rs b/src/io/geos/scalar/point.rs index a76835f10..c6d355b0d 100644 --- a/src/io/geos/scalar/point.rs +++ b/src/io/geos/scalar/point.rs @@ -33,10 +33,13 @@ impl<'a> GEOSPoint<'a> { } pub fn try_new(geom: geos::Geometry<'a>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::Point)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::Point) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be point".to_string(), + )) + } } } @@ -96,10 +99,13 @@ impl<'a, 'b> GEOSConstPoint<'a, 'b> { } pub fn try_new(geom: &'a geos::ConstGeometry<'a, 'b>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::Point)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::Point) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be point".to_string(), + )) + } } } diff --git a/src/io/geos/scalar/polygon.rs b/src/io/geos/scalar/polygon.rs index 5db3c9429..a9d2b71a3 100644 --- a/src/io/geos/scalar/polygon.rs +++ b/src/io/geos/scalar/polygon.rs @@ -45,10 +45,13 @@ impl<'a> GEOSPolygon<'a> { #[allow(dead_code)] pub fn try_new(geom: geos::Geometry<'a>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::LineString)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::Polygon) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be polygon".to_string(), + )) + } } #[allow(dead_code)] @@ -88,10 +91,13 @@ impl<'a, 'b> GEOSConstPolygon<'a, 'b> { #[allow(dead_code)] pub fn try_new(geom: geos::ConstGeometry<'a, 'b>) -> Result { - // TODO: make Err - assert!(matches!(geom.geometry_type(), GeometryTypes::LineString)); - - Ok(Self(geom)) + if matches!(geom.geometry_type(), GeometryTypes::Polygon) { + Ok(Self(geom)) + } else { + Err(GeoArrowError::General( + "Geometry type must be polygon".to_string(), + )) + } } pub fn num_interiors(&self) -> usize {