Skip to content

Commit

Permalink
Fix route snapper lines doubling back on themselves. #25
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Nov 16, 2022
1 parent 120395c commit e1126a0
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions route-snapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Route {
waypoints: Vec<IntersectionID>,
// The full sequence of intersections. Waypoints are a subset
full_path: Vec<IntersectionID>,
// All roads, in order
// All roads, in order. They lack direction.
roads: Vec<RoadID>,
}

Expand Down Expand Up @@ -153,8 +153,35 @@ impl JsRouteSnapper {
return None;
}
let mut pts = Vec::new();
let mut last_i = None;
for r in &self.route.roads {
pts.extend(self.map.road(r).center_pts.clone().into_points());
let road = self.map.road(r);
let mut add_pts = road.center_pts.clone().into_points();
// The road is oriented one way, so maybe reverse these points
match last_i {
Some(i) => {
if road.i1 == i {
last_i = Some(road.i2);
} else {
add_pts.reverse();
last_i = Some(road.i1);
}
}
None => {
if let Some(next) = self.route.roads.get(1) {
let next_road = self.map.road(next);
if road.i1 == next_road.i1 || road.i1 == next_road.i2 {
add_pts.reverse();
last_i = Some(road.i1);
} else {
last_i = Some(road.i2);
}
} else {
// Route with only route doesn't matter
}
}
}
pts.extend(add_pts);
}
pts.dedup();
let pl = PolyLine::unchecked_new(pts);
Expand Down

0 comments on commit e1126a0

Please sign in to comment.