Skip to content

Commit c483623

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

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

src/curves.rs

+36-9
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,27 @@ impl Curve for SphericalLineStringCurve {
364364
}
365365

366366
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
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+
368380
Rect::new(
369381
coord! {
370-
x: bounding_rect.min().x - self.max_extent,
371-
y: bounding_rect.min().y - self.max_extent,
382+
x: min_point_extended.x(),
383+
y: min_point_extended.y(),
372384
},
373385
coord! {
374-
x: bounding_rect.max().x + self.max_extent,
375-
y: bounding_rect.max().y + self.max_extent,
386+
x: max_point_extended.x(),
387+
y: max_point_extended.y(),
376388
},
377389
)
378390
}
@@ -634,7 +646,7 @@ mod tests {
634646
#[test]
635647
fn spherical_projection() {
636648
let mut paris_to_new_york =
637-
SphericalLineStringCurve::new(line_string![PARIS, NEW_YORK], 1.,);
649+
SphericalLineStringCurve::new(line_string![PARIS, NEW_YORK], 1.);
638650

639651
// Point is located on the right (north) of the curve
640652
let projected = paris_to_new_york
@@ -730,11 +742,26 @@ mod tests {
730742

731743
#[test]
732744
fn spherical_bbox() {
733-
let paris_to_new_york = SphericalLineStringCurve::new(line_string![PARIS, NEW_YORK], 1.);
745+
let paris_to_new_york = SphericalLineStringCurve::new(
746+
line_string![
747+
coord! {x: -7.65, y: 51.79},
748+
coord! {x: -7.31, y: 51.94},
749+
coord! {x: -7.31, y: 51.54},
750+
coord! {x: -6.84, y: 51.69},
751+
coord! {x: -6.39, y: 51.55},
752+
],
753+
100.,
754+
);
734755
let bbox = paris_to_new_york.bbox();
735756

736-
assert_eq!(bbox.min(), coord! {x: -75.01, y: 39.71});
737-
assert_eq!(bbox.max(), coord! {x: 3.35, y: 49.86});
757+
assert_eq!(
758+
bbox.min(),
759+
coord! {x: -7.651445898208635, y: 51.53910067075082}
760+
);
761+
assert_eq!(
762+
bbox.max(),
763+
coord! {x: -6.388541186830253, y: 51.9408993113492}
764+
);
738765
}
739766

740767
#[test]

0 commit comments

Comments
 (0)