pub struct BoundingBox {
pub min_lat: f64,
pub max_lat: f64,
pub min_lon: f64,
pub max_lon: f64,
}Expand description
An axis-aligned geographic bounding box defined by min/max lat and lon.
Coordinates are in degrees (latitude: [-90, 90], longitude: [-180, 180]). This struct does not handle anti-meridian crossing (bounding boxes that wrap around longitude ±180°). For those use cases, split into two boxes.
§Examples
use scirs2_spatial::geo::BoundingBox;
let bbox = BoundingBox::new(48.0, 52.0, -1.0, 3.0).unwrap();
assert!(bbox.contains(50.0, 1.0));
assert!(!bbox.contains(53.0, 1.0));Fields§
§min_lat: f64Minimum latitude in degrees
max_lat: f64Maximum latitude in degrees
min_lon: f64Minimum longitude in degrees
max_lon: f64Maximum longitude in degrees
Implementations§
Source§impl BoundingBox
impl BoundingBox
Sourcepub fn new(
min_lat: f64,
max_lat: f64,
min_lon: f64,
max_lon: f64,
) -> SpatialResult<Self>
pub fn new( min_lat: f64, max_lat: f64, min_lon: f64, max_lon: f64, ) -> SpatialResult<Self>
Create a new BoundingBox.
§Arguments
min_lat- Minimum latitude in degreesmax_lat- Maximum latitude in degreesmin_lon- Minimum longitude in degreesmax_lon- Maximum longitude in degrees
§Errors
Returns SpatialError::ValueError if:
min_lat > max_latmin_lon > max_lon- Any value is out of range (lat ∉ [-90, 90], lon ∉ [-180, 180])
Sourcepub fn from_points(points: &[(f64, f64)]) -> SpatialResult<Self>
pub fn from_points(points: &[(f64, f64)]) -> SpatialResult<Self>
Sourcepub fn contains(&self, lat: f64, lon: f64) -> bool
pub fn contains(&self, lat: f64, lon: f64) -> bool
Test whether a geographic point is inside (or on the boundary of) this box.
§Arguments
lat- Latitude in degreeslon- Longitude in degrees
Sourcepub fn intersects(&self, other: &BoundingBox) -> bool
pub fn intersects(&self, other: &BoundingBox) -> bool
Test whether two bounding boxes overlap (share any area or boundary point).
Sourcepub fn expand(&self, margin_deg: f64) -> SpatialResult<BoundingBox>
pub fn expand(&self, margin_deg: f64) -> SpatialResult<BoundingBox>
Sourcepub fn width_deg(&self) -> f64
pub fn width_deg(&self) -> f64
Return the width of the bounding box in degrees (longitude span).
Sourcepub fn height_deg(&self) -> f64
pub fn height_deg(&self) -> f64
Return the height of the bounding box in degrees (latitude span).
Trait Implementations§
Source§impl Clone for BoundingBox
impl Clone for BoundingBox
Source§fn clone(&self) -> BoundingBox
fn clone(&self) -> BoundingBox
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BoundingBox
impl Debug for BoundingBox
Source§impl PartialEq for BoundingBox
impl PartialEq for BoundingBox
impl Copy for BoundingBox
impl StructuralPartialEq for BoundingBox
Auto Trait Implementations§
impl Freeze for BoundingBox
impl RefUnwindSafe for BoundingBox
impl Send for BoundingBox
impl Sync for BoundingBox
impl Unpin for BoundingBox
impl UnsafeUnpin for BoundingBox
impl UnwindSafe for BoundingBox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.