diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-06-27 17:44:36 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-06-27 17:44:36 -0400 |
commit | 49be082296367f90ca717a6cd4100d57823d8b78 (patch) | |
tree | f6fd67f5474f0c13f02b2985f5574dfc9ba63d37 /src | |
parent | 07e61231dff21fda6da32929c0eae82fa44f6517 (diff) | |
download | acap-49be082296367f90ca717a6cd4100d57823d8b78.tar.xz |
Fix some clippy lints
Diffstat (limited to 'src')
-rw-r--r-- | src/kd.rs | 6 | ||||
-rw-r--r-- | src/vp.rs | 16 |
2 files changed, 17 insertions, 5 deletions
@@ -251,6 +251,12 @@ impl<T: Coordinates> KdTree<T> { } } +impl<T: Coordinates> Default for KdTree<T> { + fn default() -> Self { + Self::new() + } +} + impl<T: Coordinates> Extend<T> for KdTree<T> { fn extend<I: IntoIterator<Item = T>>(&mut self, items: I) { if self.root.is_some() { @@ -1,6 +1,6 @@ //! [Vantage-point trees](https://en.wikipedia.org/wiki/Vantage-point_tree). -use crate::distance::{DistanceValue, Metric, Proximity}; +use crate::distance::{Distance, DistanceValue, Metric, Proximity}; use crate::util::Ordered; use crate::{ExactNeighbors, NearestNeighbors, Neighborhood}; @@ -51,11 +51,11 @@ impl<T: Proximity> VpNode<T> { fn balanced_recursive(nodes: &mut [Option<Box<Self>>]) -> Option<Box<Self>> { if let Some((node, children)) = nodes.split_first_mut() { let mut node = node.take().unwrap(); - children.sort_by_cached_key(|x| Ordered::new(Self::box_distance(&node, x))); + children.sort_by_cached_key(|x| Ordered::new(node.distance_to_box(x))); let (inside, outside) = children.split_at_mut(children.len() / 2); if let Some(last) = inside.last() { - node.radius = Self::box_distance(&node, last).into(); + node.radius = node.distance_to_box(last).value(); } node.inside = Self::balanced_recursive(inside); @@ -68,8 +68,8 @@ impl<T: Proximity> VpNode<T> { } /// Get the distance between to boxed nodes. - fn box_distance(node: &Box<Self>, child: &Option<Box<Self>>) -> T::Distance { - node.item.distance(&child.as_ref().unwrap().item) + fn distance_to_box(&self, child: &Option<Box<Self>>) -> T::Distance { + self.item.distance(&child.as_ref().unwrap().item) } /// Push a new item into this subtree. @@ -255,6 +255,12 @@ where } } +impl<T: Proximity> Default for VpTree<T> { + fn default() -> Self { + Self::new() + } +} + impl<T: Proximity> Extend<T> for VpTree<T> { fn extend<I: IntoIterator<Item = T>>(&mut self, items: I) { if self.root.is_some() { |