use serde::{Deserialize, Serialize};
use std::fmt::Debug;
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub struct LocalDistance(pub f32);
pub const LS_IN_M: f32 = 299792458.0;
pub const LS_IN_AU: f32 = 500.0;
impl LocalDistance {
pub fn from_m(m: f32) -> Self {
LocalDistance(m / LS_IN_M)
}
pub fn as_m(&self) -> f32 {
self.0 * LS_IN_M
}
pub fn from_ls(ls: f32) -> Self {
LocalDistance(ls)
}
pub fn as_ls(&self) -> f32 {
self.0
}
pub fn from_au(au: f32) -> Self {
LocalDistance(au * LS_IN_AU)
}
pub fn as_au(&self) -> f32 {
self.0 / LS_IN_AU
}
}
impl Debug for LocalDistance {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} ls ({} au / {} m)", self.0, self.as_au(), self.as_m())
}
}