Skip to content

Commit

Permalink
Replace manual ObjectRef with rstar ObjectRef
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Nov 4, 2024
1 parent 5a86f6a commit b2c635b
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions geo/src/algorithm/bool_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -228,21 +230,6 @@ impl<T: BoolOpsNum> BooleanOps for MultiPolygon<T> {
}
}

// 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,
Expand All @@ -255,17 +242,17 @@ where
// these three functions drive the union operation
let init = || MultiPolygon::<T>::new(vec![]);
let fold = |mut accum: MultiPolygon<T>,
poly: &CachedEnvelope<RTreeObjectRef<'a, Boppable>>|
poly: &CachedEnvelope<ObjectRef<'a, Boppable>>|
-> MultiPolygon<T> {
accum = accum.union(poly.0);
accum = accum.union(&***poly);
accum
};
let reduce = |accum1: MultiPolygon<T>, accum2: MultiPolygon<T>| -> MultiPolygon<T> {
accum1.union(&accum2)
};
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)
Expand Down

0 comments on commit b2c635b

Please sign in to comment.