use crate::{CoordFloat, Distance, Point, Rhumb};
use num_traits::FromPrimitive;
#[deprecated(
since = "0.29.0",
note = "Please use the `Rhumb.distance` method from the `Distance` trait instead"
)]
pub trait RhumbDistance<T, Rhs = Self> {
fn rhumb_distance(&self, rhs: &Rhs) -> T;
}
#[allow(deprecated)]
impl<T> RhumbDistance<T, Point<T>> for Point<T>
where
T: CoordFloat + FromPrimitive,
{
fn rhumb_distance(&self, rhs: &Point<T>) -> T {
Rhumb.distance(*self, *rhs)
}
}
#[cfg(test)]
mod test {
use crate::Point;
#[allow(deprecated)]
use crate::RhumbDistance;
#[test]
fn distance1_test() {
let a = Point::new(0., 0.);
let b = Point::new(1., 0.);
#[allow(deprecated)]
let distance = a.rhumb_distance(&b);
assert_relative_eq!(distance, 111195.0802335329_f64, epsilon = 1.0e-6);
}
#[test]
fn distance2_test() {
let a = Point::new(-72.1235, 42.3521);
let b = Point::new(72.1260, 70.612);
#[allow(deprecated)]
let distance = a.rhumb_distance(&b);
assert_relative_eq!(distance, 8903668.508603323_f64, epsilon = 1.0e-6);
}
#[test]
fn distance3_test() {
let a = Point::new(-77.036585, 38.897448);
let b = Point::new(-77.009080, 38.889825);
#[allow(deprecated)]
let distance = a.rhumb_distance(&b);
assert_relative_eq!(distance, 2526.823513863995_f64, epsilon = 1.0e-6);
}
#[test]
fn distance3_test_f32() {
let a = Point::<f32>::new(-77.03658, 38.89745);
let b = Point::<f32>::new(-77.00908, 38.889825);
#[allow(deprecated)]
let distance = a.rhumb_distance(&b);
assert_relative_eq!(distance, 2527.4585_f32, epsilon = 1.0e-6);
}
}