[][src]Trait acap::distance::Proximity

pub trait Proximity<T: ?Sized = Self> {
    type Distance: Distance;
    fn distance(&self, other: &T) -> Self::Distance;
}

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

type Distance: Distance

The type that represents distances.

Loading content...

Required methods

fn distance(&self, other: &T) -> Self::Distance

Calculate the distance between this point and another one.

Loading content...

Implementations on Foreign Types

impl<'k, 'v, K: Proximity<V>, V> Proximity<&'v V> for &'k K[src]

Blanket Proximity implementation for references.

type Distance = K::Distance

Loading content...

Implementors

impl<T> Proximity<Angular<T>> for Angular<T> where
    T: Coordinates,
    T::Value: Real,
    AngularDistance<T::Value>: Distance
[src]

type Distance = AngularDistance<T::Value>

impl<T> Proximity<Angular<T>> for T where
    T: Coordinates,
    T::Value: Real,
    AngularDistance<T::Value>: Distance
[src]

type Distance = AngularDistance<T::Value>

impl<T> Proximity<Cosine<T>> for Cosine<T> where
    T: Coordinates,
    T::Value: Real
[src]

type Distance = T::Value

impl<T> Proximity<Cosine<T>> for T where
    T: Coordinates,
    T::Value: Real
[src]

type Distance = T::Value

impl<T> Proximity<PrenormAngular<T>> for PrenormAngular<T> where
    T: Coordinates,
    T::Value: Real,
    AngularDistance<T::Value>: Distance
[src]

type Distance = AngularDistance<T::Value>

impl<T> Proximity<PrenormAngular<T>> for T where
    T: Coordinates,
    T::Value: Real,
    AngularDistance<T::Value>: Distance
[src]

type Distance = AngularDistance<T::Value>

impl<T> Proximity<PrenormCosine<T>> for PrenormCosine<T> where
    T: Coordinates,
    T::Value: Real
[src]

type Distance = T::Value

impl<T> Proximity<PrenormCosine<T>> for T where
    T: Coordinates,
    T::Value: Real
[src]

type Distance = T::Value

impl<T> Proximity<Euclidean<T>> for Euclidean<T> where
    T: Coordinates,
    EuclideanDistance<T::Value>: Distance
[src]

The Euclidean distance function.

type Distance = EuclideanDistance<T::Value>

impl<T> Proximity<Euclidean<T>> for T where
    T: Coordinates,
    EuclideanDistance<T::Value>: Distance
[src]

type Distance = EuclideanDistance<T::Value>

impl<T> Proximity<T> for Angular<T> where
    T: Coordinates,
    T::Value: Real,
    AngularDistance<T::Value>: Distance
[src]

type Distance = AngularDistance<T::Value>

impl<T> Proximity<T> for Cosine<T> where
    T: Coordinates,
    T::Value: Real
[src]

type Distance = T::Value

impl<T> Proximity<T> for PrenormAngular<T> where
    T: Coordinates,
    T::Value: Real,
    AngularDistance<T::Value>: Distance
[src]

type Distance = AngularDistance<T::Value>

impl<T> Proximity<T> for PrenormCosine<T> where
    T: Coordinates,
    T::Value: Real
[src]

type Distance = T::Value

impl<T> Proximity<T> for Euclidean<T> where
    T: Coordinates,
    EuclideanDistance<T::Value>: Distance
[src]

type Distance = EuclideanDistance<T::Value>

impl<T: Coordinates> Proximity<Chebyshev<T>> for Chebyshev<T>[src]

The Chebyshev distance function.

type Distance = T::Value

impl<T: Coordinates> Proximity<Chebyshev<T>> for T[src]

type Distance = T::Value

impl<T: Coordinates> Proximity<Taxicab<T>> for Taxicab<T>[src]

The taxicab distance function.

type Distance = T::Value

impl<T: Coordinates> Proximity<Taxicab<T>> for T[src]

type Distance = T::Value

impl<T: Coordinates> Proximity<T> for Chebyshev<T>[src]

type Distance = T::Value

impl<T: Coordinates> Proximity<T> for Taxicab<T>[src]

type Distance = T::Value

impl<T: PrimInt> Proximity<Hamming<T>> for Hamming<T>[src]

The hamming distance function.

type Distance = i32

impl<T: PrimInt> Proximity<T> for Hamming<T>[src]

type Distance = i32

impl<T: PrimInt> Proximity<Hamming<T>> for T[src]

type Distance = i32

Loading content...