From b2c635b9b02cdeaefb9422309784217c65dd5c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Mon, 4 Nov 2024 11:24:25 +0000 Subject: [PATCH] Replace manual ObjectRef with rstar ObjectRef --- geo/src/algorithm/bool_ops/mod.rs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/geo/src/algorithm/bool_ops/mod.rs b/geo/src/algorithm/bool_ops/mod.rs index c5bfa3a12..23f6a0b65 100644 --- a/geo/src/algorithm/bool_ops/mod.rs +++ b/geo/src/algorithm/bool_ops/mod.rs @@ -5,7 +5,9 @@ mod tests; pub use i_overlay_integration::BoolOpsNum; use crate::geometry::{LineString, MultiLineString, MultiPolygon, Polygon}; -use rstar::{primitives::CachedEnvelope, ParentNode, RTree, RTreeNode, RTreeObject}; +use rstar::{ + primitives::CachedEnvelope, primitives::ObjectRef, ParentNode, RTree, RTreeNode, RTreeObject, +}; /// Boolean Operations on geometry. /// @@ -228,21 +230,6 @@ impl BooleanOps for MultiPolygon { } } -// This struct and its RTReeObject impl allow construction of an R tree containing short-lived -// references to the original objects. -struct RTreeObjectRef<'a, T>(&'a T); - -impl<'a, T> RTreeObject for RTreeObjectRef<'a, T> -where - T: RTreeObject, -{ - type Envelope = T::Envelope; - - fn envelope(&self) -> Self::Envelope { - self.0.envelope() - } -} - impl<'a, T, Boppable, BoppableCollection> UnaryUnion for &'a BoppableCollection where T: BoolOpsNum, @@ -255,9 +242,9 @@ where // these three functions drive the union operation let init = || MultiPolygon::::new(vec![]); let fold = |mut accum: MultiPolygon, - poly: &CachedEnvelope>| + poly: &CachedEnvelope>| -> MultiPolygon { - accum = accum.union(poly.0); + accum = accum.union(&***poly); accum }; let reduce = |accum1: MultiPolygon, accum2: MultiPolygon| -> MultiPolygon { @@ -265,7 +252,7 @@ where }; let rtree = RTree::bulk_load( self.into_iter() - .map(|p| CachedEnvelope::new(RTreeObjectRef(p))) + .map(|p| CachedEnvelope::new(ObjectRef::new(p))) .collect(), ); bottom_up_fold_reduce(&rtree, init, fold, reduce)