make sure we're not exceeding speed limit...

This commit is contained in:
Dustin Carlino 2018-08-28 13:37:14 -07:00
parent 1845e5881b
commit 6e3f246877

View File

@ -241,6 +241,11 @@ impl Car {
self.speed = new_speed; self.speed = new_speed;
loop { loop {
let current_speed_limit = self.on.speed_limit(map);
if self.speed > current_speed_limit {
return Err(InvariantViolated(format!("{} is going {} on {:?}, which has a speed limit of {}", self.id, self.speed, self.on, current_speed_limit)));
}
let leftover_dist = self.dist_along - self.on.length(map); let leftover_dist = self.dist_along - self.on.length(map);
// == 0.0 is important! If no floating point imprecision happens, cars will stop RIGHT // == 0.0 is important! If no floating point imprecision happens, cars will stop RIGHT
// at the end of a lane, with exactly 0 leftover distance. We don't want to bump them // at the end of a lane, with exactly 0 leftover distance. We don't want to bump them