1#![cfg_attr(not(test), no_std)]
113
114extern crate angle_sc;
115extern crate nalgebra as na;
116
117pub mod great_circle;
118pub mod vector;
119
120pub use angle_sc::{Angle, Degrees, Radians, Validate};
121use thiserror::Error;
122
123#[must_use]
127pub fn is_valid_latitude(degrees: f64) -> bool {
128 (-90.0..=90.0).contains(°rees)
129}
130
131#[must_use]
135pub fn is_valid_longitude(degrees: f64) -> bool {
136 (-180.0..=180.0).contains(°rees)
137}
138
139#[derive(Clone, Copy, Debug, PartialEq)]
141pub struct LatLong {
142 lat: Degrees,
143 lon: Degrees,
144}
145
146impl Validate for LatLong {
147 fn is_valid(&self) -> bool {
152 is_valid_latitude(self.lat.0) && is_valid_longitude(self.lon.0)
153 }
154}
155
156impl LatLong {
157 #[must_use]
158 pub const fn new(lat: Degrees, lon: Degrees) -> Self {
159 Self { lat, lon }
160 }
161
162 #[must_use]
163 pub const fn lat(&self) -> Degrees {
164 self.lat
165 }
166
167 #[must_use]
168 pub const fn lon(&self) -> Degrees {
169 self.lon
170 }
171
172 #[must_use]
179 pub fn is_south_of(&self, a: &Self) -> bool {
180 self.lat.0 < a.lat.0
181 }
182
183 #[must_use]
190 pub fn is_west_of(&self, a: &Self) -> bool {
191 (a.lon() - self.lon).0 < 0.0
192 }
193}
194
195#[derive(Error, Debug, PartialEq)]
197pub enum LatLongError {
198 #[error("invalid latitude value: `{0}`")]
199 Latitude(f64),
200 #[error("invalid longitude value: `{0}`")]
201 Longitude(f64),
202}
203
204impl TryFrom<(f64, f64)> for LatLong {
205 type Error = LatLongError;
206
207 fn try_from(lat_long: (f64, f64)) -> Result<Self, Self::Error> {
211 if !is_valid_latitude(lat_long.0) {
212 Err(LatLongError::Latitude(lat_long.0))
213 } else if !is_valid_longitude(lat_long.1) {
214 Err(LatLongError::Longitude(lat_long.1))
215 } else {
216 Ok(Self::new(Degrees(lat_long.0), Degrees(lat_long.1)))
217 }
218 }
219}
220
221#[must_use]
228pub fn calculate_azimuth_and_distance(a: &LatLong, b: &LatLong) -> (Angle, Radians) {
229 let a_lat = Angle::from(a.lat);
230 let b_lat = Angle::from(b.lat);
231 let delta_long = Angle::from((b.lon, a.lon));
232 (
233 great_circle::calculate_gc_azimuth(a_lat, b_lat, delta_long),
234 great_circle::calculate_gc_distance(a_lat, b_lat, delta_long),
235 )
236}
237
238#[must_use]
246pub fn haversine_distance(a: &LatLong, b: &LatLong) -> Radians {
247 let a_lat = Angle::from(a.lat);
248 let b_lat = Angle::from(b.lat);
249 let delta_lat = Angle::from((b.lat, a.lat));
250 let delta_long = Angle::from(b.lon - a.lon);
251 great_circle::calculate_haversine_distance(a_lat, b_lat, delta_long, delta_lat)
252}
253
254#[allow(clippy::module_name_repetitions)]
256pub type Vector3d = na::Vector3<f64>;
257
258impl From<&LatLong> for Vector3d {
259 fn from(a: &LatLong) -> Self {
267 vector::to_point(Angle::from(a.lat), Angle::from(a.lon))
268 }
269}
270
271impl From<&Vector3d> for LatLong {
272 fn from(value: &Vector3d) -> Self {
274 Self::new(
275 Degrees::from(vector::latitude(value)),
276 Degrees::from(vector::longitude(value)),
277 )
278 }
279}
280
281#[derive(Clone, Copy, Debug, PartialEq)]
283pub struct Arc {
284 a: Vector3d,
286 pole: Vector3d,
288 length: Radians,
290 half_width: Radians,
292}
293
294impl Validate for Arc {
295 fn is_valid(&self) -> bool {
300 vector::is_unit(&self.a)
301 && vector::is_unit(&self.pole)
302 && vector::are_orthogonal(&self.a, &self.pole)
303 && !self.length.0.is_sign_negative()
304 && !self.half_width.0.is_sign_negative()
305 }
306}
307
308impl Arc {
309 #[must_use]
316 pub const fn new(a: Vector3d, pole: Vector3d, length: Radians, half_width: Radians) -> Self {
317 Self {
318 a,
319 pole,
320 length,
321 half_width,
322 }
323 }
324
325 #[must_use]
331 pub fn from_lat_lon_azi_length(a: &LatLong, azimuth: Angle, length: Radians) -> Self {
332 Self::new(
333 Vector3d::from(a),
334 vector::calculate_pole(Angle::from(a.lat()), Angle::from(a.lon()), azimuth),
335 length,
336 Radians(0.0),
337 )
338 }
339
340 #[must_use]
345 pub fn between_positions(a: &LatLong, b: &LatLong) -> Self {
346 let (azimuth, length) = calculate_azimuth_and_distance(a, b);
347 let a_lat = Angle::from(a.lat());
348 if a_lat.cos().0 < great_circle::MIN_VALUE {
350 Self::from_lat_lon_azi_length(&LatLong::new(a.lat(), b.lon()), azimuth, length)
352 } else {
353 Self::from_lat_lon_azi_length(a, azimuth, length)
354 }
355 }
356
357 #[must_use]
361 pub const fn set_half_width(&mut self, half_width: Radians) -> &mut Self {
362 self.half_width = half_width;
363 self
364 }
365
366 #[must_use]
368 pub const fn a(&self) -> Vector3d {
369 self.a
370 }
371
372 #[must_use]
374 pub const fn pole(&self) -> Vector3d {
375 self.pole
376 }
377
378 #[must_use]
380 pub const fn length(&self) -> Radians {
381 self.length
382 }
383
384 #[must_use]
386 pub const fn half_width(&self) -> Radians {
387 self.half_width
388 }
389
390 #[must_use]
392 pub fn azimuth(&self) -> Angle {
393 vector::calculate_azimuth(&self.a, &self.pole)
394 }
395
396 #[must_use]
398 pub fn direction(&self) -> Vector3d {
399 vector::direction(&self.a, &self.pole)
400 }
401
402 #[must_use]
404 pub fn position(&self, distance: Radians) -> Vector3d {
405 vector::position(&self.a, &self.direction(), Angle::from(distance))
406 }
407
408 #[must_use]
410 pub fn b(&self) -> Vector3d {
411 self.position(self.length)
412 }
413
414 #[must_use]
416 pub fn mid_point(&self) -> Vector3d {
417 self.position(self.length.half())
418 }
419
420 #[must_use]
427 pub fn perp_position(&self, point: &Vector3d, distance: Radians) -> Vector3d {
428 vector::position(point, &self.pole, Angle::from(distance))
429 }
430
431 #[must_use]
437 pub fn angle_position(&self, angle: Angle) -> Vector3d {
438 vector::rotate_position(&self.a, &self.pole, angle, Angle::from(self.length))
439 }
440
441 #[must_use]
447 pub fn end_arc(&self, at_b: bool) -> Self {
448 let p = if at_b { self.b() } else { self.a };
449 let pole = vector::direction(&p, &self.pole);
450 if self.half_width.0 < great_circle::MIN_VALUE {
451 Self::new(p, pole, Radians(0.0), Radians(0.0))
452 } else {
453 let a = self.perp_position(&p, self.half_width);
454 Self::new(a, pole, self.half_width + self.half_width, Radians(0.0))
455 }
456 }
457
458 #[must_use]
465 pub fn calculate_atd_and_xtd(&self, point: &Vector3d) -> (Radians, Radians) {
466 vector::calculate_atd_and_xtd(&self.a, &self.pole(), point)
467 }
468
469 #[must_use]
475 pub fn shortest_distance(&self, point: &Vector3d) -> Radians {
476 let (atd, xtd) = self.calculate_atd_and_xtd(point);
477 if vector::intersection::is_alongside(atd, self.length, Radians(4.0 * f64::EPSILON)) {
478 xtd.abs()
479 } else {
480 let atd_centre = atd - self.length.half();
482 let p = if atd_centre.0.is_sign_negative() {
483 self.a
484 } else {
485 self.b()
486 };
487 great_circle::e2gc_distance(vector::distance(&p, point))
488 }
489 }
490}
491
492#[derive(Error, Debug, PartialEq)]
494pub enum ArcError {
495 #[error("positions are too close: `{0}`")]
496 PositionsTooClose(f64),
497 #[error("positions are too far apart: `{0}`")]
498 PositionsTooFar(f64),
499}
500
501impl TryFrom<(&LatLong, &LatLong)> for Arc {
502 type Error = ArcError;
503
504 fn try_from(params: (&LatLong, &LatLong)) -> Result<Self, Self::Error> {
508 let a = Vector3d::from(params.0);
510 let b = Vector3d::from(params.1);
511 vector::normalise(&a.cross(&b), vector::MIN_SQ_NORM).map_or_else(
513 || {
514 let sq_d = vector::sq_distance(&a, &b);
515 if sq_d < 1.0 {
516 Err(ArcError::PositionsTooClose(sq_d))
517 } else {
518 Err(ArcError::PositionsTooFar(sq_d))
519 }
520 },
521 |pole| {
522 Ok(Self::new(
523 a,
524 pole,
525 great_circle::e2gc_distance(vector::distance(&a, &b)),
526 Radians(0.0),
527 ))
528 },
529 )
530 }
531}
532
533#[must_use]
542pub fn calculate_intersection_distances(arc1: &Arc, arc2: &Arc) -> (Radians, Radians) {
543 vector::intersection::calculate_intersection_point_distances(
544 &arc1.a,
545 &arc1.pole,
546 arc1.length(),
547 &arc2.a,
548 &arc2.pole,
549 arc2.length(),
550 &(0.5 * (arc1.mid_point() + arc2.mid_point())),
551 )
552}
553
554#[must_use]
587pub fn calculate_intersection_point(arc1: &Arc, arc2: &Arc) -> Option<Vector3d> {
588 let (distance1, distance2) = calculate_intersection_distances(arc1, arc2);
589
590 if vector::intersection::is_alongside(distance1, arc1.length(), Radians(4.0 * f64::EPSILON))
592 && vector::intersection::is_alongside(distance2, arc2.length(), Radians(4.0 * f64::EPSILON))
593 {
594 Some(arc1.position(distance1.clamp(arc1.length())))
595 } else {
596 None
597 }
598}
599
600#[cfg(test)]
601mod tests {
602 use super::*;
603 use angle_sc::{Degrees, is_within_tolerance};
604
605 #[test]
606 fn test_is_valid_latitude() {
607 assert!(!is_valid_latitude(-90.0001));
609 assert!(is_valid_latitude(-90.0));
611 assert!(is_valid_latitude(90.0));
613 assert!(!is_valid_latitude(90.0001));
615 }
616
617 #[test]
618 fn test_is_valid_longitude() {
619 assert!(!is_valid_longitude(-180.0001));
621 assert!(is_valid_longitude(-180.0));
623 assert!(is_valid_longitude(180.0));
625 assert!(!is_valid_longitude(180.0001));
627 }
628
629 #[test]
630 fn test_latlong_traits() {
631 let a = LatLong::try_from((0.0, 90.0)).unwrap();
632
633 assert!(a.is_valid());
634
635 let a_clone = a.clone();
636 assert!(a_clone == a);
637
638 assert_eq!(Degrees(0.0), a.lat());
639 assert_eq!(Degrees(90.0), a.lon());
640
641 assert!(!a.is_south_of(&a));
642 assert!(!a.is_west_of(&a));
643
644 let b = LatLong::try_from((-10.0, -91.0)).unwrap();
645 assert!(b.is_south_of(&a));
646 assert!(b.is_west_of(&a));
647
648 println!("LatLong: {:?}", a);
649
650 let invalid_lat = LatLong::try_from((91.0, 0.0));
651 assert_eq!(Err(LatLongError::Latitude(91.0)), invalid_lat);
652 println!("invalid_lat: {:?}", invalid_lat);
653
654 let invalid_lon = LatLong::try_from((0.0, 181.0));
655 assert_eq!(Err(LatLongError::Longitude(181.0)), invalid_lon);
656 println!("invalid_lon: {:?}", invalid_lon);
657 }
658
659 #[test]
660 fn test_vector3d_traits() {
661 let a = LatLong::try_from((0.0, 90.0)).unwrap();
662 let point = Vector3d::from(&a);
663
664 assert_eq!(0.0, point.x);
665 assert_eq!(1.0, point.y);
666 assert_eq!(0.0, point.z);
667
668 assert_eq!(Degrees(0.0), Degrees::from(vector::latitude(&point)));
669 assert_eq!(Degrees(90.0), Degrees::from(vector::longitude(&point)));
670
671 let result = LatLong::from(&point);
672 assert_eq!(a, result);
673 }
674
675 #[test]
676 fn test_great_circle_90n_0n_0e() {
677 let a = LatLong::new(Degrees(90.0), Degrees(0.0));
678 let b = LatLong::new(Degrees(0.0), Degrees(0.0));
679 let (azimuth, dist) = calculate_azimuth_and_distance(&a, &b);
680
681 assert!(is_within_tolerance(
682 core::f64::consts::FRAC_PI_2,
683 dist.0,
684 f64::EPSILON
685 ));
686 assert_eq!(180.0, Degrees::from(azimuth).0);
687
688 let dist = haversine_distance(&a, &b);
689 assert!(is_within_tolerance(
690 core::f64::consts::FRAC_PI_2,
691 dist.0,
692 f64::EPSILON
693 ));
694 }
695
696 #[test]
697 fn test_great_circle_90s_0n_50e() {
698 let a = LatLong::new(Degrees(-90.0), Degrees(0.0));
699 let b = LatLong::new(Degrees(0.0), Degrees(50.0));
700 let (azimuth, dist) = calculate_azimuth_and_distance(&a, &b);
701
702 assert!(is_within_tolerance(
703 core::f64::consts::FRAC_PI_2,
704 dist.0,
705 f64::EPSILON
706 ));
707 assert_eq!(0.0, Degrees::from(azimuth).0);
708
709 let dist = haversine_distance(&a, &b);
710 assert!(is_within_tolerance(
711 core::f64::consts::FRAC_PI_2,
712 dist.0,
713 f64::EPSILON
714 ));
715 }
716
717 #[test]
718 fn test_great_circle_0n_60e_0n_60w() {
719 let a = LatLong::new(Degrees(0.0), Degrees(60.0));
720 let b = LatLong::new(Degrees(0.0), Degrees(-60.0));
721 let (azimuth, dist) = calculate_azimuth_and_distance(&a, &b);
722
723 assert!(is_within_tolerance(
724 2.0 * core::f64::consts::FRAC_PI_3,
725 dist.0,
726 2.0 * f64::EPSILON
727 ));
728 assert_eq!(-90.0, Degrees::from(azimuth).0);
729
730 let dist = haversine_distance(&a, &b);
731 assert!(is_within_tolerance(
732 2.0 * core::f64::consts::FRAC_PI_3,
733 dist.0,
734 2.0 * f64::EPSILON
735 ));
736 }
737
738 #[test]
739 fn test_arc() {
740 let g_eq = LatLong::new(Degrees(0.0), Degrees(0.0));
742
743 let e_eq = LatLong::new(Degrees(0.0), Degrees(90.0));
745
746 let mut arc = Arc::between_positions(&g_eq, &e_eq);
747 let arc = arc.set_half_width(Radians(0.01));
748 assert!(arc.is_valid());
749 assert_eq!(Radians(0.01), arc.half_width());
750
751 assert_eq!(Vector3d::from(&g_eq), arc.a());
752 assert_eq!(Vector3d::new(0.0, 0.0, 1.0), arc.pole());
753 assert!(is_within_tolerance(
754 core::f64::consts::FRAC_PI_2,
755 arc.length().0,
756 f64::EPSILON
757 ));
758 assert_eq!(Angle::from(Degrees(90.0)), arc.azimuth());
759 let b = Vector3d::from(&e_eq);
760 assert!(is_within_tolerance(
761 0.0,
762 vector::distance(&b, &arc.b()),
763 f64::EPSILON
764 ));
765
766 let mid_point = arc.mid_point();
767 assert_eq!(0.0, mid_point.z);
768 assert!(is_within_tolerance(
769 45.0,
770 Degrees::from(vector::longitude(&mid_point)).0,
771 32.0 * f64::EPSILON
772 ));
773
774 let start_arc = arc.end_arc(false);
775 assert_eq!(0.02, start_arc.length().0);
776
777 let start_arc_a = start_arc.a();
778 assert_eq!(start_arc_a, arc.perp_position(&arc.a(), Radians(0.01)));
779
780 let angle_90 = Angle::from(Degrees(90.0));
781 let pole_0 = Vector3d::new(0.0, 0.0, 1.0);
782 assert!(vector::distance(&pole_0, &arc.angle_position(angle_90)) <= f64::EPSILON);
783
784 let end_arc = arc.end_arc(true);
785 assert_eq!(0.02, end_arc.length().0);
786
787 let end_arc_a = end_arc.a();
788 assert_eq!(end_arc_a, arc.perp_position(&arc.b(), Radians(0.01)));
789 }
790
791 #[test]
792 fn test_north_and_south_poles() {
793 let north_pole = LatLong::new(Degrees(90.0), Degrees(0.0));
794 let south_pole = LatLong::new(Degrees(-90.0), Degrees(0.0));
795
796 let (azimuth, distance) = calculate_azimuth_and_distance(&south_pole, &north_pole);
797 assert_eq!(0.0, Degrees::from(azimuth).0);
798 assert_eq!(core::f64::consts::PI, distance.0);
799
800 let (azimuth, distance) = calculate_azimuth_and_distance(&north_pole, &south_pole);
801 assert_eq!(180.0, Degrees::from(azimuth).0);
802 assert_eq!(core::f64::consts::PI, distance.0);
803
804 let e_eq = LatLong::new(Degrees(0.0), Degrees(50.0));
806
807 let arc = Arc::between_positions(&north_pole, &e_eq);
808 assert!(is_within_tolerance(
809 e_eq.lat().0,
810 LatLong::from(&arc.b()).lat().abs().0,
811 1e-13
812 ));
813 assert!(is_within_tolerance(
814 e_eq.lon().0,
815 LatLong::from(&arc.b()).lon().0,
816 50.0 * f64::EPSILON
817 ));
818
819 let arc = Arc::between_positions(&south_pole, &e_eq);
820 assert!(is_within_tolerance(
821 e_eq.lat().0,
822 LatLong::from(&arc.b()).lat().abs().0,
823 1e-13
824 ));
825 assert!(is_within_tolerance(
826 e_eq.lon().0,
827 LatLong::from(&arc.b()).lon().0,
828 50.0 * f64::EPSILON
829 ));
830
831 let w_eq = LatLong::new(Degrees(0.0), Degrees(-140.0));
832
833 let arc = Arc::between_positions(&north_pole, &w_eq);
834 assert!(is_within_tolerance(
835 w_eq.lat().0,
836 LatLong::from(&arc.b()).lat().abs().0,
837 1e-13
838 ));
839 assert!(is_within_tolerance(
840 w_eq.lon().0,
841 LatLong::from(&arc.b()).lon().0,
842 256.0 * f64::EPSILON
843 ));
844
845 let arc = Arc::between_positions(&south_pole, &w_eq);
846 assert!(is_within_tolerance(
847 w_eq.lat().0,
848 LatLong::from(&arc.b()).lat().abs().0,
849 1e-13
850 ));
851 assert!(is_within_tolerance(
852 w_eq.lon().0,
853 LatLong::from(&arc.b()).lon().0,
854 256.0 * f64::EPSILON
855 ));
856
857 let invalid_arc = Arc::try_from((&north_pole, &north_pole));
858 assert_eq!(Err(ArcError::PositionsTooClose(0.0)), invalid_arc);
859 println!("invalid_arc: {:?}", invalid_arc);
860
861 let arc = Arc::between_positions(&north_pole, &north_pole);
862 assert_eq!(north_pole, LatLong::from(&arc.b()));
863
864 let invalid_arc = Arc::try_from((&north_pole, &south_pole));
865 assert_eq!(Err(ArcError::PositionsTooFar(4.0)), invalid_arc);
866 println!("invalid_arc: {:?}", invalid_arc);
867
868 let arc = Arc::between_positions(&north_pole, &south_pole);
869 assert_eq!(south_pole, LatLong::from(&arc.b()));
870
871 let arc = Arc::between_positions(&south_pole, &north_pole);
872 assert_eq!(north_pole, LatLong::from(&arc.b()));
873
874 let arc = Arc::between_positions(&south_pole, &south_pole);
875 assert_eq!(south_pole, LatLong::from(&arc.b()));
876 }
877
878 #[test]
879 fn test_arc_atd_and_xtd() {
880 let g_eq = LatLong::new(Degrees(0.0), Degrees(0.0));
882
883 let e_eq = LatLong::new(Degrees(0.0), Degrees(90.0));
885
886 let arc = Arc::try_from((&g_eq, &e_eq)).unwrap();
887 assert!(arc.is_valid());
888
889 let start_arc = arc.end_arc(false);
890 assert_eq!(0.0, start_arc.length().0);
891
892 let start_arc_a = start_arc.a();
893 assert_eq!(arc.a(), start_arc_a);
894
895 let longitude = Degrees(1.0);
896
897 for lat in -83..84 {
900 let latitude = Degrees(lat as f64);
901 let latlong = LatLong::new(latitude, longitude);
902 let point = Vector3d::from(&latlong);
903
904 let expected = (lat as f64).to_radians();
905 let (atd, xtd) = arc.calculate_atd_and_xtd(&point);
906 assert!(is_within_tolerance(1_f64.to_radians(), atd.0, f64::EPSILON));
907 assert!(is_within_tolerance(expected, xtd.0, 2.0 * f64::EPSILON));
908
909 let d = arc.shortest_distance(&point);
910 assert!(is_within_tolerance(expected.abs(), d.0, 2.0 * f64::EPSILON));
911 }
912
913 let point = Vector3d::from(&g_eq);
914 let d = arc.shortest_distance(&point);
915 assert_eq!(0.0, d.0);
916
917 let point = Vector3d::from(&e_eq);
918 let d = arc.shortest_distance(&point);
919 assert_eq!(0.0, d.0);
920
921 let latlong = LatLong::new(Degrees(0.0), Degrees(-1.0));
922 let point = Vector3d::from(&latlong);
923 let d = arc.shortest_distance(&point);
924 assert!(is_within_tolerance(1_f64.to_radians(), d.0, f64::EPSILON));
925
926 let point = -point;
927 let d = arc.shortest_distance(&point);
928 assert!(is_within_tolerance(89_f64.to_radians(), d.0, f64::EPSILON));
929
930 let latlong = LatLong::new(Degrees(0.0), Degrees(-160.0));
932 let point = Vector3d::from(&latlong);
933 let d = arc.shortest_distance(&point);
934 assert_eq!(
936 great_circle::e2gc_distance(vector::distance(&arc.b(), &point)),
937 d
938 );
939 }
940
941 #[test]
942 fn test_arc_intersection_point() {
943 let istanbul = LatLong::new(Degrees(42.0), Degrees(29.0));
947 let washington = LatLong::new(Degrees(39.0), Degrees(-77.0));
948 let reyjavik = LatLong::new(Degrees(64.0), Degrees(-22.0));
949 let accra = LatLong::new(Degrees(6.0), Degrees(0.0));
950
951 let arc1 = Arc::try_from((&istanbul, &washington)).unwrap();
952 let arc2 = Arc::try_from((&reyjavik, &accra)).unwrap();
953
954 let intersection_point = calculate_intersection_point(&arc1, &arc2).unwrap();
955 let lat_long = LatLong::from(&intersection_point);
956 assert!(is_within_tolerance(54.72, lat_long.lat().0, 0.05));
958 assert!(is_within_tolerance(-14.56, lat_long.lon().0, 0.02));
960
961 let intersection_point = calculate_intersection_point(&arc2, &arc1).unwrap();
963 let lat_long = LatLong::from(&intersection_point);
964 assert!(is_within_tolerance(54.72, lat_long.lat().0, 0.05));
966 assert!(is_within_tolerance(-14.56, lat_long.lon().0, 0.02));
968 }
969
970 #[test]
971 fn test_arc_intersection_same_great_circles() {
972 let south_pole_1 = LatLong::new(Degrees(-88.0), Degrees(-180.0));
973 let south_pole_2 = LatLong::new(Degrees(-87.0), Degrees(0.0));
974
975 let arc1 = Arc::try_from((&south_pole_1, &south_pole_2)).unwrap();
976
977 let intersection_lengths = calculate_intersection_distances(&arc1, &arc1);
978 assert_eq!(Radians(0.0), intersection_lengths.0);
979 assert_eq!(Radians(0.0), intersection_lengths.1);
980
981 let intersection_point = calculate_intersection_point(&arc1, &arc1).unwrap();
982 assert_eq!(0.0, vector::sq_distance(&arc1.a(), &intersection_point));
983
984 let south_pole_3 = LatLong::new(Degrees(-85.0), Degrees(0.0));
985 let south_pole_4 = LatLong::new(Degrees(-86.0), Degrees(0.0));
986 let arc2 = Arc::try_from((&south_pole_3, &south_pole_4)).unwrap();
987 let intersection_point = calculate_intersection_point(&arc1, &arc2);
988 assert!(intersection_point.is_none());
989 }
990}