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

The type that represents distances.

Required methods

Calculate the distance between this point and another one.

Implementations on Foreign Types

Blanket Proximity implementation for references.

Implementors

The Euclidean distance function.

The Chebyshev distance function.

The taxicab distance function.

The hamming distance function.