pub struct BoundingBox {
pub min_lat: f64,
pub max_lat: f64,
pub min_lon: f64,
pub max_lon: f64,
}
Expand description
A bounding box composed by 2 geolocations
Fields§
§min_lat: f64
§max_lat: f64
§min_lon: f64
§max_lon: f64
Implementations§
Source§impl BoundingBox
impl BoundingBox
Sourcepub fn new() -> BoundingBox
pub fn new() -> BoundingBox
Create a new BoudingBox
with default values
§Example
let b=geohashrust::BoundingBox::new();
assert!(b.min_lat==0.0);
assert!(b.min_lon==0.0);
assert!(b.max_lat==0.0);
assert!(b.max_lon==0.0);
Sourcepub fn from_coordinates(
minlat: f64,
maxlat: f64,
minlon: f64,
maxlon: f64,
) -> BoundingBox
pub fn from_coordinates( minlat: f64, maxlat: f64, minlon: f64, maxlon: f64, ) -> BoundingBox
Create a new BoudingBox
with 4 coordinates
§Example
let b=geohashrust::BoundingBox::from_coordinates(34.0, 12.0, 78.0, 56.0);
assert!(b.min_lat==12.0);
assert!(b.min_lon==56.0);
assert!(b.max_lat==34.0);
assert!(b.max_lon==78.0);
Sourcepub fn from_geolocations(p1: &GeoLocation, p2: &GeoLocation) -> BoundingBox
pub fn from_geolocations(p1: &GeoLocation, p2: &GeoLocation) -> BoundingBox
Creates a new BoundingBox
with 2 GeoLocations
§Example
let box1=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude:23.0,
longitude:89.0,
},
&geohashrust::GeoLocation{
latitude:67.0,
longitude:45.0,
},
);
assert!(box1.min_lat==23.0);
assert!(box1.min_lon==45.0);
assert!(box1.max_lat==67.0);
assert!(box1.max_lon==89.0);
Sourcepub fn merged(one: &BoundingBox, other: &BoundingBox) -> BoundingBox
pub fn merged(one: &BoundingBox, other: &BoundingBox) -> BoundingBox
Creates a new BoundingBox
with the merge of 2 BoundingBoxes
§Example
let box1=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
let box2=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 123.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 145.0,
},
);
let box3=geohashrust::BoundingBox::merged(&box1, &box2);
assert_eq!(box3.min_lat, 23.0);
assert_eq!(box3.min_lon, 45.0);
assert_eq!(box3.max_lat, 123.0);
assert_eq!(box3.max_lon, 145.0);
Sourcepub fn center(&self) -> GeoLocation
pub fn center(&self) -> GeoLocation
Get the center point of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.center().latitude, 45.0);
assert_eq!(b.center().longitude, 67.0);
Sourcepub fn top_left(&self) -> GeoLocation
pub fn top_left(&self) -> GeoLocation
Get the top-left point of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.top_left().latitude, 67.0);
assert_eq!(b.top_left().longitude, 45.0);
Sourcepub fn top_right(&self) -> GeoLocation
pub fn top_right(&self) -> GeoLocation
Get the top-right point of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.top_right().latitude, 67.0);
assert_eq!(b.top_right().longitude, 89.0);
Sourcepub fn bottom_left(&self) -> GeoLocation
pub fn bottom_left(&self) -> GeoLocation
Get the bottom-left point of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.bottom_left().latitude, 23.0);
assert_eq!(b.bottom_left().longitude, 45.0);
Sourcepub fn bottom_right(&self) -> GeoLocation
pub fn bottom_right(&self) -> GeoLocation
Get the bottom-right point of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.bottom_right().latitude, 23.0);
assert_eq!(b.bottom_right().longitude, 89.0);
Sourcepub fn latitude_range(&self) -> f64
pub fn latitude_range(&self) -> f64
Get the latitude range of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.latitude_range(), 44.0);
Sourcepub fn longitude_range(&self) -> f64
pub fn longitude_range(&self) -> f64
Get the longitude range of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 99.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.longitude_range(), 54.0);
Sourcepub fn latitude_error(&self) -> f64
pub fn latitude_error(&self) -> f64
Get the latitude error from the center point of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.latitude_error(), 22.0);
Sourcepub fn longitude_error(&self) -> f64
pub fn longitude_error(&self) -> f64
Get the longitude error from the center point of the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 99.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert_eq!(b.longitude_error(), 27.0);
Sourcepub fn contains(&self, point: &GeoLocation) -> bool
pub fn contains(&self, point: &GeoLocation) -> bool
Test if a GeoLocation
is in the bounding box
§Example
let b=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 99.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
assert!(b.contains(&geohashrust::GeoLocation::from_coordinates(33.0, 55.0)));
assert!(!b.contains(&geohashrust::GeoLocation::from_coordinates(13.0, 55.0)));
Sourcepub fn merge_with(&mut self, other: &BoundingBox)
pub fn merge_with(&mut self, other: &BoundingBox)
Merge another BoundingBox
into this one
§Example
let mut box1=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 23.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 45.0,
},
);
let box2=geohashrust::BoundingBox::from_geolocations(
&geohashrust::GeoLocation{
latitude: 123.0,
longitude: 89.0,
},
&geohashrust::GeoLocation{
latitude: 67.0,
longitude: 145.0,
},
);
box1.merge_with(&box2);
assert_eq!(box1.min_lat, 23.0);
assert_eq!(box1.min_lon, 45.0);
assert_eq!(box1.max_lat, 123.0);
assert_eq!(box1.max_lon, 145.0);
Trait Implementations§
Source§impl Clone for BoundingBox
impl Clone for BoundingBox
Source§fn clone(&self) -> BoundingBox
fn clone(&self) -> BoundingBox
Returns a copy 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 Default for BoundingBox
impl Default for BoundingBox
Source§fn default() -> BoundingBox
fn default() -> BoundingBox
Returns the “default value” for a type. Read more
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 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