pub trait DistanceStrategy<A: Geometry, B: Geometry> {
type Out: CoordinateScalar;
type Comparable: DistanceStrategy<A, B, Out = Self::Out>;
// Required methods
fn distance(&self, a: &A, b: &B) -> Self::Out;
fn comparable(&self) -> Self::Comparable;
}Expand description
A strategy for computing the distance between two geometries.
Mirrors the per-CS strategy concept declared in
boost/geometry/strategies/distance.hpp and refined per
coordinate system in strategies/{cartesian,spherical,geographic}/ distance_*.hpp. The Boost concept exposes
apply(g1, g2) plus a return_type<G1, G2> metafunction plus a
comparable_type<...> sibling; we collapse those three onto one
Rust trait via associated types.
§Associated items
Self::Out— the scalar the distance comes back as. Equivalent to Boost’sboost::geometry::strategy::distance::services::return_type<...>(strategies/distance/services.hpp). Typically the wider ofA’s andB’s coordinate scalars after promotion.Self::Comparable— the “skip the sqrt” form of this strategy. For Pythagoras this isComparablePythagoras; for strategies where there is nothing to save by deferring a square root (Andoyer, Vincenty), settype Comparable = Self;and the optimiser collapses the indirection. Mirrorscomparable_type<...>from the same Boost services header.
§Method shape
distance(&self, &A, &B) mirrors apply(g1, g2) on Boost’s
strategy structs (e.g.
strategies/cartesian/distance_pythagoras.hpp:75-95 for the
comparable form, :99-115 for the sqrt-paying form).
comparable(&self) mirrors get_comparable(strategy) from
strategies/distance/services.hpp.
Required Associated Types§
Sourcetype Out: CoordinateScalar
type Out: CoordinateScalar
The output scalar type. Typically the promoted scalar of
A and B. Mirrors
services::return_type<Strategy, P1, P2>::type from
strategies/distance/services.hpp.
Sourcetype Comparable: DistanceStrategy<A, B, Out = Self::Out>
type Comparable: DistanceStrategy<A, B, Out = Self::Out>
The “skip the sqrt” form of this strategy.
For Pythagoras → ComparablePythagoras (returns squared
distance). For strategies where there is no win from a
comparable form (Vincenty, Andoyer), type Comparable = Self;
— the optimiser collapses it. Mirrors
comparable_type<Strategy>::type from
strategies/distance/services.hpp.
The bound DistanceStrategy<A, B, Out = Self::Out> enforces
the invariant that comparing two comparable distances gives
the same ordering as comparing two real distances — both
sides of the comparison must speak the same scalar type.
Required Methods§
Sourcefn distance(&self, a: &A, b: &B) -> Self::Out
fn distance(&self, a: &A, b: &B) -> Self::Out
Compute the distance between a and b.
Mirrors apply(g1, g2) on Boost strategy structs (e.g.
strategies/cartesian/distance_pythagoras.hpp:99-115).
Sourcefn comparable(&self) -> Self::Comparable
fn comparable(&self) -> Self::Comparable
Return the comparable-form companion of this strategy.
Mirrors services::get_comparable(strategy) from
strategies/distance/services.hpp — most concrete strategies
implement it as a no-op constructor of the sibling
comparable::* type.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl<A, B, S> DistanceStrategy<B, A> for Reversed<S>
impl<A, B, S> DistanceStrategy<B, A> for Reversed<S>
type Out = <S as DistanceStrategy<A, B>>::Out
type Comparable = Reversed<<S as DistanceStrategy<A, B>>::Comparable>
Source§impl<P1, P2> DistanceStrategy<P1, P2> for Andoyerwhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
Available on crate feature std only.Andoyer on f64 geographic points.
impl<P1, P2> DistanceStrategy<P1, P2> for Andoyerwhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
std only.Andoyer on f64 geographic points.
Mirrors formula::andoyer_inverse<CT, true, false>::apply at
formulas/andoyer_inverse.hpp:58-123 — the distance-only branch
(EnableDistance = true, all other flags false). Computes:
cos_d = sin(lat1)·sin(lat2) + cos(lat1)·cos(lat2)·cos(Δlon)
d = acos(cos_d)
K = (sin(lat1) − sin(lat2))²
L = (sin(lat1) + sin(lat2))²
H = (d + 3·sin_d) / (1 − cos_d)
G = (d − 3·sin_d) / (1 + cos_d)
dd = −(f/4) · (H·K + G·L)
result = a · (d + dd)with the degenerate 1 ± cos_d == 0 branches falling back to
H = 0 / G = 0 as in
formulas/andoyer_inverse.hpp:111-117.
§Diagnostics on mis-paired CS
A caller who pairs a Cartesian or Spherical point with Andoyer
hits the <P::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>
bound below and gets the redirect plate on
geometry_tag::SameAs pointing them at
WithCs<_, Geographic<…>> or at the Cartesian / Spherical
strategies. See T31 and proposal §3.7.
Source§impl<P1, P2> DistanceStrategy<P1, P2> for ComparableHaversinewhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily>,
Available on crate feature std only.
impl<P1, P2> DistanceStrategy<P1, P2> for ComparableHaversinewhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily>,
std only.type Out = f64
type Comparable = ComparableHaversine
Source§impl<P1, P2> DistanceStrategy<P1, P2> for ComparablePythagoraswhere
P1: Point,
P2: Point<Scalar = P1::Scalar>,
<P1::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,
impl<P1, P2> DistanceStrategy<P1, P2> for ComparablePythagoraswhere
P1: Point,
P2: Point<Scalar = P1::Scalar>,
<P1::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,
type Out = <P1 as Point>::Scalar
type Comparable = ComparablePythagoras
Source§impl<P1, P2> DistanceStrategy<P1, P2> for Haversinewhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily>,
Available on crate feature std only.Haversine on f64 spherical points.
impl<P1, P2> DistanceStrategy<P1, P2> for Haversinewhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily>,
std only.Haversine on f64 spherical points.
Mirrors the apply(p1, p2) member of
boost::geometry::strategy::distance::haversine at
strategies/spherical/distance_haversine.hpp:188-199:
d = 2 · R · asin(sqrt(h))
where h = sin²(Δlat/2) + cos(lat1)·cos(lat2)·sin²(Δlon/2)§Diagnostics on mis-paired CS
A caller who pairs a Cartesian or Geographic point with
Haversine hits the <P::Cs as CoordinateSystem>::Family: SameAs<SphericalFamily> bound below and gets the redirect plate
on geometry_tag::SameAs pointing them at
WithCs<_, Spherical<…>> or at the geographic strategies
(Andoyer, Vincenty). See T31 and proposal §3.7.
type Out = f64
type Comparable = ComparableHaversine
Source§impl<P1, P2> DistanceStrategy<P1, P2> for KarneyInversewhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
Available on crate feature std only.
impl<P1, P2> DistanceStrategy<P1, P2> for KarneyInversewhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
std only.type Out = f64
type Comparable = KarneyInverse
Source§impl<P1, P2> DistanceStrategy<P1, P2> for Pythagoraswhere
P1: Point,
P2: Point<Scalar = P1::Scalar>,
<P1::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,
impl<P1, P2> DistanceStrategy<P1, P2> for Pythagoraswhere
P1: Point,
P2: Point<Scalar = P1::Scalar>,
<P1::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,
type Out = <P1 as Point>::Scalar
type Comparable = ComparablePythagoras
Source§impl<P1, P2> DistanceStrategy<P1, P2> for Rhumbwhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64, Cs = P1::Cs>,
P1::Cs: HasAngularUnits + CoordinateSystem,
<P1::Cs as CoordinateSystem>::Family: RhumbFamily,
impl<P1, P2> DistanceStrategy<P1, P2> for Rhumbwhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64, Cs = P1::Cs>,
P1::Cs: HasAngularUnits + CoordinateSystem,
<P1::Cs as CoordinateSystem>::Family: RhumbFamily,
Source§impl<P1, P2> DistanceStrategy<P1, P2> for Thomaswhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
Available on crate feature std only.Thomas on f64 geographic points.
impl<P1, P2> DistanceStrategy<P1, P2> for Thomaswhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
std only.Thomas on f64 geographic points.
Mirrors formula::thomas_inverse<CT, true, false>::apply at
formulas/thomas_inverse.hpp:59-215 — the distance-only branch
(EnableDistance = true, all other flags false). The full
derivation lives in Paul D. Thomas, Mathematical Models for
Navigation Systems, 1965, and Spheroidal Geodesics, Reference
Systems, and Local Geometry, 1970.
§Diagnostics on mis-paired CS
A caller who pairs a Cartesian or Spherical point with Thomas
hits the <P::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>
bound below and gets the redirect plate on
geometry_tag::SameAs pointing them at
WithCs<_, Geographic<…>> or at the Cartesian / Spherical
strategies. See T31 and proposal §3.7.
Source§impl<P1, P2> DistanceStrategy<P1, P2> for Vincentywhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
Available on crate feature std only.Vincenty on f64 geographic points.
impl<P1, P2> DistanceStrategy<P1, P2> for Vincentywhere
P1: Point<Scalar = f64>,
P2: Point<Scalar = f64>,
P1::Cs: HasAngularUnits,
P2::Cs: HasAngularUnits,
<P1::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
<P2::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>,
std only.Vincenty on f64 geographic points.
Mirrors formula::vincenty_inverse<CT, true, false>::apply at
formulas/vincenty_inverse.hpp:67-188 — the distance-only branch.
Iterates λ on the auxiliary sphere until either successive λ
differ by less than self.tolerance, |λ| exits the (−π, π)
interval, or self.max_iterations is reached, then evaluates the
arc length on the ellipsoid via the standard A / B / Δσ series.
§Diagnostics on mis-paired CS
A caller who pairs a Cartesian or Spherical point with Vincenty
hits the <P::Cs as CoordinateSystem>::Family: SameAs<GeographicFamily>
bound below and gets the redirect plate on
geometry_tag::SameAs pointing them at
WithCs<_, Geographic<…>> or at the Cartesian / Spherical
strategies. See T31 and proposal §3.7.