Struct BoundingBox

Source
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

Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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)));
Source

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

Source§

fn clone(&self) -> BoundingBox

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for BoundingBox

Source§

fn default() -> BoundingBox

Returns the “default value” for a type. Read more
Source§

impl PartialEq for BoundingBox

Source§

fn eq(&self, other: &BoundingBox) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for BoundingBox

Source§

impl StructuralPartialEq for BoundingBox

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.