Struct tilejson::Bounds

source ·
pub struct Bounds {
    pub left: f64,
    pub bottom: f64,
    pub right: f64,
    pub top: f64,
}

Fields§

§left: f64§bottom: f64§right: f64§top: f64

Implementations§

source§

impl Bounds

source

pub fn new(left: f64, bottom: f64, right: f64, top: f64) -> Self

Create a new Bounds object.

source

pub const MAX: Self = _

Create maximum bounds object in WGS84 space.

assert_eq!(
    Bounds::MAX,
    Bounds::new(-180.0, -90.0, 180.0, 90.0)
);
source

pub const MAX_TILED: Self = _

Create maximum bounds object usable with vector tiles. See https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#35-bounds

assert_eq!(
    Bounds::MAX_TILED,
    Bounds::new(-180.0, -85.05112877980659, 180.0, 85.0511287798066)
);

Trait Implementations§

source§

impl Add for Bounds

source§

fn add(self, rhs: Self) -> Self::Output

Combine two bounds, resulting in an bounding box that encloses both.

assert_eq!(
    Bounds::new(1., 3., 7., 9.) + Bounds::new(2., 2., 8., 8.),
    Bounds::new(1., 2., 8., 9.)
)
§

type Output = Bounds

The resulting type after applying the + operator.
source§

impl AddAssign for Bounds

source§

fn add_assign(&mut self, rhs: Self)

Combine another bounds into this one, resulting in an bounding box that encloses both.

let mut value = Bounds::new(1., 3., 7., 9.);
value += Bounds::new(2., 2., 8., 8.);
assert_eq!(value, Bounds::new(1., 2., 8., 9.))
source§

impl Clone for Bounds

source§

fn clone(&self) -> Bounds

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 Debug for Bounds

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Bounds

source§

fn default() -> Self

Default bounds are set to [-180, -85.05112877980659, 180, 85.0511287798066] See https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#35-bounds

assert_eq!(Bounds::MAX_TILED, Bounds::default());
source§

impl<'de> Deserialize<'de> for Bounds

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Bounds

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format Bounds struct as a comma-separated string. Accepts all precision formatting parameters as for floats.

let bounds = Bounds::new(-1.5, -2.5, 3.5, 4.5);
assert_eq!(bounds.to_string(), "-1.5,-2.5,3.5,4.5");
assert_eq!(format!("{bounds:.2}"), "-1.50,-2.50,3.50,4.50");
assert_eq!(Bounds::from_str(&bounds.to_string()).unwrap(), bounds);
source§

impl From<[f32; 4]> for Bounds

source§

fn from(value: [f32; 4]) -> Self

Parse four f32 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::from([1.0f32, 2.0f32, 3.0f32, 4.0f32])
);
source§

impl From<[f64; 4]> for Bounds

source§

fn from(value: [f64; 4]) -> Self

Parse four f64 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::from([1., 2., 3., 4.])
);
source§

impl From<[i32; 4]> for Bounds

source§

fn from(value: [i32; 4]) -> Self

Parse four i32 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::from([1, 2, 3, 4])
);
source§

impl From<(f32, f32, f32, f32)> for Bounds

source§

fn from(value: (f32, f32, f32, f32)) -> Self

Parse a tuple with four f32 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::from((1.0f32, 2.0f32, 3.0f32, 4.0f32))
);
source§

impl From<(f64, f64, f64, f64)> for Bounds

source§

fn from(value: (f64, f64, f64, f64)) -> Self

Parse a tuple with four f64 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::from((1., 2., 3., 4.))
);
source§

impl From<(i32, i32, i32, i32)> for Bounds

source§

fn from(value: (i32, i32, i32, i32)) -> Self

Parse a tuple with four i32 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::from((1, 2, 3, 4))
);
source§

impl FromStr for Bounds

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse a string of four comma-separated values as a Bounds value, same order as the Bounds::new constructor. Extra spaces are ignored.

Example
let bounds = Bounds::from_str("-1.0, -2.0, 3, 4").unwrap();
assert_eq!(bounds, Bounds::new(-1.0, -2.0, 3.0, 4.0));
§

type Err = ParseBoundsError

The associated error which can be returned from parsing.
source§

impl PartialEq for Bounds

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Bounds

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&[f32]> for Bounds

source§

fn try_from(value: &[f32]) -> Result<Self, Self::Error>

Parse four f32 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::try_from(vec![1.0f32, 2.0f32, 3.0f32, 4.0f32].as_slice()).unwrap()
);
§

type Error = ParseBoundsError

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

impl TryFrom<&[f64]> for Bounds

source§

fn try_from(value: &[f64]) -> Result<Self, Self::Error>

Parse four f64 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::try_from(vec![1., 2., 3., 4.].as_slice()).unwrap()
);
§

type Error = ParseBoundsError

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

impl TryFrom<&[i32]> for Bounds

source§

fn try_from(value: &[i32]) -> Result<Self, Self::Error>

Parse four i32 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::try_from(vec![1, 2, 3, 4].as_slice()).unwrap()
);
§

type Error = ParseBoundsError

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

impl TryFrom<Vec<f64>> for Bounds

source§

fn try_from(value: Vec<f64>) -> Result<Self, Self::Error>

Parse four f64 values as a Bounds value, same order as the Bounds::new constructor.

assert_eq!(
    Bounds::new(1., 2., 3., 4.),
    Bounds::try_from(vec![1., 2., 3., 4.]).unwrap()
);
§

type Error = ParseBoundsError

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

impl Copy for Bounds

source§

impl StructuralPartialEq for Bounds

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> 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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,