Skip to main content

GeoCoord

Struct GeoCoord 

Source
pub struct GeoCoord {
    pub lat: f64,
    pub lon: f64,
    pub alt: f64,
}
Expand description

A geographic coordinate in WGS-84 (latitude / longitude in degrees, altitude in meters).

§Construction

MethodValidationAltitude
newdebug_assert onlyexplicit
from_lat_londebug_assert only0.0
new_checkedreturns Optionexplicit
From<(f64, f64)>debug_assert only0.0
From<(f64, f64, f64)>debug_assert onlyexplicit
From<[f64; 2]>debug_assert only0.0
From<[f64; 3]>debug_assert onlyexplicit

§Default

Default returns Null Island: (0, 0, 0).

§Display

Formats as "51.100000 N 17.000000 E 100.0m" (absolute lat/lon with hemisphere suffix).

Fields§

§lat: f64

Latitude in degrees, positive north ([-90, 90]).

§lon: f64

Longitude in degrees, positive east ([-180, 180]).

§alt: f64

Altitude above the WGS-84 ellipsoid, in meters.

Implementations§

Source§

impl GeoCoord

Source

pub fn new(lat: f64, lon: f64, alt: f64) -> Self

Create a new geographic coordinate.

§Panics (debug only)

Debug-asserts that latitude is in [-90, 90] and longitude is in [-180, 180], with a small tolerance for floating-point rounding. In release builds the values are unchecked – use new_checked when the inputs come from untrusted sources.

Source

pub fn from_lat_lon(lat: f64, lon: f64) -> Self

Convenience constructor without altitude (defaults to 0.0).

Source

pub fn new_checked(lat: f64, lon: f64, alt: f64) -> Option<Self>

Checked constructor that returns None for out-of-range values.

Valid ranges: latitude [-90, 90], longitude [-180, 180]. Altitude is unrestricted.

Source

pub fn is_web_mercator_valid(&self) -> bool

Whether this coordinate is within the valid range for Web Mercator projection.

Returns true when |lat| <= 85.051129 and |lon| <= 180.

Source

pub fn clamped_mercator(&self) -> Self

Clamp latitude to the Web Mercator valid range and wrap longitude to [-180, 180].

Note: latitude is clamped (saturated), but longitude is wrapped via modular arithmetic so that e.g. 200.0 becomes -160.0. Altitude is preserved unchanged.

Trait Implementations§

Source§

impl Clone for GeoCoord

Source§

fn clone(&self) -> GeoCoord

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 GeoCoord

Source§

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

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

impl Default for GeoCoord

Source§

fn default() -> Self

Returns Null Island: (lat=0, lon=0, alt=0).

Source§

impl<'de> Deserialize<'de> for GeoCoord

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 GeoCoord

Source§

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

Formats as "51.100000 N 17.000000 E 100.0m".

Source§

impl From<[f64; 2]> for GeoCoord

Source§

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

Create from [lat, lon] with altitude 0.

Source§

impl From<[f64; 3]> for GeoCoord

Source§

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

Create from [lat, lon, alt].

Source§

impl From<(f64, f64)> for GeoCoord

Source§

fn from((lat, lon): (f64, f64)) -> Self

Create from (lat, lon) with altitude 0.

Source§

impl From<(f64, f64, f64)> for GeoCoord

Source§

fn from((lat, lon, alt): (f64, f64, f64)) -> Self

Create from (lat, lon, alt).

Source§

impl From<GeoCoord> for [f64; 3]

Source§

fn from(c: GeoCoord) -> Self

Convert to [lat, lon, alt].

Source§

impl From<GeoCoord> for (f64, f64, f64)

Source§

fn from(c: GeoCoord) -> Self

Convert to (lat, lon, alt).

Source§

impl PartialEq for GeoCoord

Source§

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

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 GeoCoord

Source§

impl StructuralPartialEq for GeoCoord

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