Skip to main content

BoundingBox

Struct BoundingBox 

Source
pub struct BoundingBox {
    pub min_x: f64,
    pub min_y: f64,
    pub max_x: f64,
    pub max_y: f64,
}
Expand description

A 2D bounding box in any coordinate system

The bounding box is defined by its minimum and maximum coordinates. Coordinates can be in any unit (degrees, meters, etc.) depending on the CRS.

Fields§

§min_x: f64

Minimum X coordinate (west)

§min_y: f64

Minimum Y coordinate (south)

§max_x: f64

Maximum X coordinate (east)

§max_y: f64

Maximum Y coordinate (north)

Implementations§

Source§

impl BoundingBox

Source

pub fn new( min_x: f64, min_y: f64, max_x: f64, max_y: f64, ) -> Result<BoundingBox, OxiGdalError>

Creates a new bounding box from min/max coordinates

§Arguments
  • min_x - Minimum X coordinate
  • min_y - Minimum Y coordinate
  • max_x - Maximum X coordinate
  • max_y - Maximum Y coordinate
§Errors

Returns an error if min > max for either axis

Source

pub const fn new_unchecked( min_x: f64, min_y: f64, max_x: f64, max_y: f64, ) -> BoundingBox

Creates a new bounding box without validation

§Safety

This is safe but may create invalid bounding boxes where min > max. Use BoundingBox::new for validated construction.

Source

pub fn from_wsen( west: f64, south: f64, east: f64, north: f64, ) -> Result<BoundingBox, OxiGdalError>

Creates a bounding box from (west, south, east, north) coordinates

This is a common ordering used in many geospatial APIs.

§Errors

Returns an error if coordinates are invalid

Source

pub const fn point(x: f64, y: f64) -> BoundingBox

Creates a point bounding box (zero area)

Source

pub const fn world_wgs84() -> BoundingBox

Creates the world bounds in WGS84 coordinates

Source

pub const fn world_web_mercator() -> BoundingBox

Creates the world bounds in Web Mercator coordinates (EPSG:3857)

Source

pub const fn min_x(&self) -> f64

Returns the minimum X coordinate (west)

Source

pub const fn min_y(&self) -> f64

Returns the minimum Y coordinate (south)

Source

pub const fn max_x(&self) -> f64

Returns the maximum X coordinate (east)

Source

pub const fn max_y(&self) -> f64

Returns the maximum Y coordinate (north)

Source

pub fn width(&self) -> f64

Returns the width of the bounding box

Source

pub fn height(&self) -> f64

Returns the height of the bounding box

Source

pub fn area(&self) -> f64

Returns the area of the bounding box

Source

pub fn center(&self) -> (f64, f64)

Returns the center point of the bounding box

Source

pub fn contains_point(&self, x: f64, y: f64) -> bool

Returns true if this bounding box contains the given point

Source

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

Returns true if this bounding box fully contains another bounding box

Source

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

Returns true if this bounding box is fully within another bounding box

This is the inverse of contains().

Source

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

Returns true if this bounding box intersects with another

Source

pub fn intersection(&self, other: &BoundingBox) -> Option<BoundingBox>

Returns the intersection of two bounding boxes, if any

Source

pub fn union(&self, other: &BoundingBox) -> BoundingBox

Returns the union of two bounding boxes

Source

pub fn expand(&self, amount: f64) -> BoundingBox

Expands the bounding box by the given amount in all directions

Source

pub fn expand_to_include(&self, x: f64, y: f64) -> BoundingBox

Expands the bounding box to include the given point

Source

pub fn is_empty(&self) -> bool

Returns true if the bounding box has zero area

Source

pub fn is_valid(&self) -> bool

Returns true if the bounding box is valid (finite values, min <= max)

Source

pub const fn as_array(&self) -> [f64; 4]

Returns the bounding box as an array [min_x, min_y, max_x, max_y]

Source

pub const fn as_wsen(&self) -> (f64, f64, f64, f64)

Returns the bounding box as (west, south, east, north) tuple

Source

pub fn from_array(arr: [f64; 4]) -> Result<BoundingBox, OxiGdalError>

Creates a bounding box from an array [min_x, min_y, max_x, max_y]

§Errors

Returns an error if the array represents an invalid bounding box

Trait Implementations§

Source§

impl Clone for BoundingBox

Source§

fn clone(&self) -> BoundingBox

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 BoundingBox

Source§

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

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

impl Default for BoundingBox

Source§

fn default() -> BoundingBox

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

impl<'de> Deserialize<'de> for BoundingBox

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<BoundingBox, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl Display for BoundingBox

Source§

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

Formats the value using the given formatter. 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 Serialize for BoundingBox

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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