recalculate bus stop driving_pos when editing

This commit is contained in:
Dustin Carlino 2019-06-06 14:47:17 -07:00
parent d7e639b5f3
commit 88f6516f79
3 changed files with 22 additions and 7 deletions

View File

@ -394,7 +394,7 @@ fn can_change_lane_type(r: &Road, l: &Lane, lt: LaneType, map: &Map) -> bool {
} }
// Don't let players orphan a bus stop. // Don't let players orphan a bus stop.
if r.has_bus_stop(map) && (lt == LaneType::Parking || lt == LaneType::Biking) { if !r.all_bus_stops(map).is_empty() && (lt == LaneType::Parking || lt == LaneType::Biking) {
// Is this the last one? // Is this the last one?
let mut other_bus_lane = false; let mut other_bus_lane = false;
for id in r.all_lanes() { for id in r.all_lanes() {

View File

@ -598,6 +598,7 @@ impl Map {
let mut changed_lanes = BTreeSet::new(); let mut changed_lanes = BTreeSet::new();
let mut changed_intersections = BTreeSet::new(); let mut changed_intersections = BTreeSet::new();
let mut changed_roads = BTreeSet::new();
for (id, lt) in all_lane_edits { for (id, lt) in all_lane_edits {
changed_lanes.insert(id); changed_lanes.insert(id);
@ -614,6 +615,21 @@ impl Map {
changed_intersections.insert(l.src_i); changed_intersections.insert(l.src_i);
changed_intersections.insert(l.dst_i); changed_intersections.insert(l.dst_i);
changed_roads.insert(l.parent);
}
for id in changed_roads {
let stops = self.get_r(id).all_bus_stops(self);
for s in stops {
let sidewalk_pos = self.get_bs(s).sidewalk_pos;
// Must exist, because we aren't allowed to orphan a bus stop.
let driving_lane = self
.get_r(id)
.find_closest_lane(sidewalk_pos.lane(), vec![LaneType::Driving, LaneType::Bus])
.unwrap();
let driving_pos = sidewalk_pos.equiv_pos(driving_lane, self);
self.bus_stops.get_mut(&s).unwrap().driving_pos = driving_pos;
}
} }
// Recompute turns and intersection policy // Recompute turns and intersection policy

View File

@ -1,4 +1,4 @@
use crate::{raw_data, IntersectionID, LaneID, LaneType, Map, LANE_THICKNESS}; use crate::{raw_data, BusStopID, IntersectionID, LaneID, LaneType, Map, LANE_THICKNESS};
use abstutil::{Error, Warn}; use abstutil::{Error, Warn};
use geom::{Distance, PolyLine, Polygon, Speed}; use geom::{Distance, PolyLine, Polygon, Speed};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
@ -401,12 +401,11 @@ impl Road {
} }
} }
pub fn has_bus_stop(&self, map: &Map) -> bool { pub fn all_bus_stops(&self, map: &Map) -> Vec<BusStopID> {
let mut stops = Vec::new();
for id in self.all_lanes() { for id in self.all_lanes() {
if !map.get_l(id).bus_stops.is_empty() { stops.extend(map.get_l(id).bus_stops.iter().cloned());
return true; }
} stops
}
false
} }
} }