diff --git a/src/position.rs b/src/position.rs index 3e09cc1..f3b5569 100644 --- a/src/position.rs +++ b/src/position.rs @@ -8,6 +8,8 @@ use cached::proc_macro::cached; use geocoding::{Forward, Openstreetmap, Point}; use rocket::tokio; +use std::f64::consts::PI; + /// A (geocoded) position. /// /// This is used for measuring and communication positions directly on the Earth as latitude and @@ -46,6 +48,16 @@ impl Position { (self.lon * 10_000.0).round() as i32 } + /// Returns the latitude in radians. + pub(crate) fn lat_as_rad(&self) -> f64 { + self.lat * PI / 180.0 + } + + /// Returns the longitude in radians. + pub(crate) fn lon_as_rad(&self) -> f64 { + self.lon * PI / 180.0 + } + /// Returns the latitude as a string with the given precision. pub(crate) fn lat_as_str(&self, precision: usize) -> String { format!("{:.*}", precision, self.lat)