diff --git a/src/hud.rs b/src/hud.rs index 982e504..a29b7f2 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -878,10 +878,10 @@ fn update_speedometer( // Atmospheric conditions let mut atmo = String::new(); if let Some(val) = settings.atmo_altitude { - atmo += format!("Altitude: {val:.6}\n").as_str(); + atmo += format!("Altitude: {}m\n", nature::readable_si(val as f64)).as_str(); } if let Some(val) = settings.atmo_pressure { - atmo += format!("Pressure: {val:.6}\n").as_str(); + atmo += format!("Pressure: {}bar\n", nature::readable_si(val as f64)).as_str(); } speed_text.sections[0].value = atmo; @@ -897,7 +897,8 @@ fn update_speedometer( }; // Velocity relative to target - speed_text.sections[2].value = if let Ok(target_v) = q_target.get_single() { let delta_v = (target_v.0 - cam_v.0).length(); + speed_text.sections[2].value = if let Ok(target_v) = q_target.get_single() { + let delta_v = (target_v.0 - cam_v.0).length(); if delta_v > 0.0001 { format!("Δv {}\n", nature::readable_speed(delta_v)) } else { diff --git a/src/nature.rs b/src/nature.rs index 3c5cb5b..ad1e7f8 100644 --- a/src/nature.rs +++ b/src/nature.rs @@ -155,6 +155,21 @@ pub fn readable_speed(speed: f64) -> String { } } +pub fn readable_si(value: f64) -> String { + if value > 1e10 { + return format!("{:.3} G", value / 1e9); + } else if value > 1e7 { + return format!("{:.3} M", value / 1e6); + } else if value > 1e4 { + return format!("{:.3} k", value / 1e3); + } else if value < 1e-2 { + return format!("{:.3} m", value * 1e3); + } else if value < 1e-5 { + return format!("{:.3} µ", value * 1e3); + } + return format!("{:.3} ", value); +} + pub fn lorentz_factor(speed: f64) -> f64 { (1.0 - (speed.powf(2.0) / C.powf(2.0))).powf(-0.5) }