Skip to content

Commit

Permalink
Merge pull request #1254 from urschrei/rstar_multipolygon
Browse files Browse the repository at this point in the history
Add rstar MultiPolygon compat
  • Loading branch information
urschrei authored Nov 6, 2024
2 parents ab9856f + d6f0d5a commit f82349e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions geo-types/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 34 additions & 0 deletions geo-types/src/geometry/multi_polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> $rstar::RTreeObject for MultiPolygon<T>
where
T: ::num_traits::Float + ::$rstar::RTreeNum,
{
type Envelope = ::$rstar::AABB<$crate::Point<T>>;
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::*;
Expand Down

0 comments on commit f82349e

Please sign in to comment.