Fix a crash in the trip info panel. If you happen to open a trip of a

car waiting to spawn, its total path distance is briefly 0.

Also silence the lane-changing info for the moment, until work resumes
there.
This commit is contained in:
Dustin Carlino 2021-07-03 08:28:16 -07:00
parent 160d65ca28
commit bf316fa99c
3 changed files with 18 additions and 7 deletions

View File

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

View File

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

View File

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