Struct geohashrust::BoundingBox [] [src]

pub struct BoundingBox {
    pub min_lat: f64,
    pub max_lat: f64,
    pub min_lon: f64,
    pub max_lon: f64,
}

A bounding box composed by 2 geolocations

Fields

Methods

impl BoundingBox
[src]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl Default for BoundingBox
[src]

Returns the "default value" for a type. Read more

impl Clone for BoundingBox
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Copy for BoundingBox
[src]

impl PartialEq for BoundingBox
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.