summaryrefslogtreecommitdiffstats
path: root/src/euclid.rs
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-07-06 22:24:02 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-07-06 22:33:10 -0400
commit5f85a59d4be37d350bcf1ee62c25ac1f84d71770 (patch)
tree8fc7ea8e59226c5e677d7b9aef39b0b2be5f28b7 /src/euclid.rs
parented4d7b7143f1a8a9602698ca3e60e18bbb4dd226 (diff)
downloadacap-5f85a59d4be37d350bcf1ee62c25ac1f84d71770.tar.xz
kd: Use a more traditional k-d tree implementation
The slight extra pruning possible in the previous implementation didn't seem to be worth it. The new, simpler implementation is also about 30% faster in most of the benchmarks. This gets rid of Coordinate{Proximity,Metric} as they're not necessary any more (and the old ExactNeighbors impl was too restrictive anyway).
Diffstat (limited to 'src/euclid.rs')
-rw-r--r--src/euclid.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/euclid.rs b/src/euclid.rs
index 3833146..3ec0af9 100644
--- a/src/euclid.rs
+++ b/src/euclid.rs
@@ -1,7 +1,8 @@
//! [Euclidean space](https://en.wikipedia.org/wiki/Euclidean_space).
-use crate::coords::{CoordinateMetric, CoordinateProximity, Coordinates};
+use crate::coords::Coordinates;
use crate::distance::{Distance, Metric, Proximity, Value};
+use crate::lp::Minkowski;
use num_traits::zero;
@@ -128,19 +129,20 @@ where
EuclideanDistance<T::Value>: Distance,
{}
-impl<T> CoordinateProximity<T::Value> for Euclidean<T>
+/// Euclidean distance is a [Minkowski] distance.
+impl<T> Minkowski for Euclidean<T>
where
T: Coordinates,
EuclideanDistance<T::Value>: Distance,
-{
- type Distance = EuclideanDistance<T::Value>;
+{}
- fn distance_to_coords(&self, coords: &[T::Value]) -> Self::Distance {
- euclidean_distance(self, coords)
- }
-}
+impl<T> Minkowski<T> for Euclidean<T>
+where
+ T: Coordinates,
+ EuclideanDistance<T::Value>: Distance,
+{}
-impl<T> CoordinateMetric<T::Value> for Euclidean<T>
+impl<T> Minkowski<Euclidean<T>> for T
where
T: Coordinates,
EuclideanDistance<T::Value>: Distance,