From 0e583a8afe67116f69461ee0d9be84d448ba7b38 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 2 Dec 2024 15:00:36 -0800 Subject: [PATCH] Remove unnecessary bounds from trait impl --- geo/CHANGES.md | 5 +++ geo/src/algorithm/remove_repeated_points.rs | 46 ++++----------------- 2 files changed, 14 insertions(+), 37 deletions(-) diff --git a/geo/CHANGES.md b/geo/CHANGES.md index 6ced3ee2e4..e33b422d81 100644 --- a/geo/CHANGES.md +++ b/geo/CHANGES.md @@ -1,5 +1,10 @@ # Changes +## Unreleased + +- Loosen bounds on `RemoveRepeatedPoints` trait (`num_traits::FromPrimitive` isn't required) + - + ## 0.29.3 - 2024.12.03 - Fix crash in `BoolOps` by updating `i_overlay` to 1.9.0. diff --git a/geo/src/algorithm/remove_repeated_points.rs b/geo/src/algorithm/remove_repeated_points.rs index bfd2233fc2..4f112ff3e2 100644 --- a/geo/src/algorithm/remove_repeated_points.rs +++ b/geo/src/algorithm/remove_repeated_points.rs @@ -3,7 +3,6 @@ use crate::{ Polygon, Rect, Triangle, }; use geo_types::GeometryCollection; -use num_traits::FromPrimitive; /// Remove repeated points from a `MultiPoint` and repeated consecutive coordinates /// from `LineString`, `Polygon`, `MultiLineString` and `MultiPolygon`. @@ -12,20 +11,14 @@ use num_traits::FromPrimitive; /// of each geometry in the collection. /// /// For `Point`, `Line`, `Rect` and `Triangle` the geometry remains the same. -pub trait RemoveRepeatedPoints -where - T: CoordNum + FromPrimitive, -{ +pub trait RemoveRepeatedPoints { /// Create a new geometry with (consecutive) repeated points removed. fn remove_repeated_points(&self) -> Self; /// Remove (consecutive) repeated points inplace. fn remove_repeated_points_mut(&mut self); } -impl RemoveRepeatedPoints for MultiPoint -where - T: CoordNum + FromPrimitive, -{ +impl RemoveRepeatedPoints for MultiPoint { /// Create a MultiPoint with repeated points removed. fn remove_repeated_points(&self) -> Self { let mut points = vec![]; @@ -49,10 +42,7 @@ where } } -impl RemoveRepeatedPoints for LineString -where - T: CoordNum + FromPrimitive, -{ +impl RemoveRepeatedPoints for LineString { /// Create a LineString with consecutive repeated points removed. fn remove_repeated_points(&self) -> Self { let mut coords = self.0.clone(); @@ -66,10 +56,7 @@ where } } -impl RemoveRepeatedPoints for Polygon -where - T: CoordNum + FromPrimitive, -{ +impl RemoveRepeatedPoints for Polygon { /// Create a Polygon with consecutive repeated points removed. fn remove_repeated_points(&self) -> Self { Polygon::new( @@ -92,10 +79,7 @@ where } } -impl RemoveRepeatedPoints for MultiLineString -where - T: CoordNum + FromPrimitive, -{ +impl RemoveRepeatedPoints for MultiLineString { /// Create a MultiLineString with consecutive repeated points removed. fn remove_repeated_points(&self) -> Self { MultiLineString::new( @@ -114,10 +98,7 @@ where } } -impl RemoveRepeatedPoints for MultiPolygon -where - T: CoordNum + FromPrimitive, -{ +impl RemoveRepeatedPoints for MultiPolygon { /// Create a MultiPolygon with consecutive repeated points removed. fn remove_repeated_points(&self) -> Self { MultiPolygon::new(self.0.iter().map(|p| p.remove_repeated_points()).collect()) @@ -136,10 +117,7 @@ where // and `remove_repeated_points_mut` is a no-op. macro_rules! impl_for_not_candidate_types { ($type:ident) => { - impl RemoveRepeatedPoints for $type - where - T: CoordNum + FromPrimitive, - { + impl RemoveRepeatedPoints for $type { fn remove_repeated_points(&self) -> Self { self.clone() } @@ -156,10 +134,7 @@ impl_for_not_candidate_types!(Rect); impl_for_not_candidate_types!(Triangle); impl_for_not_candidate_types!(Line); -impl RemoveRepeatedPoints for GeometryCollection -where - T: CoordNum + FromPrimitive, -{ +impl RemoveRepeatedPoints for GeometryCollection { /// Create a GeometryCollection with (consecutive) repeated points /// of its geometries removed. fn remove_repeated_points(&self) -> Self { @@ -174,10 +149,7 @@ where } } -impl RemoveRepeatedPoints for Geometry -where - T: CoordNum + FromPrimitive, -{ +impl RemoveRepeatedPoints for Geometry { // The following couldn't be used for implementing `remove_repeated_points` until // "impl From> for Geometry" is implemented // (see geo-types/src/geometry/mod.rs, lines 101-106) so we implement it manually for now