diff --git a/src/nature.rs b/src/nature.rs index 6d16b69..a873c25 100644 --- a/src/nature.rs +++ b/src/nature.rs @@ -84,19 +84,20 @@ pub fn ring_density(radius: f32) -> f32 { } pub fn readable_distance(distance: f64) -> String { - if distance > LIGHTYEAR2METER * 0.001 { + let abs_distance = distance.abs(); + if abs_distance > LIGHTYEAR2METER * 0.001 { let lightyears = distance / LIGHTYEAR2METER; return format!("{lightyears:.3}ly"); } - if distance >= 1.0e10 { + if abs_distance >= 1.0e10 { let gigameters = distance * 1.0e-9; return format!("{gigameters:.1}Gm"); } - if distance >= 1.0e7 { + if abs_distance >= 1.0e7 { let megameters = distance * 1.0e-6; return format!("{megameters:.1}Mm"); } - if distance >= 1.0e4 { + if abs_distance >= 1.0e4 { let kilometers = distance * 1.0e-3; return format!("{kilometers:.1}km"); }