diff --git a/geo-types/CHANGES.md b/geo-types/CHANGES.md index 3387cb661f..79bb76114d 100644 --- a/geo-types/CHANGES.md +++ b/geo-types/CHANGES.md @@ -1,5 +1,8 @@ # Changes +## Unreleased +* Add rstar compatibility for MultiPolygon + ## 0.7.13 * POSSIBLY BREAKING: Minimum supported version of Rust (MSRV) is now 1.70 diff --git a/geo-types/src/geometry/multi_polygon.rs b/geo-types/src/geometry/multi_polygon.rs index 8a0b7d2005..fefeaf8579 100644 --- a/geo-types/src/geometry/multi_polygon.rs +++ b/geo-types/src/geometry/multi_polygon.rs @@ -170,6 +170,40 @@ where } } +#[cfg(any( + feature = "rstar_0_8", + feature = "rstar_0_9", + feature = "rstar_0_10", + feature = "rstar_0_11", + feature = "rstar_0_12" +))] +macro_rules! impl_rstar_multi_polygon { + ($rstar:ident) => { + impl $rstar::RTreeObject for MultiPolygon + where + T: ::num_traits::Float + ::$rstar::RTreeNum, + { + type Envelope = ::$rstar::AABB<$crate::Point>; + fn envelope(&self) -> Self::Envelope { + use ::$rstar::Envelope; + self.iter() + .map(|p| p.envelope()) + .fold(::$rstar::AABB::new_empty(), |a, b| a.merged(&b)) + } + } + }; +} +#[cfg(feature = "rstar_0_8")] +impl_rstar_multi_polygon!(rstar_0_8); +#[cfg(feature = "rstar_0_9")] +impl_rstar_multi_polygon!(rstar_0_9); +#[cfg(feature = "rstar_0_10")] +impl_rstar_multi_polygon!(rstar_0_10); +#[cfg(feature = "rstar_0_11")] +impl_rstar_multi_polygon!(rstar_0_11); +#[cfg(feature = "rstar_0_12")] +impl_rstar_multi_polygon!(rstar_0_12); + #[cfg(test)] mod test { use super::*;