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: f64Minimum X coordinate (west)
min_y: f64Minimum Y coordinate (south)
max_x: f64Maximum X coordinate (east)
max_y: f64Maximum Y coordinate (north)
Implementations§
Source§impl BoundingBox
impl BoundingBox
Sourcepub fn new(
min_x: f64,
min_y: f64,
max_x: f64,
max_y: f64,
) -> Result<BoundingBox, OxiGdalError>
pub fn new( min_x: f64, min_y: f64, max_x: f64, max_y: f64, ) -> Result<BoundingBox, OxiGdalError>
Sourcepub const fn new_unchecked(
min_x: f64,
min_y: f64,
max_x: f64,
max_y: f64,
) -> BoundingBox
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.
Sourcepub fn from_wsen(
west: f64,
south: f64,
east: f64,
north: f64,
) -> Result<BoundingBox, OxiGdalError>
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
Sourcepub const fn point(x: f64, y: f64) -> BoundingBox
pub const fn point(x: f64, y: f64) -> BoundingBox
Creates a point bounding box (zero area)
Sourcepub const fn world_wgs84() -> BoundingBox
pub const fn world_wgs84() -> BoundingBox
Creates the world bounds in WGS84 coordinates
Sourcepub const fn world_web_mercator() -> BoundingBox
pub const fn world_web_mercator() -> BoundingBox
Creates the world bounds in Web Mercator coordinates (EPSG:3857)
Sourcepub fn contains_point(&self, x: f64, y: f64) -> bool
pub fn contains_point(&self, x: f64, y: f64) -> bool
Returns true if this bounding box contains the given point
Sourcepub fn contains(&self, other: &BoundingBox) -> bool
pub fn contains(&self, other: &BoundingBox) -> bool
Returns true if this bounding box fully contains another bounding box
Sourcepub fn is_within(&self, other: &BoundingBox) -> bool
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().
Sourcepub fn intersects(&self, other: &BoundingBox) -> bool
pub fn intersects(&self, other: &BoundingBox) -> bool
Returns true if this bounding box intersects with another
Sourcepub fn intersection(&self, other: &BoundingBox) -> Option<BoundingBox>
pub fn intersection(&self, other: &BoundingBox) -> Option<BoundingBox>
Returns the intersection of two bounding boxes, if any
Sourcepub fn union(&self, other: &BoundingBox) -> BoundingBox
pub fn union(&self, other: &BoundingBox) -> BoundingBox
Returns the union of two bounding boxes
Sourcepub fn expand(&self, amount: f64) -> BoundingBox
pub fn expand(&self, amount: f64) -> BoundingBox
Expands the bounding box by the given amount in all directions
Sourcepub fn expand_to_include(&self, x: f64, y: f64) -> BoundingBox
pub fn expand_to_include(&self, x: f64, y: f64) -> BoundingBox
Expands the bounding box to include the given point
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns true if the bounding box is valid (finite values, min <= max)
Sourcepub const fn as_array(&self) -> [f64; 4]
pub const fn as_array(&self) -> [f64; 4]
Returns the bounding box as an array [min_x, min_y, max_x, max_y]
Sourcepub const fn as_wsen(&self) -> (f64, f64, f64, f64)
pub const fn as_wsen(&self) -> (f64, f64, f64, f64)
Returns the bounding box as (west, south, east, north) tuple
Sourcepub fn from_array(arr: [f64; 4]) -> Result<BoundingBox, OxiGdalError>
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
impl Clone for BoundingBox
Source§fn clone(&self) -> BoundingBox
fn clone(&self) -> BoundingBox
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BoundingBox
impl Debug for BoundingBox
Source§impl Default for BoundingBox
impl Default for BoundingBox
Source§fn default() -> BoundingBox
fn default() -> BoundingBox
Source§impl<'de> Deserialize<'de> for BoundingBox
impl<'de> Deserialize<'de> for BoundingBox
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<BoundingBox, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<BoundingBox, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for BoundingBox
impl Display for BoundingBox
Source§impl PartialEq for BoundingBox
impl PartialEq for BoundingBox
Source§impl Serialize for BoundingBox
impl Serialize for BoundingBox
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for BoundingBox
impl StructuralPartialEq for BoundingBox
Auto Trait Implementations§
impl Freeze for BoundingBox
impl RefUnwindSafe for BoundingBox
impl Send for BoundingBox
impl Sync for BoundingBox
impl Unpin for BoundingBox
impl UnsafeUnpin for BoundingBox
impl UnwindSafe for BoundingBox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.