@@ -229,8 +229,8 @@ impl Curve for PlanarLineStringCurve {
229
229
/// Each [`Line`] made up of 2 [`Coord`]s.
230
230
/// A spherical coordinates model takes 3 coordinates: longitude (`x`), latitude (`y`)
231
231
/// and radius as const ([`geo::MEAN_EARTH_RADIUS`]).
232
- /// [`GeodesicLength`] for a Paris to New-York is about 5837.283 km, and
233
- /// [`HaversineLength`] for a Paris to New-York is about 5852.970 km.
232
+ /// [`GeodesicLength`] for a Paris to New-York is about 5853.101 km, and
233
+ /// [`HaversineLength`] for a Paris to New-York is about 5837.415 km.
234
234
/// We've chosen here to stick with Haversine Formula.
235
235
/// The computations are made along the Great Circle.
236
236
/// When required, some methods use [geo::algorithm::densify_haversine::DensifyHaversine]
@@ -446,20 +446,13 @@ mod tests {
446
446
pub use geo:: line_string;
447
447
use geo:: point;
448
448
449
- const PARIS_LON : f64 = 2.352565660016694 ;
450
- const PARIS_LAT : f64 = 48.85643268390663 ;
451
- const NEW_YORK_LON : f64 = -74.00599134051316 ;
452
- const NEW_YORK_LAT : f64 = 40.71274961837565 ;
453
- const LILLE_LON : f64 = 3.066667 ;
454
- const LILLE_LAT : f64 = 50.633333 ;
455
- const PERPIGNAN_LON : f64 = 2.8948332 ;
456
- const PERPIGNAN_LAT : f64 = 42.6886591 ;
457
- const BREST_LON : f64 = -4.486076 ;
458
- const BREST_LAT : f64 = 48.390394 ;
459
- const NANCY_LON : f64 = 6.184417 ;
460
- const NANCY_LAT : f64 = 48.692054 ;
461
- const REYKJAVIK_LON : f64 = -21.827774 ;
462
- const REYKJAVIK_LAT : f64 = 64.128288 ;
449
+ const PARIS : geo:: Coord = coord ! { x: 2.35 , y: 48.86 } ;
450
+ const NEW_YORK : geo:: Coord = coord ! { x: -74.01 , y: 40.71 } ;
451
+ const LILLE : geo:: Coord = coord ! { x: 3.07 , y: 50.63 } ;
452
+ const PERPIGNAN : geo:: Coord = coord ! { x: 2.89 , y: 42.69 } ;
453
+ const BREST : geo:: Coord = coord ! { x: -4.49 , y: 48.39 } ;
454
+ const NANCY : geo:: Coord = coord ! { x: 6.18 , y: 48.69 } ;
455
+ const REYKJAVIK : geo:: Coord = coord ! { x: -21.83 , y: 64.13 } ;
463
456
464
457
#[ test]
465
458
fn planar_fragmented ( ) {
@@ -573,39 +566,39 @@ mod tests {
573
566
fn spherical_fragmented ( ) {
574
567
let framentation_max_length = 1. ;
575
568
let paris_to_new_york = SphericalLineStringCurve :: new_fragmented (
576
- line_string ! [ ( x : PARIS_LON , y : PARIS_LAT ) , ( x : NEW_YORK_LON , y : NEW_YORK_LAT ) ] ,
569
+ line_string ! [ PARIS , NEW_YORK ] ,
577
570
framentation_max_length,
578
571
1. ,
579
572
) ;
580
573
581
- assert_eq ! ( 5837284 , paris_to_new_york. len( ) ) ;
574
+ assert_eq ! ( 5837416 , paris_to_new_york. len( ) ) ;
582
575
assert_relative_eq ! (
583
576
framentation_max_length,
584
577
paris_to_new_york[ 0 ] . length( ) ,
585
- epsilon = 1e-7
578
+ epsilon = 1e-6
586
579
) ;
587
- // 1e-7 means we lose 0.1 micrometer per segment
580
+ // 1e-6 means we lose 1. micrometer per segment
588
581
}
589
582
590
583
#[ test]
591
584
fn spherical_length ( ) {
592
585
let paris_to_new_york = SphericalLineStringCurve :: new (
593
- line_string ! [ ( x : PARIS_LON , y : PARIS_LAT ) , ( x : NEW_YORK_LON , y : NEW_YORK_LAT ) ] ,
586
+ line_string ! [ PARIS , NEW_YORK ] ,
594
587
1. ,
595
588
) ;
596
- assert_relative_eq ! ( 5837283.441678336 , paris_to_new_york. length( ) ) ; // 5837283.441678336 using [`HaversineLength`] and 5852969.839293494 using [`GeodesicLength`]
589
+ assert_eq ! ( 5837415.205720471 , paris_to_new_york. length( ) ) ; // 5837415.205720471 using [`HaversineLength`] and 5853101.331803938 using [`GeodesicLength`]
597
590
598
591
let lille_to_perpignan = SphericalLineStringCurve :: new (
599
- line_string ! [ ( x : LILLE_LON , y : LILLE_LAT ) , ( x : PERPIGNAN_LON , y : PERPIGNAN_LAT ) ] ,
592
+ line_string ! [ LILLE , PERPIGNAN ] ,
600
593
1. ,
601
594
) ;
602
- assert_relative_eq ! ( 883505.2931188548 , lille_to_perpignan. length( ) ) ; // 883505.2931188548 using [`HaversineLength`] and 883260.051153502 using [`GeodesicLength`]
595
+ assert_eq ! ( 882995.0489150163 , lille_to_perpignan. length( ) ) ; // 882995.0489150163 using [`HaversineLength`] and 882749.856002331 using [`GeodesicLength`]
603
596
604
597
let brest_to_nancy = SphericalLineStringCurve :: new (
605
- line_string ! [ ( x : BREST_LON , y : BREST_LAT ) , ( x : NANCY_LON , y : NANCY_LAT ) ] ,
598
+ line_string ! [ BREST , NANCY ] ,
606
599
1. ,
607
600
) ;
608
- assert_relative_eq ! ( 785636.8730262491 , brest_to_nancy. length( ) ) ; // 785636.8730262491 using [`HaversineLength`] and 787994.4363866252 using [`GeodesicLength`]
601
+ assert_eq ! ( 785611.8752324395 , brest_to_nancy. length( ) ) ; // 785611.8752324395 using [`HaversineLength`] and 787969.3534391255 using [`GeodesicLength`]
609
602
}
610
603
611
604
#[ test]
@@ -646,65 +639,65 @@ mod tests {
646
639
#[ test]
647
640
fn spherical_projection ( ) {
648
641
let mut paris_to_new_york = SphericalLineStringCurve :: new (
649
- line_string ! [ ( x : PARIS_LON , y : PARIS_LAT ) , ( x : NEW_YORK_LON , y : NEW_YORK_LAT ) ] ,
642
+ line_string ! [ PARIS , NEW_YORK ] ,
650
643
1. ,
651
644
) ;
652
645
653
646
// Point is located on the right (north) of the curve
654
647
let projected = paris_to_new_york
655
- . project ( point ! { x: -6.705403880820967 , y: 51.42135181702875 } )
648
+ . project ( point ! { x: -6.71 , y: 51.42 } )
656
649
. unwrap ( ) ;
657
- assert_eq ! ( 701924.3809693493 , projected. distance_along_curve) ;
658
- assert_eq ! ( -67157.93913531031 , projected. offset) ;
650
+ assert_eq ! ( 701868.9818283478 , projected. distance_along_curve) ;
651
+ assert_eq ! ( -66665.6982638038 , projected. offset) ;
659
652
660
653
// Point is located on the left (south) of the curve
661
654
let projected = paris_to_new_york
662
- . project ( point ! { x: -12.250890759346419 , y: 45.857650969554356 } )
655
+ . project ( point ! { x: -12.25 , y: 45.86 } )
663
656
. unwrap ( ) ;
664
- assert_eq ! ( 963365.3768036617 , projected. distance_along_curve) ;
665
- assert_eq ! ( 625592.3211438804 , projected. offset) ;
657
+ assert_eq ! ( 963056.4000812048 , projected. distance_along_curve) ;
658
+ assert_eq ! ( 625574.8001320735 , projected. offset) ;
666
659
667
660
// Same point, but with an offset from the curve
668
661
paris_to_new_york. start_offset = 1000000. ;
669
662
let projected = paris_to_new_york
670
- . project ( point ! { x: -12.250890759346419 , y: 45.857650969554356 } )
663
+ . project ( point ! { x: -12.25 , y: 45.86 } )
671
664
. unwrap ( ) ;
672
- assert_eq ! ( 1963365.3768036617 , projected. distance_along_curve) ;
673
- assert_eq ! ( 625592.3211438804 , projected. offset) ;
665
+ assert_eq ! ( 1963056.4000812047 , projected. distance_along_curve) ;
666
+ assert_eq ! ( 625574.8001320735 , projected. offset) ;
674
667
675
668
// ################################################################################
676
669
let mut new_york_to_paris = SphericalLineStringCurve :: new (
677
- line_string ! [ ( x : NEW_YORK_LON , y : NEW_YORK_LAT ) , ( x : PARIS_LON , y : PARIS_LAT ) ] ,
670
+ line_string ! [ NEW_YORK , PARIS ] ,
678
671
1. ,
679
672
) ;
680
673
681
674
// Point is located on the left (north) of the curve
682
675
let projected = new_york_to_paris
683
- . project ( point ! { x: -6.705403880820967 , y: 51.42135181702875 } )
676
+ . project ( point ! { x: -6.71 , y: 51.42 } )
684
677
. unwrap ( ) ;
685
- assert_eq ! ( 5135359.060708988 , projected. distance_along_curve) ;
686
- assert_eq ! ( 67157.93913531031 , projected. offset) ;
678
+ assert_eq ! ( 5135546.223892125 , projected. distance_along_curve) ;
679
+ assert_eq ! ( 66665.6982638038 , projected. offset) ;
687
680
688
681
// Point is located on the right (south) of the curve
689
682
let projected = new_york_to_paris
690
- . project ( point ! { x: -12.250890759346419 , y: 45.857650969554356 } )
683
+ . project ( point ! { x: -12.25 , y: 45.86 } )
691
684
. unwrap ( ) ;
692
- assert_eq ! ( 4873918.064874676 , projected. distance_along_curve) ;
693
- assert_eq ! ( -625592.3211438811 , projected. offset) ; // Note: result is weird -> distance should remain the same than the other way curve, difference is 0.7mm
685
+ assert_eq ! ( 4874358.805639268 , projected. distance_along_curve) ;
686
+ assert_eq ! ( -625574.8001320735 , projected. offset) ;
694
687
695
688
// Same point, but with an offset from the curve
696
689
new_york_to_paris. start_offset = 1000000. ;
697
690
let projected = new_york_to_paris
698
- . project ( point ! { x: -12.250890759346419 , y: 45.857650969554356 } )
691
+ . project ( point ! { x: -12.25 , y: 45.86 } )
699
692
. unwrap ( ) ;
700
- assert_eq ! ( 5873918.064874676 , projected. distance_along_curve) ;
701
- assert_eq ! ( -625592.3211438811 , projected. offset) ; // Note: same, difference is 0.7mm
693
+ assert_eq ! ( 5874358.805639268 , projected. distance_along_curve) ;
694
+ assert_eq ! ( -625574.8001320735 , projected. offset) ;
702
695
}
703
696
704
697
#[ test]
705
698
fn spherical_resolve ( ) {
706
699
let mut paris_to_new_york = SphericalLineStringCurve :: new (
707
- line_string ! [ ( x : PARIS_LON , y : PARIS_LAT ) , ( x : NEW_YORK_LON , y : NEW_YORK_LAT ) ] ,
700
+ line_string ! [ PARIS , NEW_YORK ] ,
708
701
1. ,
709
702
) ;
710
703
@@ -713,20 +706,20 @@ mod tests {
713
706
offset : 0. ,
714
707
} ;
715
708
let paris_to_new_york_projection = paris_to_new_york. resolve ( projection) . unwrap ( ) ;
716
- assert_eq ! ( paris_to_new_york_projection. x( ) , - 11.113419713640527 ) ;
717
- assert_eq ! ( paris_to_new_york_projection. y( ) , 51.44320774918762 ) ;
709
+ assert_eq ! ( - 11.117252327440333 , paris_to_new_york_projection. x( ) ) ;
710
+ assert_eq ! ( 51.44598457247205 , paris_to_new_york_projection. y( ) ) ;
718
711
719
712
paris_to_new_york. start_offset = 300000. ;
720
713
let paris_to_new_york_projection = paris_to_new_york. resolve ( projection) . unwrap ( ) ;
721
- assert_eq ! ( paris_to_new_york_projection. x( ) , - 6.924269520648392 ) ;
722
- assert_eq ! ( paris_to_new_york_projection. y( ) , 50.83295845015173 ) ;
714
+ assert_eq ! ( - 6.927740203201038 , paris_to_new_york_projection. x( ) ) ;
715
+ assert_eq ! ( 50.835999775637625 , paris_to_new_york_projection. y( ) ) ;
723
716
724
717
projection. distance_along_curve = 8000000. ;
725
718
assert ! ( paris_to_new_york. resolve( projection) . is_err( ) ) ;
726
719
727
- // ################################################################################
720
+ // Test on a linestring where only the longitude changes (latitude remains almost the same)
728
721
let lille_to_perpignan = SphericalLineStringCurve :: new (
729
- line_string ! [ ( x : LILLE_LON , y : LILLE_LAT ) , ( x : PERPIGNAN_LON , y : PERPIGNAN_LAT ) ] ,
722
+ line_string ! [ LILLE , PERPIGNAN ] ,
730
723
1. ,
731
724
) ;
732
725
@@ -735,12 +728,12 @@ mod tests {
735
728
offset : 0. ,
736
729
} ;
737
730
let lille_to_perpignan_p = lille_to_perpignan. resolve ( projection) . unwrap ( ) ;
738
- assert_eq ! ( lille_to_perpignan_p. x( ) , 2.963285977058639 ) ;
739
- assert_eq ! ( lille_to_perpignan_p. y( ) , 46.13725407237963 ) ;
731
+ assert_eq ! ( 2.961652543888961 , lille_to_perpignan_p. x( ) ) ;
732
+ assert_eq ! ( 46.13397259680868 , lille_to_perpignan_p. y( ) ) ;
740
733
741
- // ################################################################################
734
+ // Test on a linestring where only the latitude changes (longitude remains almost the same)
742
735
let brest_to_nancy = SphericalLineStringCurve :: new (
743
- line_string ! [ ( x : BREST_LON , y : BREST_LAT ) , ( x : NANCY_LON , y : NANCY_LAT ) ] ,
736
+ line_string ! [ BREST , NANCY ] ,
744
737
1. ,
745
738
) ;
746
739
@@ -749,25 +742,25 @@ mod tests {
749
742
offset : 0. ,
750
743
} ;
751
744
let brest_to_nancy_p = brest_to_nancy. resolve ( projection) . unwrap ( ) ;
752
- assert_eq ! ( brest_to_nancy_p. x( ) , 2.292338879356053 ) ;
753
- assert_eq ! ( brest_to_nancy_p. y( ) , 48.69669359753767 ) ;
745
+ assert_eq ! ( 2.288400083145514 , brest_to_nancy_p. x( ) ) ;
746
+ assert_eq ! ( 48.69523589360801 , brest_to_nancy_p. y( ) ) ;
754
747
}
755
748
756
749
#[ test]
757
750
fn spherical_bbox ( ) {
758
751
let paris_to_new_york = SphericalLineStringCurve :: new (
759
- line_string ! [ ( x : PARIS_LON , y : PARIS_LAT ) , ( x : NEW_YORK_LON , y : NEW_YORK_LAT ) ] ,
752
+ line_string ! [ PARIS , NEW_YORK ] ,
760
753
1. ,
761
754
) ;
762
755
let bbox = paris_to_new_york. bbox ( ) ;
763
756
764
757
assert_eq ! (
765
758
bbox. min( ) ,
766
- coord! { x: -75.00599134051316 , y: 39.71274961837565 }
759
+ coord! { x: -75.01 , y: 39.71 }
767
760
) ;
768
761
assert_eq ! (
769
762
bbox. max( ) ,
770
- coord! { x: 3.352565660016694 , y: 49.85643268390663 }
763
+ coord! { x: 3.35 , y: 49.86 }
771
764
) ;
772
765
}
773
766
@@ -777,40 +770,39 @@ mod tests {
777
770
778
771
// Intersection
779
772
let paris_to_new_york = SphericalLineStringCurve :: new (
780
- line_string ! [ ( x : PARIS_LON , y : PARIS_LAT ) , ( x : NEW_YORK_LON , y : NEW_YORK_LAT ) ] ,
773
+ line_string ! [ PARIS , NEW_YORK ] ,
781
774
1. ,
782
775
) ;
783
776
let segment = Line :: new (
784
- coord ! { x: -36.76627263796084 , y: 69.72980545457074 } ,
785
- coord ! { x: -53.52127629098692 , y: 15.34337895024332 } ,
777
+ coord ! { x: -36.77 , y: 69.73 } ,
778
+ coord ! { x: -53.52 , y: 15.34 } ,
786
779
) ;
787
780
assert_eq ! (
788
- paris_to_new_york . intersect_segment ( segment ) ,
789
- Some ( point! { x : - 42.500669938830555 , y : 51.11605974559634 } )
781
+ Some ( point! { x : - 42.50207557067806 , y : 51.11700953497436 } ) ,
782
+ paris_to_new_york . intersect_segment ( segment )
790
783
) ;
791
784
792
785
// No intersection
793
786
let segment = Line :: new (
794
- coord ! { x: -88.45243862592235 , y: 20.758717928501483 } ,
795
- coord ! { x: 19.035989490700018 , y: 41.32134615429521 } ,
787
+ coord ! { x: -88.45 , y: 20.76 } ,
788
+ coord ! { x: 19.04 , y: 41.32 } ,
796
789
) ;
797
790
assert ! ( paris_to_new_york. intersect_segment( segment) . is_none( ) ) ;
798
791
799
- // TODO: Collinear
800
- // Notes:
792
+ // Collinear: not tested
801
793
// - because of the haversine densification, the geometry is slightly different and includes more points
802
794
// than before, thus creating intersection(s) point(s).
803
795
// - is very rare in reality
804
796
805
797
// Multiple intersection
806
798
let paris_to_reykjavik_to_new_york = SphericalLineStringCurve :: new (
807
- line_string ! [ ( x : PARIS_LON , y : PARIS_LAT ) , ( x : REYKJAVIK_LON , y : REYKJAVIK_LAT ) , ( x : NEW_YORK_LON , y : NEW_YORK_LAT ) ] ,
799
+ line_string ! [ PARIS , REYKJAVIK , NEW_YORK ] ,
808
800
1. ,
809
801
) ;
810
802
811
803
let segment = Line :: new (
812
- coord ! { x: -70.77775907909825 , y: 47.835409180411006 } ,
813
- coord ! { x: 9.293636086504506 , y: 54.83039737996501 } ,
804
+ coord ! { x: -70.78 , y: 47.84 } ,
805
+ coord ! { x: 9.29 , y: 54.83 } ,
814
806
) ;
815
807
assert ! ( paris_to_reykjavik_to_new_york
816
808
. intersect_segment( segment)
0 commit comments