pub struct GeoBounds { /* private fields */ }Expand description
A geographic bounding box defined by its southwest and northeast corners in WGS-84 degrees.
This is the Rust equivalent of MapLibre GL JS’s LngLatBounds and
Mapbox GL JS’s LngLatBounds.
§Construction
| Method | Description |
|---|---|
new | From explicit sw/ne corners |
from_coords | From west, south, east, north |
from_center_radius | Expand a center point by a radius in meters |
From<[f64; 4]> | [west, south, east, north] |
§Antimeridian
When sw.lon > ne.lon, the bounds wrap across the 180th meridian.
Use adjust_antimeridian to unwrap
into a contiguous longitude range (ne.lon may exceed 180).
§Display
Formats as "GeoBounds(sw: (lat, lon), ne: (lat, lon))".
Implementations§
Source§impl GeoBounds
impl GeoBounds
Sourcepub fn new(sw: GeoCoord, ne: GeoCoord) -> Self
pub fn new(sw: GeoCoord, ne: GeoCoord) -> Self
Create a geographic bounding box from explicit southwest and northeast corners.
The caller should ensure sw.lat <= ne.lat. Longitude may
have sw.lon > ne.lon to represent antimeridian-crossing bounds.
Sourcepub fn from_coords(west: f64, south: f64, east: f64, north: f64) -> Self
pub fn from_coords(west: f64, south: f64, east: f64, north: f64) -> Self
Create a geographic bounding box from edge values.
Equivalent to MapLibre’s new LngLatBounds([west, south, east, north]).
Sourcepub fn from_center_radius(center: GeoCoord, radius_m: f64) -> Self
pub fn from_center_radius(center: GeoCoord, radius_m: f64) -> Self
Create a bounding box by expanding a center point by a radius in meters.
Uses the same approximation as MapLibre’s LngLatBounds.fromLngLat:
latitude accuracy is computed from the Earth’s equatorial
circumference, and longitude accuracy is scaled by cos(lat).
§Arguments
center- The center geographic coordinate.radius_m- Distance in meters to expand in all directions.
Sourcepub fn center(&self) -> GeoCoord
pub fn center(&self) -> GeoCoord
Geographic center of the bounding box.
Equivalent to MapLibre’s LngLatBounds.getCenter().
Sourcepub fn extend_coord(&mut self, coord: GeoCoord)
pub fn extend_coord(&mut self, coord: GeoCoord)
Extend the bounds to include a single geographic coordinate.
Equivalent to MapLibre’s LngLatBounds.extend(LngLat).
Sourcepub fn extend_bounds(&mut self, other: &GeoBounds)
pub fn extend_bounds(&mut self, other: &GeoBounds)
Extend the bounds to include another bounding box.
Equivalent to MapLibre’s LngLatBounds.extend(LngLatBounds).
Sourcepub fn contains_coord(&self, coord: &GeoCoord) -> bool
pub fn contains_coord(&self, coord: &GeoCoord) -> bool
Check if a geographic coordinate is within the bounding box.
Handles antimeridian-crossing bounds (where west > east).
Equivalent to MapLibre’s LngLatBounds.contains().
Sourcepub fn intersects(&self, other: &GeoBounds) -> bool
pub fn intersects(&self, other: &GeoBounds) -> bool
Check if this bounding box intersects another.
Returns true if the bounding boxes share any area, including
cases where they only touch along an edge or at a corner.
Properly handles cases where either or both bounding boxes cross the antimeridian.
Equivalent to MapLibre’s LngLatBounds.intersects().
Sourcepub fn adjust_antimeridian(&self) -> Self
pub fn adjust_antimeridian(&self) -> Self
Adjust bounds that cross the antimeridian so that
ne.lon >= sw.lon.
When sw.lon > ne.lon (crossing the 180th meridian), this adds
360 to ne.lon so the bounds form a contiguous longitude range.
The resulting ne.lon may exceed 180.
Equivalent to MapLibre’s LngLatBounds.adjustAntiMeridian().