Add helper methods that calculate lat/lon in radians

This commit is contained in:
Paul van Tilburg 2022-02-18 22:58:39 +01:00
parent 6b62cc7797
commit 7d1a1a1c0d
1 changed files with 12 additions and 0 deletions

View File

@ -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)