# [−][src]Trait acap::distance::Distance

pub trait Distance where    Self: Copy,    Self: Into<Self::Value>,    Self: PartialOrd<Self::Value>,    Self::Value: PartialOrd<Self>,    Self: PartialOrd, {
type Value: Value;
fn value(self) -> Self::Value { ... }
}

A distance between two points.

An implementation may be an actual numerical distance, or an order embedding of the true distance. This allows for optimizations whenever distances can be compared more efficiently than their exact values can be computed. Implementors must satisfy, for all distances $x$ and $y$:

\begin{aligned}
x.\mathrm{value}() &< y.\mathrm{value}() & &\iff& x.\mathrm{value}() &< y \\
& & &\iff& x &< y.\mathrm{value}() \\
& & &\iff& x &< y
\end{aligned}


Any monotonically increasing function can be used to create an order embedding. For example, EuclideanDistance holds a squared distance, rather than the distance itself. Comparisons still behave correctly because $x \mapsto x^2$ is an increasing function. This lets us avoid computing relatively expensive square roots until we need the value() itself, at which point the inverse function $x \mapsto \sqrt{x}$ must be applied.

## Associated Types

### type Value: Value

The type of actual numerical distances.

## Provided methods

### fn value(self) -> Self::Value

Get the real numerical value of this distance.

## Implementors

### impl<T: Value> Distance for T[src]

Any numerical distance value can be a Distance.