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

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

Create a new Bounds object.

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.)
)
Source§

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

type Err = ParseBoundsError

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

impl PartialEq for Bounds

Source§

fn eq(&self, other: &Bounds) -> 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 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()
);
Source§

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

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

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

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§

§

impl Freeze for Bounds

§

impl RefUnwindSafe for Bounds

§

impl Send for Bounds

§

impl Sync for Bounds

§

impl Unpin for Bounds

§

impl UnwindSafe for Bounds

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

Source§

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

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

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