diff --git a/src/array/mixed/array.rs b/src/array/mixed/array.rs index c653d64d..3c629c4b 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/array/linestring.rs b/src/io/geos/array/linestring.rs index 350c2c69..5a525626 100644 --- a/src/io/geos/array/linestring.rs +++ b/src/io/geos/array/linestring.rs @@ -12,10 +12,9 @@ impl<'a, O: OffsetSizeTrait> TryFrom>>> fn try_from(value: Vec>>) -> std::result::Result { let length = value.len(); - // TODO: don't use new_unchecked let geos_linestring_objects: Vec> = value .into_iter() - .map(|geom| geom.map(GEOSLineString::new_unchecked)) + .map(|geom| geom.map(|geom| GEOSLineString::try_new(geom)?)) .collect(); let (coord_capacity, geom_capacity) = first_pass( geos_linestring_objects.iter().map(|item| item.as_ref()), diff --git a/src/io/geos/array/multilinestring.rs b/src/io/geos/array/multilinestring.rs index ed33012b..5120cf1a 100644 --- a/src/io/geos/array/multilinestring.rs +++ b/src/io/geos/array/multilinestring.rs @@ -129,10 +129,9 @@ impl TryFrom>>> fn try_from(value: Vec>>) -> Result { let length = value.len(); - // TODO: don't use new_unchecked let geos_objects: Vec> = value .into_iter() - .map(|geom| geom.map(GEOSMultiLineString::new_unchecked)) + .map(|geom| geom.map(|geom| GEOSMultiLineString::try_new(geom)?)) .collect(); let (coord_capacity, ring_capacity, geom_capacity) = first_pass(&geos_objects, length); diff --git a/src/io/geos/array/multipoint.rs b/src/io/geos/array/multipoint.rs index b99e8ab1..af630b99 100644 --- a/src/io/geos/array/multipoint.rs +++ b/src/io/geos/array/multipoint.rs @@ -63,10 +63,9 @@ impl<'a, O: OffsetSizeTrait> TryFrom>>> fn try_from(value: Vec>>) -> std::result::Result { let length = value.len(); - // TODO: don't use new_unchecked let geos_objects: Vec> = value .into_iter() - .map(|geom| geom.map(GEOSMultiPoint::new_unchecked)) + .map(|geom| geom.map(|geom| GEOSMultiPoint::try_new(geom)?)) .collect(); let (coord_capacity, geom_capacity) = first_pass(&geos_objects, length); Ok(second_pass( diff --git a/src/io/geos/array/multipolygon.rs b/src/io/geos/array/multipolygon.rs index 06dd1c97..b74cad37 100644 --- a/src/io/geos/array/multipolygon.rs +++ b/src/io/geos/array/multipolygon.rs @@ -188,10 +188,9 @@ impl TryFrom>>> for MutableMul fn try_from(value: Vec>>) -> Result { let length = value.len(); - // TODO: don't use new_unchecked let geos_objects: Vec> = value .into_iter() - .map(|geom| geom.map(GEOSMultiPolygon::new_unchecked)) + .map(|geom| geom.map(|geom| GEOSMultiPolygon::try_new(geom)?)) .collect(); let (coord_capacity, ring_capacity, polygon_capacity, geom_capacity) = diff --git a/src/io/geos/array/point.rs b/src/io/geos/array/point.rs index 718fda72..7daed570 100644 --- a/src/io/geos/array/point.rs +++ b/src/io/geos/array/point.rs @@ -8,10 +8,9 @@ impl<'a> TryFrom>>> for MutablePointArray { fn try_from(value: Vec>>) -> std::result::Result { let length = value.len(); - // TODO: don't use new_unchecked let geos_linestring_objects: Vec> = value .into_iter() - .map(|geom| geom.map(GEOSPoint::new_unchecked)) + .map(|geom| geom.map(|geom| GEOSPoint::try_new(geom)?)) .collect(); Ok(from_nullable_coords( geos_linestring_objects.iter().map(|item| item.as_ref()), diff --git a/src/io/geos/array/polygon.rs b/src/io/geos/array/polygon.rs index de73a29d..8bf3ac46 100644 --- a/src/io/geos/array/polygon.rs +++ b/src/io/geos/array/polygon.rs @@ -116,10 +116,9 @@ impl TryFrom>>> for MutablePol fn try_from(value: Vec>>) -> Result { let length = value.len(); - // TODO: don't use new_unchecked let geos_objects: Vec> = value .into_iter() - .map(|geom| geom.map(GEOSPolygon::new_unchecked)) + .map(|geom| geom.map(|geom| GEOSPolygon::try_new(geom)?)) .collect(); let (coord_capacity, ring_capacity, geom_capacity) = first_pass(&geos_objects, length); @@ -151,10 +150,9 @@ impl<'a, O: OffsetSizeTrait> TryFrom> = value .into_iter() - .map(|geom| geom.map(GEOSPolygon::new_unchecked)) + .map(|geom| geom.map(|geom| GEOSPolygon::try_new(geom)?)) .collect_in(&bump); let (coord_capacity, ring_capacity, geom_capacity) = first_pass(&geos_objects, length); diff --git a/src/io/geos/scalar/linestring.rs b/src/io/geos/scalar/linestring.rs index b754cf0c..5e3f67cc 100644 --- a/src/io/geos/scalar/linestring.rs +++ b/src/io/geos/scalar/linestring.rs @@ -47,15 +47,12 @@ impl<'b, O: OffsetSizeTrait> LineString<'_, O> { pub struct GEOSLineString<'a>(geos::Geometry<'a>); 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())) + } } } diff --git a/src/io/geos/scalar/multilinestring.rs b/src/io/geos/scalar/multilinestring.rs index 27284423..1720056d 100644 --- a/src/io/geos/scalar/multilinestring.rs +++ b/src/io/geos/scalar/multilinestring.rs @@ -33,19 +33,12 @@ impl<'a, 'b, O: OffsetSizeTrait> TryFrom<&'a MultiLineString<'_, O>> for geos::G pub struct GEOSMultiLineString<'a>(pub(crate) geos::Geometry<'a>); impl<'a> GEOSMultiLineString<'a> { - pub fn new_unchecked(geom: geos::Geometry<'a>) -> Self { - Self(geom) - } - - #[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 23f2cc88..51ffdb95 100644 --- a/src/io/geos/scalar/multipoint.rs +++ b/src/io/geos/scalar/multipoint.rs @@ -32,16 +32,12 @@ impl<'a, 'b, O: OffsetSizeTrait> TryFrom<&'a MultiPoint<'_, O>> for geos::Geomet pub struct GEOSMultiPoint<'a>(pub(crate) geos::Geometry<'a>); impl<'a> GEOSMultiPoint<'a> { - pub fn new_unchecked(geom: geos::Geometry<'a>) -> Self { - Self(geom) - } - - #[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 2ed490eb..e2694ec2 100644 --- a/src/io/geos/scalar/multipolygon.rs +++ b/src/io/geos/scalar/multipolygon.rs @@ -33,16 +33,12 @@ impl<'a, 'b, O: OffsetSizeTrait> TryFrom<&'a MultiPolygon<'_, O>> for geos::Geom pub struct GEOSMultiPolygon<'a>(pub(crate) geos::Geometry<'a>); impl<'a> GEOSMultiPolygon<'a> { - pub fn new_unchecked(geom: geos::Geometry<'a>) -> Self { - Self(geom) - } - - #[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 a76835f1..2862a5b9 100644 --- a/src/io/geos/scalar/point.rs +++ b/src/io/geos/scalar/point.rs @@ -33,10 +33,11 @@ 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())) + } } } diff --git a/src/io/geos/scalar/polygon.rs b/src/io/geos/scalar/polygon.rs index 5db3c942..db0f401c 100644 --- a/src/io/geos/scalar/polygon.rs +++ b/src/io/geos/scalar/polygon.rs @@ -39,16 +39,12 @@ impl<'a, 'b, O: OffsetSizeTrait> TryFrom<&'a Polygon<'_, O>> for geos::Geometry< pub struct GEOSPolygon<'a>(pub(crate) geos::Geometry<'a>); impl<'a> GEOSPolygon<'a> { - pub fn new_unchecked(geom: geos::Geometry<'a>) -> Self { - Self(geom) - } - - #[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)]