fix a path trace bug for paths with one step, but no geometry

This commit is contained in:
Dustin Carlino 2018-11-21 10:00:33 -08:00
parent f3c76c4416
commit ca95c58b3b
4 changed files with 20 additions and 9 deletions

View File

@ -42,6 +42,9 @@ impl PathStep {
if dist_ahead < 0.0 * si::M {
panic!("Negative dist_ahead?! {}", dist_ahead);
}
if dist_ahead == 0.0 * si::M {
return None;
}
match self {
PathStep::Lane(id) => {
@ -137,7 +140,7 @@ impl Path {
map: &Map,
start_dist: si::Meter<f64>,
dist_ahead: si::Meter<f64>,
) -> Trace {
) -> Option<Trace> {
let mut pts_so_far: Option<PolyLine> = None;
let mut dist_remaining = dist_ahead;
@ -153,21 +156,24 @@ impl Path {
}
// Special case the first step.
// TODO I think should modify start_dist here for ContraflowLane
if let Some((pts, dist)) = self.steps[0].slice(map, start_dist, dist_remaining) {
pts_so_far = Some(pts);
dist_remaining = dist;
}
if self.steps.len() == 1 {
// TODO uh, there's one case where this won't work
return pts_so_far.unwrap();
// It's possible there are paths on their last step that're effectively empty, because
// they're a 0-length turn, or something like a pedestrian crossing a front path and
// immediately getting on a bike.
return pts_so_far;
}
// Crunch through the intermediate steps, as long as we can.
for i in 1..self.steps.len() {
if dist_remaining <= 0.0 * si::M {
return pts_so_far.unwrap();
// We know there's at least some geometry if we made it here, so unwrap to verify
// that understanding.
return Some(pts_so_far.unwrap());
}
// If we made it to the last step, maybe use the end_dist.
if i == self.steps.len() - 1 && self.end_dist < dist_remaining {
@ -192,7 +198,7 @@ impl Path {
}
}
return pts_so_far.unwrap();
return Some(pts_so_far.unwrap());
}
pub fn get_steps(&self) -> &VecDeque<PathStep> {

View File

@ -849,7 +849,7 @@ impl DrivingSimState {
}
let r = self.routers.get(&id)?;
let c = &self.cars[&id];
Some(r.trace_route(c.dist_along, map, dist_ahead))
r.trace_route(c.dist_along, map, dist_ahead)
}
pub fn get_path(&self, id: CarID) -> Option<&Path> {

View File

@ -204,7 +204,12 @@ impl Router {
None
}
pub fn trace_route(&self, start_dist: Distance, map: &Map, dist_ahead: Distance) -> Trace {
pub fn trace_route(
&self,
start_dist: Distance,
map: &Map,
dist_ahead: Distance,
) -> Option<Trace> {
self.path.trace(map, start_dist, dist_ahead)
}

View File

@ -666,7 +666,7 @@ impl WalkingSimState {
pub fn trace_route(&self, id: PedestrianID, map: &Map, dist_ahead: Distance) -> Option<Trace> {
let p = self.peds.get(&id)?;
Some(p.path.trace(map, p.dist_along, dist_ahead))
p.path.trace(map, p.dist_along, dist_ahead)
}
pub fn get_path(&self, id: PedestrianID) -> Option<&Path> {