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
| Method | Validation | Altitude |
|---|---|---|
new | debug_assert only | explicit |
from_lat_lon | debug_assert only | 0.0 |
new_checked | returns Option | explicit |
From<(f64, f64)> | debug_assert only | 0.0 |
From<(f64, f64, f64)> | debug_assert only | explicit |
From<[f64; 2]> | debug_assert only | 0.0 |
From<[f64; 3]> | debug_assert only | explicit |
§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: f64Latitude in degrees, positive north ([-90, 90]).
lon: f64Longitude in degrees, positive east ([-180, 180]).
alt: f64Altitude above the WGS-84 ellipsoid, in meters.
Implementations§
Source§impl GeoCoord
impl GeoCoord
Sourcepub fn new(lat: f64, lon: f64, alt: f64) -> Self
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.
Sourcepub fn from_lat_lon(lat: f64, lon: f64) -> Self
pub fn from_lat_lon(lat: f64, lon: f64) -> Self
Convenience constructor without altitude (defaults to 0.0).
Sourcepub fn new_checked(lat: f64, lon: f64, alt: f64) -> Option<Self>
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.
Sourcepub fn is_web_mercator_valid(&self) -> bool
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.
Sourcepub fn clamped_mercator(&self) -> Self
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.