Added distance_squared_to_nearest

This commit is contained in:
Olek 2016-12-31 03:32:20 +01:00
parent e6755865f0
commit 2b4539f331
2 changed files with 6 additions and 2 deletions

View File

@ -71,7 +71,11 @@ impl<KdtreePoint: KdtreePointTrait> Kdtree<KdtreePoint> {
pub fn has_neighbor_in_range(&self, node: &KdtreePoint, range: f64) -> bool { pub fn has_neighbor_in_range(&self, node: &KdtreePoint, range: f64) -> bool {
let squared_range = range * range; let squared_range = range * range;
squared_euclidean(&self.nearest_search(node).dims(), node.dims()) <= squared_range self.distance_squared_to_nearest(node) <= squared_range
}
pub fn distance_squared_to_nearest(&self, node: &KdtreePoint) -> f64 {
squared_euclidean(&self.nearest_search(node).dims(), node.dims())
} }
pub fn insert_node(&mut self, node_to_add : KdtreePoint) { pub fn insert_node(&mut self, node_to_add : KdtreePoint) {

View File

@ -10,7 +10,7 @@ fn gen_random() -> f64 {
rand::thread_rng().gen_range(0., 10000.) rand::thread_rng().gen_range(0., 10000.)
} }
fn find_nn_with_linear_search<'a>(points : &'a Vec<Point3WithId>, find_for : Point3WithId) -> &Point3WithId { fn find_nn_with_linear_search(points : &Vec<Point3WithId>, find_for : Point3WithId) -> &Point3WithId {
let distance_fun = kdtree::kdtree::distance::squared_euclidean; let distance_fun = kdtree::kdtree::distance::squared_euclidean;