@@ -364,17 +364,20 @@ impl Curve for SphericalLineStringCurve {
364
364
}
365
365
366
366
fn bbox ( & self ) -> Rect {
367
- let bounding_rect = self . geom . bounding_rect ( ) . unwrap ( ) ;
368
- Rect :: new (
369
- coord ! {
370
- x: bounding_rect. min( ) . x - self . max_extent,
371
- y: bounding_rect. min( ) . y - self . max_extent,
372
- } ,
373
- coord ! {
374
- x: bounding_rect. max( ) . x + self . max_extent,
375
- y: bounding_rect. max( ) . y + self . max_extent,
376
- } ,
377
- )
367
+ let min_point = geo:: Point ( self . geom . bounding_rect ( ) . unwrap ( ) . min ( ) ) ;
368
+ let max_point = geo:: Point ( self . geom . bounding_rect ( ) . unwrap ( ) . max ( ) ) ;
369
+
370
+ // add max_extend distance in South and then West direction
371
+ let min_point_extended = min_point
372
+ . haversine_destination ( 180. , self . max_extent )
373
+ . haversine_destination ( 270. , self . max_extent ) ;
374
+
375
+ // add max_extend distance in North and then East direction
376
+ let max_point_extended = max_point
377
+ . haversine_destination ( 0. , self . max_extent )
378
+ . haversine_destination ( 90. , self . max_extent ) ;
379
+
380
+ Rect :: new ( min_point_extended, max_point_extended)
378
381
}
379
382
380
383
// Important:
@@ -634,7 +637,7 @@ mod tests {
634
637
#[ test]
635
638
fn spherical_projection ( ) {
636
639
let mut paris_to_new_york =
637
- SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. , ) ;
640
+ SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. ) ;
638
641
639
642
// Point is located on the right (north) of the curve
640
643
let projected = paris_to_new_york
@@ -730,11 +733,26 @@ mod tests {
730
733
731
734
#[ test]
732
735
fn spherical_bbox ( ) {
733
- let paris_to_new_york = SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. ) ;
736
+ let paris_to_new_york = SphericalLineStringCurve :: new (
737
+ line_string ! [
738
+ coord! { x: -7.65 , y: 51.79 } ,
739
+ coord! { x: -7.31 , y: 51.94 } ,
740
+ coord! { x: -7.31 , y: 51.54 } ,
741
+ coord! { x: -6.84 , y: 51.69 } ,
742
+ coord! { x: -6.39 , y: 51.55 } ,
743
+ ] ,
744
+ 100. ,
745
+ ) ;
734
746
let bbox = paris_to_new_york. bbox ( ) ;
735
747
736
- assert_eq ! ( bbox. min( ) , coord! { x: -75.01 , y: 39.71 } ) ;
737
- assert_eq ! ( bbox. max( ) , coord! { x: 3.35 , y: 49.86 } ) ;
748
+ assert_eq ! (
749
+ bbox. min( ) ,
750
+ coord! { x: -7.651445898208635 , y: 51.53910067075082 }
751
+ ) ;
752
+ assert_eq ! (
753
+ bbox. max( ) ,
754
+ coord! { x: -6.388541186830253 , y: 51.9408993113492 }
755
+ ) ;
738
756
}
739
757
740
758
#[ test]
0 commit comments