@@ -364,15 +364,23 @@ impl Curve for SphericalLineStringCurve {
364
364
}
365
365
366
366
fn bbox ( & self ) -> Rect {
367
- let bounding_rect = self . geom . bounding_rect ( ) . unwrap ( ) ;
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. haversine_destination ( 180. , self . max_extent ) . haversine_destination ( 270. , self . max_extent ) ;
372
+
373
+ // add max_extend distance in North and then East direction
374
+ let max_point_extended = max_point. haversine_destination ( 0. , self . max_extent ) . haversine_destination ( 90. , self . max_extent ) ;
375
+
368
376
Rect :: new (
369
377
coord ! {
370
- x: bounding_rect . min ( ) . x - self . max_extent ,
371
- y: bounding_rect . min ( ) . y - self . max_extent ,
378
+ x: min_point_extended . x ( ) ,
379
+ y: min_point_extended . y ( ) ,
372
380
} ,
373
381
coord ! {
374
- x: bounding_rect . max ( ) . x + self . max_extent ,
375
- y: bounding_rect . max ( ) . y + self . max_extent ,
382
+ x: max_point_extended . x ( ) ,
383
+ y: max_point_extended . y ( ) ,
376
384
} ,
377
385
)
378
386
}
@@ -730,11 +738,20 @@ mod tests {
730
738
731
739
#[ test]
732
740
fn spherical_bbox ( ) {
733
- let paris_to_new_york = SphericalLineStringCurve :: new ( line_string ! [ PARIS , NEW_YORK ] , 1. ) ;
741
+ let paris_to_new_york = SphericalLineStringCurve :: new ( line_string !
742
+ [
743
+ coord! { x: -7.65 , y: 51.79 } ,
744
+ coord! { x: -7.31 , y: 51.94 } ,
745
+ coord! { x: -7.31 , y: 51.54 } ,
746
+ coord! { x: -6.84 , y: 51.69 } ,
747
+ coord! { x: -6.39 , y: 51.55 } ,
748
+ ] ,
749
+ 100. ,
750
+ ) ;
734
751
let bbox = paris_to_new_york. bbox ( ) ;
735
752
736
- assert_eq ! ( bbox. min( ) , coord! { x: -75.01 , y: 39.71 } ) ;
737
- assert_eq ! ( bbox. max( ) , coord! { x: 3.35 , y: 49.86 } ) ;
753
+ assert_eq ! ( bbox. min( ) , coord! { x: -7.651445898208635 , y: 51.53910067075082 } ) ;
754
+ assert_eq ! ( bbox. max( ) , coord! { x: - 6.388541186830253 , y: 51.9408993113492 } ) ;
738
755
}
739
756
740
757
#[ test]
0 commit comments