Trait acap::distance::Proximity [−][src]
pub trait Proximity<T: ?Sized = Self> {
type Distance: Distance;
fn distance(&self, other: &T) -> Self::Distance;
}
Expand description
A space with some notion of distance between points.
There are no restrictions on the distances returned by spaces that implement only Proximity
.
In particular, they may be asymmetric or even negative. If a space meets the restrictions of
the Metric
trait, it should be implemented as well. Spaces that satisfy those rules, at
least approximately, often allow for more accurate and efficient searches.
Proximity<T>
is generic, to allow comparisons between objects of related but distinct types.
For example:
// A GPS coordinate
struct Gps {
lat: f64,
long: f64,
}
// For computing distances between GPS coordinates
impl Proximity for Gps {
type Distance = HaversineDistance;
fn distance(&self, other: &Self) -> Self::Distance {
haversine_distance(self, other)
}
}
// A point of interest with a known location, name, ...
struct PointOfInterest {
location: Gps,
name: String,
// ...
}
// Compute the distance between a GPS coordinate and a point of interest,
// by delegating to the Proximity impl for Gps
impl Proximity<PointOfInterest> for Gps {
type Distance = <Gps as Proximity>::Distance;
fn distance(&self, other: &PointOfInterest) -> Self::Distance {
self.distance(&other.location)
}
}
With those implementations available, you could use a NearestNeighbors<Gps, PointOfInterest>
instance to find the closest point(s) of interest to any GPS location.
Associated Types
Required methods
Implementations on Foreign Types
Blanket Proximity
implementation for references.
Implementors
impl<T> Proximity<Angular<T>> for Angular<T> where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
impl<T> Proximity<Angular<T>> for Angular<T> where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
type Distance = AngularDistance<T::Value>
impl<T> Proximity<Angular<T>> for T where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
impl<T> Proximity<Angular<T>> for T where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
type Distance = AngularDistance<T::Value>
impl<T> Proximity<PrenormAngular<T>> for PrenormAngular<T> where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
impl<T> Proximity<PrenormAngular<T>> for PrenormAngular<T> where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
type Distance = AngularDistance<T::Value>
impl<T> Proximity<PrenormAngular<T>> for T where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
impl<T> Proximity<PrenormAngular<T>> for T where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
type Distance = AngularDistance<T::Value>
impl<T> Proximity<Euclidean<T>> for Euclidean<T> where
T: Coordinates,
EuclideanDistance<T::Value>: Distance,
impl<T> Proximity<Euclidean<T>> for Euclidean<T> where
T: Coordinates,
EuclideanDistance<T::Value>: Distance,
The Euclidean distance function.
type Distance = EuclideanDistance<T::Value>
impl<T> Proximity<Euclidean<T>> for T where
T: Coordinates,
EuclideanDistance<T::Value>: Distance,
impl<T> Proximity<Euclidean<T>> for T where
T: Coordinates,
EuclideanDistance<T::Value>: Distance,
type Distance = EuclideanDistance<T::Value>
impl<T> Proximity<T> for Angular<T> where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
impl<T> Proximity<T> for Angular<T> where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
type Distance = AngularDistance<T::Value>
impl<T> Proximity<T> for PrenormAngular<T> where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
impl<T> Proximity<T> for PrenormAngular<T> where
T: Coordinates,
T::Value: Real,
AngularDistance<T::Value>: Distance,
type Distance = AngularDistance<T::Value>
impl<T> Proximity<T> for Euclidean<T> where
T: Coordinates,
EuclideanDistance<T::Value>: Distance,
impl<T> Proximity<T> for Euclidean<T> where
T: Coordinates,
EuclideanDistance<T::Value>: Distance,
type Distance = EuclideanDistance<T::Value>
The Chebyshev distance function.
The taxicab distance function.
The hamming distance function.