Skip to main content

GeoBounds

Struct GeoBounds 

Source
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

MethodDescription
newFrom explicit sw/ne corners
from_coordsFrom west, south, east, north
from_center_radiusExpand 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

Source

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.

Source

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]).

Source

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

pub fn sw(&self) -> GeoCoord

Southwest corner.

Source

pub fn ne(&self) -> GeoCoord

Northeast corner.

Source

pub fn nw(&self) -> GeoCoord

Northwest corner.

Source

pub fn se(&self) -> GeoCoord

Southeast corner.

Source

pub fn west(&self) -> f64

West edge (longitude).

Source

pub fn south(&self) -> f64

South edge (latitude).

Source

pub fn east(&self) -> f64

East edge (longitude).

Source

pub fn north(&self) -> f64

North edge (latitude).

Source

pub fn center(&self) -> GeoCoord

Geographic center of the bounding box.

Equivalent to MapLibre’s LngLatBounds.getCenter().

Source

pub fn extend_coord(&mut self, coord: GeoCoord)

Extend the bounds to include a single geographic coordinate.

Equivalent to MapLibre’s LngLatBounds.extend(LngLat).

Source

pub fn extend_bounds(&mut self, other: &GeoBounds)

Extend the bounds to include another bounding box.

Equivalent to MapLibre’s LngLatBounds.extend(LngLatBounds).

Source

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().

Source

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().

Source

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().

Source

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

Return the bounding box as [west, south, east, north].

Trait Implementations§

Source§

impl Clone for GeoBounds

Source§

fn clone(&self) -> GeoBounds

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 GeoBounds

Source§

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

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

impl<'de> Deserialize<'de> for GeoBounds

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 GeoBounds

Source§

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

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

impl From<[f64; 4]> for GeoBounds

Source§

fn from(arr: [f64; 4]) -> Self

Create from [west, south, east, north].

Source§

impl From<GeoBounds> for [f64; 4]

Source§

fn from(b: GeoBounds) -> Self

Convert to [west, south, east, north].

Source§

impl PartialEq for GeoBounds

Source§

fn eq(&self, other: &GeoBounds) -> 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 GeoBounds

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 Copy for GeoBounds

Source§

impl StructuralPartialEq for GeoBounds

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