Skip to content

Commit 2d083b2

Browse files
committed
bbox calculation with bearings
1 parent 4bca22b commit 2d083b2

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

src/curves.rs

+33-15
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,20 @@ impl Curve for SphericalLineStringCurve {
364364
}
365365

366366
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)
378381
}
379382

380383
// Important:
@@ -634,7 +637,7 @@ mod tests {
634637
#[test]
635638
fn spherical_projection() {
636639
let mut paris_to_new_york =
637-
SphericalLineStringCurve::new(line_string![PARIS, NEW_YORK], 1.,);
640+
SphericalLineStringCurve::new(line_string![PARIS, NEW_YORK], 1.);
638641

639642
// Point is located on the right (north) of the curve
640643
let projected = paris_to_new_york
@@ -730,11 +733,26 @@ mod tests {
730733

731734
#[test]
732735
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+
);
734746
let bbox = paris_to_new_york.bbox();
735747

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+
);
738756
}
739757

740758
#[test]

0 commit comments

Comments
 (0)