diff --git a/geo-types/src/coordinate.rs b/geo-types/src/coordinate.rs index 28195563ed..19bed62690 100644 --- a/geo-types/src/coordinate.rs +++ b/geo-types/src/coordinate.rs @@ -69,19 +69,19 @@ impl From> for CoordTZM From> for (T, T) { - fn from(coord: Coordinate) -> Self { +impl From> for (T, T) { + fn from(coord: CoordTZM) -> Self { (coord.x, coord.y) } } -impl From> for [T; 2] { - fn from(coord: Coordinate) -> Self { +impl From> for [T; 2] { + fn from(coord: CoordTZM) -> Self { [coord.x, coord.y] } } -impl Coordinate { +impl CoordTZM { /// Returns a tuple that contains the x/horizontal & y/vertical component of the coordinate. /// /// # Examples diff --git a/geo-types/src/geometry.rs b/geo-types/src/geometry.rs index 8e057b4efd..4767786540 100644 --- a/geo-types/src/geometry.rs +++ b/geo-types/src/geometry.rs @@ -1,8 +1,6 @@ use crate::{ - CoordNum, Error, GeometryCollection, GeometryCollectionTZM, Line, LineString, LineStringTZM, - LineTZM, Measure, MultiLineString, MultiLineStringTZM, MultiPoint, MultiPointTZM, MultiPolygon, - MultiPolygonTZM, NoValue, Point, PointTZM, Polygon, PolygonTZM, Rect, RectTZM, Triangle, - TriangleTZM, ZCoord, + CoordNum, Error, GeometryCollectionTZM, LineStringTZM, LineTZM, Measure, MultiLineStringTZM, + MultiPointTZM, MultiPolygonTZM, NoValue, PointTZM, PolygonTZM, RectTZM, TriangleTZM, ZCoord, }; #[cfg(any(feature = "approx", test))] @@ -84,32 +82,32 @@ impl From> for Geom } } -impl From> for Geometry { - fn from(x: Rect) -> Self { +impl From> for GeometryTZM { + fn from(x: RectTZM) -> Self { Self::Rect(x) } } -impl From> for Geometry { - fn from(x: Triangle) -> Self { +impl From> for GeometryTZM { + fn from(x: TriangleTZM) -> Self { Self::Triangle(x) } } macro_rules! try_from_geometry_impl { - ($($type: ident),+) => { + ($(($type: ident, $typeTZM: ident)),+ $(,)? ) => { $( /// Convert a Geometry enum into its inner type. /// /// Fails if the enum case does not match the type you are trying to convert it to. - impl TryFrom> for $type { + impl TryFrom> for $typeTZM { type Error = Error; - fn try_from(geom: Geometry) -> Result { + fn try_from(geom: GeometryTZM) -> Result { match geom { - Geometry::$type(g) => Ok(g), + GeometryTZM::$type(g) => Ok(g), other => Err(Error::MismatchedGeometry { - expected: type_name::<$type>(), + expected: type_name::<$typeTZM>(), found: inner_type_name(other) }) } @@ -119,33 +117,33 @@ macro_rules! try_from_geometry_impl { } } +// `concat_idents` is not available, so hacking around it try_from_geometry_impl!( - Point, - Line, - LineString, - Polygon, - MultiPoint, - MultiLineString, - MultiPolygon, - Rect, - Triangle + (Point, PointTZM), + (Line, LineTZM), + (LineString, LineStringTZM), + (Polygon, PolygonTZM), + (MultiPoint, MultiPointTZM), + (MultiLineString, MultiLineStringTZM), + (MultiPolygon, MultiPolygonTZM), + (Rect, RectTZM), + (Triangle, TriangleTZM), ); -fn inner_type_name(geometry: Geometry) -> &'static str -where - T: CoordNum, -{ +fn inner_type_name( + geometry: GeometryTZM, +) -> &'static str { match geometry { - Geometry::Point(_) => type_name::>(), - Geometry::Line(_) => type_name::>(), - Geometry::LineString(_) => type_name::>(), - Geometry::Polygon(_) => type_name::>(), - Geometry::MultiPoint(_) => type_name::>(), - Geometry::MultiLineString(_) => type_name::>(), - Geometry::MultiPolygon(_) => type_name::>(), - Geometry::GeometryCollection(_) => type_name::>(), - Geometry::Rect(_) => type_name::>(), - Geometry::Triangle(_) => type_name::>(), + GeometryTZM::Point(_) => type_name::>(), + GeometryTZM::Line(_) => type_name::>(), + GeometryTZM::LineString(_) => type_name::>(), + GeometryTZM::Polygon(_) => type_name::>(), + GeometryTZM::MultiPoint(_) => type_name::>(), + GeometryTZM::MultiLineString(_) => type_name::>(), + GeometryTZM::MultiPolygon(_) => type_name::>(), + GeometryTZM::GeometryCollection(_) => type_name::>(), + GeometryTZM::Rect(_) => type_name::>(), + GeometryTZM::Triangle(_) => type_name::>(), } } diff --git a/geo-types/src/line_string.rs b/geo-types/src/line_string.rs index 9719f223e0..63c3ee7db5 100644 --- a/geo-types/src/line_string.rs +++ b/geo-types/src/line_string.rs @@ -1,9 +1,7 @@ #[cfg(any(feature = "approx", test))] use approx::{AbsDiffEq, RelativeEq}; -use crate::{ - CoordNum, CoordTZM, Coordinate, LineTZM, Measure, NoValue, Point, PointTZM, TriangleTZM, ZCoord, -}; +use crate::{CoordNum, CoordTZM, LineTZM, Measure, NoValue, Point, PointTZM, TriangleTZM, ZCoord}; use std::iter::FromIterator; use std::ops::{Index, IndexMut}; @@ -378,25 +376,25 @@ impl<'a, T: CoordNum, Z: ZCoord, M: Measure> IntoIterator for &'a LineStringTZM< } /// Mutably iterate over all the [`Coordinate`]s in this [`LineString`] -impl<'a, T: CoordNum> IntoIterator for &'a mut LineString { - type Item = &'a mut Coordinate; - type IntoIter = ::std::slice::IterMut<'a, Coordinate>; +impl<'a, T: CoordNum, Z: ZCoord, M: Measure> IntoIterator for &'a mut LineStringTZM { + type Item = &'a mut CoordTZM; + type IntoIter = ::std::slice::IterMut<'a, CoordTZM>; - fn into_iter(self) -> ::std::slice::IterMut<'a, Coordinate> { + fn into_iter(self) -> ::std::slice::IterMut<'a, CoordTZM> { self.0.iter_mut() } } -impl Index for LineString { - type Output = Coordinate; +impl Index for LineStringTZM { + type Output = CoordTZM; - fn index(&self, index: usize) -> &Coordinate { + fn index(&self, index: usize) -> &CoordTZM { self.0.index(index) } } -impl IndexMut for LineString { - fn index_mut(&mut self, index: usize) -> &mut Coordinate { +impl IndexMut for LineStringTZM { + fn index_mut(&mut self, index: usize) -> &mut CoordTZM { self.0.index_mut(index) } }