Trait acap::distance::Distance [−][src]
pub trait Distance where
Self: Copy,
Self: Into<Self::Value>,
Self: PartialOrd<Self::Value>,
Self: PartialOrd, {
type Value: Value + PartialOrd<Self>;
fn value(self) -> Self::Value { ... }
}
Expand description
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 + PartialOrd<Self>
type Value: Value + PartialOrd<Self>
The type of actual numerical distances.