use the bump allocator for radius, doesn't help much
This commit is contained in:
parent
d28d212821
commit
132e38e050
1 changed files with 17 additions and 4 deletions
21
src/lib.rs
21
src/lib.rs
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![feature(allocator_api)]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{Mutex, RwLock},
|
sync::{Mutex, RwLock},
|
||||||
|
|
@ -156,10 +158,21 @@ impl Spindex2d {
|
||||||
/// Search within a given `radius` from `point`.
|
/// Search within a given `radius` from `point`.
|
||||||
pub fn radius(&self, point: &Point2d, radius: f64) -> Vec<Point2d> {
|
pub fn radius(&self, point: &Point2d, radius: f64) -> Vec<Point2d> {
|
||||||
let d2 = radius.powi(2);
|
let d2 = radius.powi(2);
|
||||||
self.aabb(point, radius * 2.0)
|
|
||||||
.into_iter()
|
let points = self.aabb(point, radius * 2.0);
|
||||||
.filter(|v| v.distance_squared(point) <= d2)
|
let mut alloc = self.alloc.lock().unwrap();
|
||||||
.collect()
|
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.
|
/// Search an axis-aligned bounding box whose sides are `span` away from the given point.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue