From d31531836e1e1c1f9d63ae595e1dd62cbcb25bfa Mon Sep 17 00:00:00 2001 From: Cedric Liegeois Date: Sat, 25 Nov 2023 22:03:23 +1100 Subject: [PATCH] tests --- src/spherical/sphere.rs | 73 +++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/src/spherical/sphere.rs b/src/spherical/sphere.rs index 33b4f66..5f0c150 100644 --- a/src/spherical/sphere.rs +++ b/src/spherical/sphere.rs @@ -798,10 +798,71 @@ where #[cfg(test)] mod tests { - // TODO(CL): along_track_distance, cross_track_distance - use std::{f64::consts::PI, time::Duration}; + use crate::{ + positions::{assert_nv_eq_d7, assert_opt_nv_eq_d7}, + spherical::{GreatCircle, MinorArc, Sphere}, + Angle, LatLong, Length, NVector, Speed, Vec3, Vehicle, + }; + + use super::newton_raphson; + + // along_track_distance + #[test] + fn along_track_distance_positive() { + let p = NVector::from_lat_long_degrees(53.2611, -0.7972); + let ma = MinorArc::new( + NVector::from_lat_long_degrees(53.3206, -1.7297), + NVector::from_lat_long_degrees(53.1887, 0.1334), + ); + let a = Sphere::EARTH.along_track_distance(p, ma); + assert_eq!(Length::from_metres(62331.501), a.round_mm()); + } + + #[test] + fn along_track_distance_negative() { + let p = NVector::from_lat_long_degrees(53.3206, -1.7297); + let ma = MinorArc::new( + NVector::from_lat_long_degrees(53.2611, -0.7972), + NVector::from_lat_long_degrees(53.1887, 0.1334), + ); + let a = Sphere::EARTH.along_track_distance(p, ma); + assert_eq!(Length::from_metres(-62329.232), a.round_mm()); + } + + #[test] + fn along_track_distance_zero() { + let p = NVector::from_lat_long_degrees(53.3206, -1.7297); + let ma = MinorArc::new(p, NVector::from_lat_long_degrees(53.1887, 0.1334)); + let a = Sphere::EARTH.along_track_distance(p, ma); + assert_eq!(Length::ZERO, a.round_mm()); + } + + // cross_track_distance + + #[test] + fn cross_track_distance_negative() { + let p = NVector::from_lat_long_degrees(53.2611, -0.7972); + let gc = GreatCircle::from_heading( + NVector::from_lat_long_degrees(53.3206, -1.7297), + Angle::from_degrees(96.0), + ); + let a = Sphere::EARTH.cross_track_distance(p, gc); + assert_eq!(Length::from_metres(-305.665), a.round_mm()); + } + + #[test] + fn cross_track_distance_positive() { + let p = NVector::from_lat_long_degrees(53.2611, -1.7972); + let gc = GreatCircle::from_heading( + NVector::from_lat_long_degrees(53.3206, -1.7297), + Angle::from_degrees(96.0), + ); + let a = Sphere::EARTH.cross_track_distance(p, gc); + assert_eq!(Length::from_metres(7047.043), a.round_mm()); + } + // destination. #[test] @@ -1154,14 +1215,6 @@ mod tests { // mean - use crate::{ - positions::{assert_nv_eq_d7, assert_opt_nv_eq_d7}, - spherical::Sphere, - Angle, LatLong, Length, NVector, Speed, Vec3, Vehicle, - }; - - use super::newton_raphson; - #[test] fn mean_antipodal() { let p = NVector::from_lat_long_degrees(0.0, 0.0);