diff --git a/src/lib.rs b/src/lib.rs index a619039..84b0d8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(allocator_api)] + use std::{ collections::HashMap, sync::{Mutex, RwLock}, @@ -156,10 +158,21 @@ impl Spindex2d { /// Search within a given `radius` from `point`. pub fn radius(&self, point: &Point2d, radius: f64) -> Vec { let d2 = radius.powi(2); - self.aabb(point, radius * 2.0) - .into_iter() - .filter(|v| v.distance_squared(point) <= d2) - .collect() + + let points = self.aabb(point, radius * 2.0); + let mut alloc = self.alloc.lock().unwrap(); + let neighbors = { + let mut neighbors = Vec::new_in(alloc.local()); + for neighbor in points.into_iter() { + if neighbor.distance_squared(point) <= d2 { + neighbors.push(neighbor); + } + } + + neighbors.to_vec() + }; + alloc.reset(); + neighbors } /// Search an axis-aligned bounding box whose sides are `span` away from the given point.