Skip to content

Commit

Permalink
Actually, to keep all of the existing editing UIs from breaking, pres…
Browse files Browse the repository at this point in the history
…erve LaneIDs when just editing lane types. #597
  • Loading branch information
dabreegster committed Apr 9, 2021
1 parent 3beb153 commit 68661f0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions map_model/src/edits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,26 @@ fn modify_lanes(
lanes_ltr: Vec<(LaneType, Direction)>,
effects: &mut EditEffects,
) {
// TODO If none of the lanes have changed, just return early. Otherwise when we change speed
// limits, we needlessly churn lane IDs.
let road = &mut map.roads[r.0];

// TODO Widening roads is still experimental. If we're just modifying lane types, preserve
// LaneIDs.
if road.lanes_ltr.len() == lanes_ltr.len() {
for (idx, (lt, dir)) in lanes_ltr.into_iter().enumerate() {
let lane = map.lanes.get_mut(&road.lanes_ltr[idx].0).unwrap();
road.lanes_ltr[idx].2 = lt;
lane.lane_type = lt;

// Direction change?
if road.lanes_ltr[idx].1 != dir {
road.lanes_ltr[idx].1 = dir;
std::mem::swap(&mut lane.src_i, &mut lane.dst_i);
lane.lane_center_pts = lane.lane_center_pts.reversed();
lane.dir = dir;
}
}
return;
}

// We may be adding lanes, deleting lanes, or just modifying existing ones. The width of
// existing lanes may change. We could try to preserve existing LaneIDs and modify them, but
Expand All @@ -467,7 +485,6 @@ fn modify_lanes(
// road.center_pts doesn't need to change; we'll keep the true physical center of the road and
// build around it.

let road = &mut map.roads[r.0];
for (l, _, _) in road.lanes_ltr.drain(..) {
map.lanes.remove(&l).unwrap();
effects.deleted_lanes.insert(l);
Expand Down

0 comments on commit 68661f0

Please sign in to comment.