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 more