@@ -259,7 +259,7 @@ pub struct SphericalLineStringCurve {
259
259
260
260
impl SphericalLineStringCurve {
261
261
const DEFAULT_DENSIFY_BY : f64 = 100.0 ;
262
-
262
+
263
263
/// Splits the [`LineString`] into smaller [`Curve`]s of at most `max_len` length.
264
264
/// If the initial geometry is invalid, it returns an empty vector.
265
265
pub fn new_fragmented ( geom : LineString , max_len : f64 , max_extent : f64 ) -> Vec < Self > {
@@ -299,8 +299,10 @@ impl Curve for SphericalLineStringCurve {
299
299
300
300
fn is_valid ( & self ) -> bool {
301
301
self . geom . coords_count ( ) >= 2
302
- && ( self . geom . coords_count ( ) > 2 || !self . geom . is_closed ( ) )
303
- && ( self . geom . coords ( ) . all ( |coord| coord. x > -180.0 && coord. x < 180.0 && coord. y > -90.0 && coord. y < 90.0 ) )
302
+ && ( self . geom . coords_count ( ) > 2 || !self . geom . is_closed ( ) )
303
+ && ( self . geom . coords ( ) . all ( |coord| {
304
+ coord. x > -180.0 && coord. x < 180.0 && coord. y > -90.0 && coord. y < 90.0
305
+ } ) )
304
306
}
305
307
306
308
fn project ( & self , point : Point ) -> Result < CurveProjection , CurveError > {
@@ -584,22 +586,13 @@ mod tests {
584
586
585
587
#[ test]
586
588
fn spherical_length ( ) {
587
- let paris_to_new_york = SphericalLineStringCurve :: new (
588
- line_string ! [ PARIS , NEW_YORK ] ,
589
- 1. ,
590
- ) ;
589
+ let paris_to_new_york = SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. ) ;
591
590
assert_eq ! ( 5837415.205720471 , paris_to_new_york. length( ) ) ; // 5837415.205720471 using [`HaversineLength`] and 5853101.331803938 using [`GeodesicLength`]
592
591
593
- let lille_to_perpignan = SphericalLineStringCurve :: new (
594
- line_string ! [ LILLE , PERPIGNAN ] ,
595
- 1. ,
596
- ) ;
592
+ let lille_to_perpignan = SphericalLineStringCurve :: new ( line_string ! [ LILLE , PERPIGNAN ] , 1. ) ;
597
593
assert_eq ! ( 882995.0489150163 , lille_to_perpignan. length( ) ) ; // 882995.0489150163 using [`HaversineLength`] and 882749.856002331 using [`GeodesicLength`]
598
594
599
- let brest_to_nancy = SphericalLineStringCurve :: new (
600
- line_string ! [ BREST , NANCY ] ,
601
- 1. ,
602
- ) ;
595
+ let brest_to_nancy = SphericalLineStringCurve :: new ( line_string ! [ BREST , NANCY ] , 1. ) ;
603
596
assert_eq ! ( 785611.8752324395 , brest_to_nancy. length( ) ) ; // 785611.8752324395 using [`HaversineLength`] and 787969.3534391255 using [`GeodesicLength`]
604
597
}
605
598
@@ -640,10 +633,7 @@ mod tests {
640
633
641
634
#[ test]
642
635
fn spherical_projection ( ) {
643
- let mut paris_to_new_york = SphericalLineStringCurve :: new (
644
- line_string ! [ PARIS , NEW_YORK ] ,
645
- 1. ,
646
- ) ;
636
+ let mut paris_to_new_york = SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. , ) ;
647
637
648
638
// Point is located on the right (north) of the curve
649
639
let projected = paris_to_new_york
@@ -667,11 +657,8 @@ mod tests {
667
657
assert_eq ! ( 1963056.4000812047 , projected. distance_along_curve) ;
668
658
assert_eq ! ( 625574.8001320735 , projected. offset) ;
669
659
670
- // ################################################################################
671
- let mut new_york_to_paris = SphericalLineStringCurve :: new (
672
- line_string ! [ NEW_YORK , PARIS ] ,
673
- 1. ,
674
- ) ;
660
+ let mut new_york_to_paris =
661
+ SphericalLineStringCurve :: new ( line_string ! [ NEW_YORK , PARIS ] , 1. ) ;
675
662
676
663
// Point is located on the left (north) of the curve
677
664
let projected = new_york_to_paris
@@ -698,10 +685,8 @@ mod tests {
698
685
699
686
#[ test]
700
687
fn spherical_resolve ( ) {
701
- let mut paris_to_new_york = SphericalLineStringCurve :: new (
702
- line_string ! [ PARIS , NEW_YORK ] ,
703
- 1. ,
704
- ) ;
688
+ let mut paris_to_new_york =
689
+ SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. ) ;
705
690
706
691
let mut projection = CurveProjection {
707
692
distance_along_curve : 1000000. ,
@@ -720,10 +705,7 @@ mod tests {
720
705
assert ! ( paris_to_new_york. resolve( projection) . is_err( ) ) ;
721
706
722
707
// Test on a linestring where only the longitude changes (latitude remains almost the same)
723
- let lille_to_perpignan = SphericalLineStringCurve :: new (
724
- line_string ! [ LILLE , PERPIGNAN ] ,
725
- 1. ,
726
- ) ;
708
+ let lille_to_perpignan = SphericalLineStringCurve :: new ( line_string ! [ LILLE , PERPIGNAN ] , 1. ) ;
727
709
728
710
let projection = CurveProjection {
729
711
distance_along_curve : 500000. ,
@@ -734,10 +716,7 @@ mod tests {
734
716
assert_eq ! ( 46.13397259680868 , lille_to_perpignan_p. y( ) ) ;
735
717
736
718
// Test on a linestring where only the latitude changes (longitude remains almost the same)
737
- let brest_to_nancy = SphericalLineStringCurve :: new (
738
- line_string ! [ BREST , NANCY ] ,
739
- 1. ,
740
- ) ;
719
+ let brest_to_nancy = SphericalLineStringCurve :: new ( line_string ! [ BREST , NANCY ] , 1. ) ;
741
720
742
721
let projection = CurveProjection {
743
722
distance_along_curve : 500000. ,
@@ -750,45 +729,27 @@ mod tests {
750
729
751
730
#[ test]
752
731
fn spherical_bbox ( ) {
753
- let paris_to_new_york = SphericalLineStringCurve :: new (
754
- line_string ! [ PARIS , NEW_YORK ] ,
755
- 1. ,
756
- ) ;
732
+ let paris_to_new_york = SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. ) ;
757
733
let bbox = paris_to_new_york. bbox ( ) ;
758
734
759
- assert_eq ! (
760
- bbox. min( ) ,
761
- coord! { x: -75.01 , y: 39.71 }
762
- ) ;
763
- assert_eq ! (
764
- bbox. max( ) ,
765
- coord! { x: 3.35 , y: 49.86 }
766
- ) ;
735
+ assert_eq ! ( bbox. min( ) , coord! { x: -75.01 , y: 39.71 } ) ;
736
+ assert_eq ! ( bbox. max( ) , coord! { x: 3.35 , y: 49.86 } ) ;
767
737
}
768
738
769
739
#[ test]
770
740
fn spherical_intersect_segment ( ) {
771
741
// Note: following tests have been computed with a maximum length of curve of 100m, otherwise the curve is densified.
772
742
773
743
// Intersection
774
- let paris_to_new_york = SphericalLineStringCurve :: new (
775
- line_string ! [ PARIS , NEW_YORK ] ,
776
- 1. ,
777
- ) ;
778
- let segment = Line :: new (
779
- coord ! { x: -36.77 , y: 69.73 } ,
780
- coord ! { x: -53.52 , y: 15.34 } ,
781
- ) ;
744
+ let paris_to_new_york = SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. ) ;
745
+ let segment = Line :: new ( coord ! { x: -36.77 , y: 69.73 } , coord ! { x: -53.52 , y: 15.34 } ) ;
782
746
assert_eq ! (
783
747
Some ( point! { x: -42.50207557067806 , y: 51.11700953497436 } ) ,
784
748
paris_to_new_york. intersect_segment( segment)
785
749
) ;
786
750
787
751
// No intersection
788
- let segment = Line :: new (
789
- coord ! { x: -88.45 , y: 20.76 } ,
790
- coord ! { x: 19.04 , y: 41.32 } ,
791
- ) ;
752
+ let segment = Line :: new ( coord ! { x: -88.45 , y: 20.76 } , coord ! { x: 19.04 , y: 41.32 } ) ;
792
753
assert ! ( paris_to_new_york. intersect_segment( segment) . is_none( ) ) ;
793
754
794
755
// Collinear: not tested
@@ -797,15 +758,10 @@ mod tests {
797
758
// - is very rare in reality
798
759
799
760
// Multiple intersection
800
- let paris_to_reykjavik_to_new_york = SphericalLineStringCurve :: new (
801
- line_string ! [ PARIS , REYKJAVIK , NEW_YORK ] ,
802
- 1. ,
803
- ) ;
761
+ let paris_to_reykjavik_to_new_york =
762
+ SphericalLineStringCurve :: new ( line_string ! [ PARIS , REYKJAVIK , NEW_YORK ] , 1. ) ;
804
763
805
- let segment = Line :: new (
806
- coord ! { x: -70.78 , y: 47.84 } ,
807
- coord ! { x: 9.29 , y: 54.83 } ,
808
- ) ;
764
+ let segment = Line :: new ( coord ! { x: -70.78 , y: 47.84 } , coord ! { x: 9.29 , y: 54.83 } ) ;
809
765
assert ! ( paris_to_reykjavik_to_new_york
810
766
. intersect_segment( segment)
811
767
. is_some( ) ) ;
0 commit comments