diff --git a/geo-types/src/coordinate.rs b/geo-types/src/coordinate.rs index 9b720d910..a5df8c612 100644 --- a/geo-types/src/coordinate.rs +++ b/geo-types/src/coordinate.rs @@ -1,5 +1,8 @@ use crate::{coord, CoordNum, Point}; +#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))] +use crate::CoordFloat; + #[cfg(any(feature = "approx", test))] use approx::{AbsDiffEq, RelativeEq, UlpsEq}; @@ -303,7 +306,7 @@ where #[cfg(feature = "rstar_0_8")] impl ::rstar_0_8::Point for Coordinate where - T: ::num_traits::Float + ::rstar_0_8::RTreeNum, + T: CoordFloat + ::rstar_0_8::RTreeNum, { type Scalar = T; @@ -336,7 +339,7 @@ where #[cfg(feature = "rstar_0_9")] impl ::rstar_0_9::Point for Coordinate where - T: ::num_traits::Float + ::rstar_0_9::RTreeNum, + T: CoordFloat + ::rstar_0_9::RTreeNum, { type Scalar = T; diff --git a/geo-types/src/geometry_collection.rs b/geo-types/src/geometry_collection.rs index da022b809..59557c246 100644 --- a/geo-types/src/geometry_collection.rs +++ b/geo-types/src/geometry_collection.rs @@ -69,18 +69,10 @@ use std::ops::{Index, IndexMut}; /// println!("{:?}", gc[0]); /// ``` /// -#[derive(Eq, PartialEq, Clone, Debug, Hash)] +#[derive(Eq, PartialEq, Clone, Debug, Hash, Default)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct GeometryCollection(pub Vec>); -// Implementing Default by hand because T does not have Default restriction -// todo: consider adding Default as a CoordNum requirement -impl Default for GeometryCollection { - fn default() -> Self { - Self(Vec::new()) - } -} - impl GeometryCollection { /// Return an empty GeometryCollection pub fn new() -> Self { diff --git a/geo-types/src/lib.rs b/geo-types/src/lib.rs index 546e68360..55a9b1343 100644 --- a/geo-types/src/lib.rs +++ b/geo-types/src/lib.rs @@ -76,9 +76,9 @@ impl CoordinateType for T {} /// For algorithms which only make sense for floating point, like area or length calculations, /// see [CoordFloat](trait.CoordFloat.html). #[allow(deprecated)] -pub trait CoordNum: CoordinateType + Debug {} +pub trait CoordNum: CoordinateType + Debug + Default {} #[allow(deprecated)] -impl CoordNum for T {} +impl CoordNum for T {} pub trait CoordFloat: CoordNum + Float {} impl CoordFloat for T {} diff --git a/geo-types/src/line.rs b/geo-types/src/line.rs index fbee02a9d..00b19608f 100644 --- a/geo-types/src/line.rs +++ b/geo-types/src/line.rs @@ -1,3 +1,5 @@ +#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))] +use crate::CoordFloat; use crate::{CoordNum, Coordinate, Point}; #[cfg(any(feature = "approx", test))] use approx::{AbsDiffEq, RelativeEq}; @@ -226,7 +228,7 @@ macro_rules! impl_rstar_line { ($rstar:ident) => { impl ::$rstar::RTreeObject for Line where - T: ::num_traits::Float + ::$rstar::RTreeNum, + T: CoordFloat + ::$rstar::RTreeNum, { type Envelope = ::$rstar::AABB>; @@ -238,7 +240,7 @@ macro_rules! impl_rstar_line { impl ::$rstar::PointDistance for Line where - T: ::num_traits::Float + ::$rstar::RTreeNum, + T: CoordFloat + ::$rstar::RTreeNum, { fn distance_2(&self, point: &Point) -> T { let d = crate::private_utils::point_line_euclidean_distance(*point, *self); diff --git a/geo-types/src/line_string.rs b/geo-types/src/line_string.rs index c8a477be0..9771af61e 100644 --- a/geo-types/src/line_string.rs +++ b/geo-types/src/line_string.rs @@ -1,3 +1,5 @@ +#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))] +use crate::CoordFloat; #[cfg(any(feature = "approx", test))] use approx::{AbsDiffEq, RelativeEq}; @@ -483,7 +485,7 @@ macro_rules! impl_rstar_line_string { ($rstar:ident) => { impl ::$rstar::RTreeObject for LineString where - T: ::num_traits::Float + ::$rstar::RTreeNum, + T: CoordFloat + ::$rstar::RTreeNum, { type Envelope = ::$rstar::AABB>; @@ -505,7 +507,7 @@ macro_rules! impl_rstar_line_string { impl ::$rstar::PointDistance for LineString where - T: ::num_traits::Float + ::$rstar::RTreeNum, + T: CoordFloat + ::$rstar::RTreeNum, { fn distance_2(&self, point: &Point) -> T { let d = crate::private_utils::point_line_string_euclidean_distance(*point, self); diff --git a/geo-types/src/point.rs b/geo-types/src/point.rs index cb704d2a9..0e7db4598 100644 --- a/geo-types/src/point.rs +++ b/geo-types/src/point.rs @@ -551,7 +551,7 @@ where // These are required for rstar RTree impl ::rstar_0_8::Point for Point where - T: ::num_traits::Float + ::rstar_0_8::RTreeNum, + T: CoordFloat + ::rstar_0_8::RTreeNum, { type Scalar = T; @@ -580,7 +580,7 @@ where #[cfg(feature = "rstar_0_9")] impl ::rstar_0_9::Point for Point where - T: ::num_traits::Float + ::rstar_0_9::RTreeNum, + T: CoordFloat + ::rstar_0_9::RTreeNum, { type Scalar = T; diff --git a/geo/CHANGES.md b/geo/CHANGES.md index 5caa1dc97..76c819d93 100644 --- a/geo/CHANGES.md +++ b/geo/CHANGES.md @@ -5,6 +5,7 @@ * Add `LinesIter` algorithm to iterate over the lines in geometries. * Very similar to `CoordsIter`, but only implemented where it makes sense (e.g., for `Polygon`, `Rect`, but not `Point`). * +* BREAKING: Add `Default` constraint to all `CoordNum`/`CoordFloat` values. ## 0.19.0