Skip to main content

wgs84

Macro wgs84 

Source
macro_rules! wgs84 {
    (latitude = deg($lat:expr), longitude = deg($lng:expr), altitude = m($alt:expr)) => { ... };
    (latitude = deg($lat:expr), longitude = deg($lng:expr), altitude = km($alt:expr)) => { ... };
    (latitude = rad($lat:expr), longitude = rad($lng:expr), altitude = m($alt:expr)) => { ... };
    (latitude = rad($lat:expr), longitude = rad($lng:expr), altitude = km($alt:expr)) => { ... };
}
Expand description

Constructs a Wgs84 coordinate with compile-time validated angles using unit suffixes.

This macro provides a safe way to construct WGS84 coordinates with compile-time known angles, eliminating the need for .expect() calls on the latitude validation.

§Supported Units

  • deg - degrees (for latitude and longitude)
  • rad - radians (for latitude and longitude)
  • m - meters (for altitude)
  • km - kilometers (for altitude)

§Examples

use sguaba::wgs84;

// Using degrees and meters
let location1 = wgs84!(latitude = deg(35.3619), longitude = deg(138.7280), altitude = m(2294.0));

// Using degrees and kilometers
let location2 = wgs84!(latitude = deg(35.3619), longitude = deg(138.7280), altitude = km(2.294));

// Using radians and meters
let location3 = wgs84!(latitude = rad(0.617), longitude = rad(2.413), altitude = m(2294.0));

§Compile-time validation

The following examples should fail to compile because latitude is out of range:

// Latitude > 90° should fail
let location = wgs84!(latitude = deg(91.0), longitude = deg(0.0), altitude = m(0.0));
// Latitude < -90° should fail
let location = wgs84!(latitude = deg(-91.0), longitude = deg(0.0), altitude = m(0.0));
// Latitude > π/2 radians should fail
let location = wgs84!(latitude = rad(1.58), longitude = rad(0.0), altitude = m(0.0));
// Latitude < -π/2 radians should fail
let location = wgs84!(latitude = rad(-1.58), longitude = rad(0.0), altitude = m(0.0));