diff --git a/game/src/info/trip.rs b/game/src/info/trip.rs index 0e65c25e16..935545b17a 100644 --- a/game/src/info/trip.rs +++ b/game/src/info/trip.rs @@ -143,7 +143,7 @@ pub fn ongoing( details, phases, &app.primary.map, - Some(props.dist_crossed / props.total_dist), + Some(props.dist_crossed.safe_percent(props.total_dist)), )); Widget::col(col) } diff --git a/geom/src/distance.rs b/geom/src/distance.rs index 5fb1080c1d..b08c06e1c2 100644 --- a/geom/src/distance.rs +++ b/geom/src/distance.rs @@ -102,6 +102,15 @@ impl Distance { } } } + + /// Calculates a percentage, usually in [0.0, 1.0], of self / other. If the denominator is + /// zero, returns 0%. + pub fn safe_percent(self, other: Distance) -> f64 { + if other == Distance::ZERO { + return 0.0; + } + self / other + } } impl fmt::Display for Distance { diff --git a/sim/src/mechanics/driving.rs b/sim/src/mechanics/driving.rs index 82f628dd87..6fc5c3322f 100644 --- a/sim/src/mechanics/driving.rs +++ b/sim/src/mechanics/driving.rs @@ -1123,12 +1123,14 @@ impl DrivingSimState { ) { // TODO Can downgrade this to an alert or debug once active work has settled down - info!( - "{} is starting to change lanes from {} to {}", - car.vehicle.id, - car.router.head(), - target_lane - ); + if false { + info!( + "{} is starting to change lanes from {} to {}", + car.vehicle.id, + car.router.head(), + target_lane + ); + } // Exit the old queue (leaving a dynamic blockage in place) self.queues