From 442523ae6c2064d9818c95d91e3ec5ab30868aa3 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 5 Sep 2021 18:05:49 -0700 Subject: [PATCH] Simplify some lane lookups that just needed to find the parent --- fifteen_min/src/isochrone.rs | 2 +- game/src/common/select.rs | 2 +- game/src/debug/mod.rs | 14 ++++++-------- game/src/debug/path_counter.rs | 4 ++-- game/src/debug/routes.rs | 2 +- game/src/edit/multiple_roads.rs | 2 +- game/src/edit/roads.rs | 10 ++++++---- game/src/info/lane.rs | 13 +++++-------- game/src/layer/map.rs | 6 +++--- game/src/layer/parking.rs | 8 ++++---- game/src/layer/traffic.rs | 2 +- game/src/sandbox/dashboards/commuter.rs | 6 ++---- game/src/ungap/explore.rs | 2 +- game/src/ungap/route.rs | 4 ++-- importer/src/bin/generate_houses.rs | 5 ++++- map_gui/src/render/lane.rs | 8 ++++---- map_model/src/edits/mod.rs | 4 +--- map_model/src/make/turns.rs | 10 +++++----- map_model/src/make/walking_turns.rs | 6 ++---- map_model/src/map.rs | 5 ++--- map_model/src/objects/lane.rs | 5 ++--- map_model/src/objects/road.rs | 1 - map_model/src/objects/stop_signs.rs | 2 +- map_model/src/objects/turn.rs | 8 ++++---- map_model/src/pathfind/mod.rs | 5 +++-- map_model/src/pathfind/uber_turns.rs | 6 +++--- map_model/src/pathfind/v1.rs | 8 ++++---- map_model/src/traversable.rs | 2 +- parking_mapper/src/mapper.rs | 2 +- sim/src/analytics.rs | 11 +++-------- sim/src/lib.rs | 2 +- sim/src/make/scenario.rs | 6 +++--- sim/src/mechanics/driving.rs | 2 +- 33 files changed, 81 insertions(+), 94 deletions(-) diff --git a/fifteen_min/src/isochrone.rs b/fifteen_min/src/isochrone.rs index d28e9ce132..2c7164cedc 100644 --- a/fifteen_min/src/isochrone.rs +++ b/fifteen_min/src/isochrone.rs @@ -87,7 +87,7 @@ impl Isochrone { } _ => {} } - all_roads.insert(app.map.get_l(bldg.sidewalk_pos.lane()).parent); + all_roads.insert(bldg.sidewalk_pos.lane().road); } let mut onstreet_parking_spots = 0; diff --git a/game/src/common/select.rs b/game/src/common/select.rs index 9c4247316d..ee61a9b178 100644 --- a/game/src/common/select.rs +++ b/game/src/common/select.rs @@ -109,7 +109,7 @@ impl RoadSelector { app.primary.current_selection = match app.mouseover_unzoomed_roads_and_intersections(ctx) { Some(ID::Road(r)) => Some(r), - Some(ID::Lane(l)) => Some(app.primary.map.get_l(l).parent), + Some(ID::Lane(l)) => Some(l.road), _ => None, } .and_then(|r| { diff --git a/game/src/debug/mod.rs b/game/src/debug/mod.rs index b4b8e2f0bf..57e1014416 100644 --- a/game/src/debug/mod.rs +++ b/game/src/debug/mod.rs @@ -771,11 +771,9 @@ impl ContextualActions for Actions { mode.reset_info(ctx); })) } - (ID::Lane(l), "export roads") => Transition::Push(select_roads::BulkSelect::new_state( - ctx, - app, - app.primary.map.get_l(l).parent, - )), + (ID::Lane(l), "export roads") => { + Transition::Push(select_roads::BulkSelect::new_state(ctx, app, l.road)) + } (ID::Lane(l), "show equiv_pos") => { Transition::ModifyState(Box::new(move |state, ctx, app| { if let Some(pt) = ctx.canvas.get_cursor_in_map_space() { @@ -1022,12 +1020,12 @@ fn draw_banned_turns(ctx: &mut EventCtx, app: &App) -> Drawable { // Don't call out one-ways, so use incoming/outgoing roads, and just for cars. for l1 in i.get_incoming_lanes(map, PathConstraints::Car) { for l2 in i.get_outgoing_lanes(map, PathConstraints::Car) { - pairs.insert((map.get_l(l1).parent, map.get_l(l2).parent)); + pairs.insert((l1.road, l2.road)); } } for t in &i.turns { - let r1 = map.get_l(t.id.src).parent; - let r2 = map.get_l(t.id.dst).parent; + let r1 = t.id.src.road; + let r2 = t.id.dst.road; pairs.remove(&(r1, r2)); } diff --git a/game/src/debug/path_counter.rs b/game/src/debug/path_counter.rs index 0c1220e3d5..57302d9353 100644 --- a/game/src/debug/path_counter.rs +++ b/game/src/debug/path_counter.rs @@ -39,7 +39,7 @@ impl PathCounter { // Count what lanes they'll cross for step in path.get_steps() { if let Traversable::Lane(l) = step.as_traversable() { - cnt.inc(map.get_l(l).parent); + cnt.inc(l.road); } } } @@ -89,7 +89,7 @@ impl State for PathCounter { app.primary.current_selection = app.mouseover_unzoomed_roads_and_intersections(ctx); self.tooltip = None; if let Some(r) = match app.primary.current_selection { - Some(ID::Lane(l)) => Some(app.primary.map.get_l(l).parent), + Some(ID::Lane(l)) => Some(l.road), Some(ID::Road(r)) => Some(r), _ => None, } { diff --git a/game/src/debug/routes.rs b/game/src/debug/routes.rs index 64d5f1d037..263fdecc8f 100644 --- a/game/src/debug/routes.rs +++ b/game/src/debug/routes.rs @@ -489,7 +489,7 @@ fn calculate_demand(app: &App, requests: &[PathRequest], timer: &mut Timer) -> C timer.next(); for step in path.get_steps() { if let Traversable::Lane(l) = step.as_traversable() { - counter.inc(app.primary.map.get_l(l).parent); + counter.inc(l.road); } } } diff --git a/game/src/edit/multiple_roads.rs b/game/src/edit/multiple_roads.rs index 258605b62e..03befc1fce 100644 --- a/game/src/edit/multiple_roads.rs +++ b/game/src/edit/multiple_roads.rs @@ -211,7 +211,7 @@ impl State for SelectSegments { ctx.show_cursor(); if let Some(r) = match app.mouseover_unzoomed_roads_and_intersections(ctx) { Some(ID::Road(r)) => Some(r), - Some(ID::Lane(l)) => Some(app.primary.map.get_l(l).parent), + Some(ID::Lane(l)) => Some(l.road), _ => None, } { if self.candidates.contains(&r) { diff --git a/game/src/edit/roads.rs b/game/src/edit/roads.rs index 2ec7e4cd4f..56d334ca8d 100644 --- a/game/src/edit/roads.rs +++ b/game/src/edit/roads.rs @@ -42,7 +42,7 @@ pub struct RoadEditor { impl RoadEditor { /// Always starts focused on a certain lane. pub fn new_state(ctx: &mut EventCtx, app: &mut App, l: LaneID) -> Box> { - RoadEditor::create(ctx, app, app.primary.map.get_l(l).parent, Some(l)) + RoadEditor::create(ctx, app, l.road, Some(l)) } pub fn new_state_without_lane( @@ -442,7 +442,7 @@ impl State for RoadEditor { } if let Some(l) = self.hovering_on_lane { if ctx.normal_left_click() { - if app.primary.map.get_l(l).parent == self.r { + if l.road == self.r { self.selected_lane = Some(l); panels_need_recalc = true; } else { @@ -966,8 +966,10 @@ fn lane_type_to_icon(lt: LaneType) -> Option<&'static str> { fn width_choices(app: &App, l: LaneID) -> Vec> { let lane = app.primary.map.get_l(l); - let mut choices = - LaneSpec::typical_lane_widths(lane.lane_type, &app.primary.map.get_r(lane.parent).osm_tags); + let mut choices = LaneSpec::typical_lane_widths( + lane.lane_type, + &app.primary.map.get_r(lane.id.road).osm_tags, + ); if !choices.iter().any(|(x, _)| *x == lane.width) { choices.push((lane.width, "custom")); } diff --git a/game/src/info/lane.rs b/game/src/info/lane.rs index cac7091d53..b6f0a1f36e 100644 --- a/game/src/info/lane.rs +++ b/game/src/info/lane.rs @@ -19,7 +19,7 @@ fn info_body(ctx: &EventCtx, app: &App, id: LaneID) -> Widget { let map = &app.primary.map; let l = map.get_l(id); - let r = map.get_r(l.parent); + let r = map.get_r(id.road); let mut kv = Vec::new(); @@ -114,7 +114,7 @@ fn debug_body(ctx: &EventCtx, app: &App, id: LaneID) -> Widget { let map = &app.primary.map; let l = map.get_l(id); - let r = map.get_r(l.parent); + let r = map.get_r(id.road); let mut kv = vec![("Parent".to_string(), r.id.to_string())]; @@ -215,21 +215,18 @@ pub fn traffic( fn traffic_body(ctx: &mut EventCtx, app: &App, id: LaneID, opts: &DataOptions) -> Widget { let mut rows = vec![]; - let map = &app.primary.map; - let l = map.get_l(id); - let r = map.get_r(l.parent); + let r = id.road; // Since this applies to the entire road, ignore lane type. let mut txt = Text::from("Traffic over entire road, not just this lane"); txt.add_line(format!( "Since midnight: {} commuters and vehicles crossed", - prettyprint_usize(app.primary.sim.get_analytics().road_thruput.total_for(r.id)) + prettyprint_usize(app.primary.sim.get_analytics().road_thruput.total_for(r)) )); rows.push(txt.into_widget(ctx)); rows.push(opts.to_controls(ctx, app)); - let r = map.get_l(id).parent; let time = if opts.show_end_of_day { app.primary.sim.get_end_of_day() } else { @@ -258,7 +255,7 @@ fn header(ctx: &EventCtx, app: &App, details: &mut Details, id: LaneID, tab: Tab let map = &app.primary.map; let l = map.get_l(id); - let r = map.get_r(l.parent); + let r = map.get_r(id.road); let label = if l.is_shoulder() { "Shoulder" diff --git a/game/src/layer/map.rs b/game/src/layer/map.rs index 73eaed2a71..9fa6553b80 100644 --- a/game/src/layer/map.rs +++ b/game/src/layer/map.rs @@ -79,7 +79,7 @@ impl BikeActivity { // Make sure all bikes lanes show up no matter what for l in app.primary.map.all_lanes() { if l.is_biking() { - on_bike_lanes.add(l.parent, 0); + on_bike_lanes.add(l.id.road, 0); intersections_on.add(l.src_i, 0); intersections_on.add(l.src_i, 0); num_lanes += 1; @@ -300,8 +300,8 @@ impl Static { pub fn no_sidewalks(ctx: &mut EventCtx, app: &App) -> Static { let mut colorer = ColorDiscrete::new(app, vec![("no sidewalks", Color::RED)]); for l in app.primary.map.all_lanes() { - if l.is_shoulder() && !app.primary.map.get_r(l.parent).is_cycleway() { - colorer.add_r(l.parent, "no sidewalks"); + if l.is_shoulder() && !app.primary.map.get_parent(l.id).is_cycleway() { + colorer.add_r(l.id.road, "no sidewalks"); } } Static::new( diff --git a/game/src/layer/parking.rs b/game/src/layer/parking.rs index b5330bf782..2d60cf777a 100644 --- a/game/src/layer/parking.rs +++ b/game/src/layer/parking.rs @@ -4,7 +4,7 @@ use abstutil::{prettyprint_usize, Counter}; use geom::{Circle, Distance, Duration, Pt2D, Time}; use map_gui::render::unzoomed_agent_radius; use map_gui::tools::{ColorLegend, ColorNetwork}; -use map_model::{BuildingID, Map, OffstreetParking, ParkingLotID, PathRequest, RoadID}; +use map_model::{BuildingID, OffstreetParking, ParkingLotID, PathRequest, RoadID}; use sim::{ParkingSpot, VehicleType}; use widgetry::{Drawable, EventCtx, GeomBatch, GfxCtx, Line, Outcome, Panel, Text, Toggle, Widget}; @@ -186,7 +186,7 @@ impl Occupancy { } } - let loc = Loc::new(spot, &app.primary.map); + let loc = Loc::new(spot); keys.insert(loc); spots.inc(loc); } @@ -290,9 +290,9 @@ enum Loc { } impl Loc { - fn new(spot: ParkingSpot, map: &Map) -> Loc { + fn new(spot: ParkingSpot) -> Loc { match spot { - ParkingSpot::Onstreet(l, _) => Loc::Road(map.get_l(l).parent), + ParkingSpot::Onstreet(l, _) => Loc::Road(l.road), ParkingSpot::Offstreet(b, _) => Loc::Bldg(b), ParkingSpot::Lot(pl, _) => Loc::Lot(pl), } diff --git a/game/src/layer/traffic.rs b/game/src/layer/traffic.rs index 36d2caa826..bed42d9551 100644 --- a/game/src/layer/traffic.rs +++ b/game/src/layer/traffic.rs @@ -56,7 +56,7 @@ impl Backpressure { for step in path.get_steps() { match step.as_traversable() { Traversable::Lane(l) => { - cnt_per_r.inc(app.primary.map.get_l(l).parent); + cnt_per_r.inc(l.road); } Traversable::Turn(t) => { cnt_per_i.inc(t.parent); diff --git a/game/src/sandbox/dashboards/commuter.rs b/game/src/sandbox/dashboards/commuter.rs index 7d77d79bc8..e56f7382c0 100644 --- a/game/src/sandbox/dashboards/commuter.rs +++ b/game/src/sandbox/dashboards/commuter.rs @@ -636,7 +636,7 @@ fn partition_sidewalk_loops(app: &App) -> Vec { groups.push(Loop { bldgs, proper: true, - roads: sidewalks.into_iter().map(|l| map.get_l(l).parent).collect(), + roads: sidewalks.into_iter().map(|l| l.road).collect(), }); } else { remainder.extend(bldgs); @@ -684,9 +684,7 @@ fn partition_sidewalk_loops(app: &App) -> Vec { per_sidewalk.insert(map.get_b(b).sidewalk(), b); } for (_, bldgs) in per_sidewalk.consume() { - let r = map - .get_l(map.get_b(*bldgs.iter().next().unwrap()).sidewalk()) - .parent; + let r = map.get_b(*bldgs.iter().next().unwrap()).sidewalk().road; groups.push(Loop { bldgs: bldgs.into_iter().collect(), proper: false, diff --git a/game/src/ungap/explore.rs b/game/src/ungap/explore.rs index f035cc1b25..d5383d445f 100644 --- a/game/src/ungap/explore.rs +++ b/game/src/ungap/explore.rs @@ -80,7 +80,7 @@ impl State for ExploreMap { app.primary.current_selection = match app.mouseover_unzoomed_roads_and_intersections(ctx) { Some(ID::Road(r)) => Some(r), - Some(ID::Lane(l)) => Some(app.primary.map.get_l(l).parent), + Some(ID::Lane(l)) => Some(l.road), _ => None, } .and_then(|r| { diff --git a/game/src/ungap/route.rs b/game/src/ungap/route.rs index 3601de55cc..dcca208cc1 100644 --- a/game/src/ungap/route.rs +++ b/game/src/ungap/route.rs @@ -169,8 +169,8 @@ impl RouteResults { num_traffic_signals += 1; } if map.is_unprotected_turn( - map.get_l(t.src).parent, - map.get_l(t.dst).parent, + t.src.road, + t.dst.road, map.get_t(*t).turn_type, ) { num_unprotected_turns += 1; diff --git a/importer/src/bin/generate_houses.rs b/importer/src/bin/generate_houses.rs index 86a1cac284..b1eef83328 100644 --- a/importer/src/bin/generate_houses.rs +++ b/importer/src/bin/generate_houses.rs @@ -74,7 +74,10 @@ fn generate_buildings_on_empty_residential_roads( for l in map.all_lanes() { if l.is_sidewalk() && !lanes_with_buildings.contains(&l.id) - && map.get_r(l.parent).osm_tags.is(osm::HIGHWAY, "residential") + && map + .get_parent(l.id) + .osm_tags + .is(osm::HIGHWAY, "residential") { empty_sidewalks.push(l.id); } diff --git a/map_gui/src/render/lane.rs b/map_gui/src/render/lane.rs index 9ba848d142..c6b26bb254 100644 --- a/map_gui/src/render/lane.rs +++ b/map_gui/src/render/lane.rs @@ -23,7 +23,7 @@ impl DrawLane { DrawLane { id: lane.id, polygon: lane.lane_center_pts.make_polygons(lane.width), - zorder: map.get_r(lane.parent).zorder, + zorder: map.get_r(lane.id.road).zorder, draw_default: RefCell::new(None), } } @@ -31,7 +31,7 @@ impl DrawLane { pub fn render>(&self, prerender: &P, app: &dyn AppLike) -> GeomBatch { let map = app.map(); let lane = map.get_l(self.id); - let road = map.get_r(lane.parent); + let road = map.get_r(lane.id.road); let rank = road.get_rank(); let mut batch = GeomBatch::new(); @@ -316,7 +316,7 @@ fn calculate_turn_markings(map: &Map, lane: &Lane) -> Vec { if i.outgoing_lanes.iter().all(|l| { let l = map.get_l(*l); l.lane_type != lane.lane_type - || l.parent == lane.parent + || l.id.road == lane.id.road || map .maybe_get_t(TurnID { parent: i.id, @@ -333,7 +333,7 @@ fn calculate_turn_markings(map: &Map, lane: &Lane) -> Vec { let mut angles_per_road: HashMap> = HashMap::new(); for turn in map.get_turns_from_lane(lane.id) { angles_per_road - .entry(map.get_l(turn.id.dst).parent) + .entry(turn.id.dst.road) .or_insert_with(Vec::new) .push(turn.angle()); } diff --git a/map_model/src/edits/mod.rs b/map_model/src/edits/mod.rs index 48e8171045..d51bf4d5d6 100644 --- a/map_model/src/edits/mod.rs +++ b/map_model/src/edits/mod.rs @@ -706,9 +706,7 @@ fn fix_building_driveways(map: &mut Map, input: Vec, effects: &mut E b.sidewalk_pos = sidewalk_pos; b.driveway_geom = driveway_geom.to_polyline(); // We may need to redraw the road that now has this building snapped to it - effects - .changed_roads - .insert(map.get_l(sidewalk_pos.lane()).parent); + effects.changed_roads.insert(sidewalk_pos.lane().road); } None => { // TODO Not sure what to do here yet. diff --git a/map_model/src/make/turns.rs b/map_model/src/make/turns.rs index 7add829f28..329b54b9a5 100644 --- a/map_model/src/make/turns.rs +++ b/map_model/src/make/turns.rs @@ -41,7 +41,7 @@ pub fn make_all_turns(map: &Map, i: &Intersection) -> Vec { // U-turns at divided highways are sometimes legal (and a common movement -- // https://www.openstreetmap.org/way/361443212), so let OSM turn:lanes override. if src_lane - .get_lane_level_turn_restrictions(map.get_r(src_lane.parent), false) + .get_lane_level_turn_restrictions(map.get_r(src_lane.id.road), false) .map(|set| !set.contains(&TurnType::UTurn)) .unwrap_or(true) { @@ -153,7 +153,7 @@ fn make_vehicle_turns(i: &Intersection, map: &Map) -> Vec { continue; } // Only allow U-turns at deadends - if src.parent == dst.parent && !is_deadend { + if src.id.road == dst.id.road && !is_deadend { continue; } // Can't go between light rail and normal roads @@ -192,14 +192,14 @@ fn make_vehicle_turns(i: &Intersection, map: &Map) -> Vec { } } else if let Some(expected_type) = expected_turn_types .as_ref() - .and_then(|e| e.get(&(src.parent, dst.parent))) + .and_then(|e| e.get(&(src.id.road, dst.id.road))) { // At some 4-way intersections, roads meet at strange angles, throwing off // turn_type_from_angles. Correct it based on relative ordering. if turn_type != *expected_type { warn!( "Turn from {} to {} looks like {:?} by angle, but is {:?} by ordering", - src.parent, dst.parent, turn_type, expected_type + src.id.road, dst.id.road, turn_type, expected_type ); turn_type = *expected_type; } @@ -290,7 +290,7 @@ fn remove_merging_turns(map: &Map, input: Vec, turn_type: TurnType) -> Vec if t.turn_type == turn_type { pairs - .entry((map.get_l(t.id.src).parent, map.get_l(t.id.dst).parent)) + .entry((t.id.src.road, t.id.dst.road)) .or_insert_with(Vec::new) .push(t); } else { diff --git a/map_model/src/make/walking_turns.rs b/map_model/src/make/walking_turns.rs index 903289afae..123bd84420 100644 --- a/map_model/src/make/walking_turns.rs +++ b/map_model/src/make/walking_turns.rs @@ -177,9 +177,7 @@ pub fn filter_turns(mut input: Vec, map: &Map, i: &Intersection) -> Vec Vec { } let l2 = l.unwrap(); - if adj && l1.parent != l2.parent { + if adj && l1.id.road != l2.id.road { // Because of the order we go, have to swap l1 and l2 here. l1 is the outgoing, l2 the // incoming. let geom = make_shared_sidewalk_corner(driving_side, i, l2, l1); diff --git a/map_model/src/map.rs b/map_model/src/map.rs index 80be768984..07f75ddc78 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -431,8 +431,7 @@ impl Map { } pub fn get_parent(&self, id: LaneID) -> &Road { - let l = self.get_l(id); - self.get_r(l.parent) + self.get_r(id.road) } pub fn get_gps_bounds(&self) -> &GPSBounds { @@ -773,7 +772,7 @@ impl Map { pub(crate) fn recalculate_road_to_buildings(&mut self) { let mut mapping = MultiMap::new(); for b in self.all_buildings() { - mapping.insert(self.get_l(b.sidewalk_pos.lane()).parent, b.id); + mapping.insert(b.sidewalk_pos.lane().road, b.id); } self.road_to_buildings = mapping; } diff --git a/map_model/src/objects/lane.rs b/map_model/src/objects/lane.rs index c68f3757f0..3971bd3fcf 100644 --- a/map_model/src/objects/lane.rs +++ b/map_model/src/objects/lane.rs @@ -239,7 +239,6 @@ impl LaneType { #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Lane { pub id: LaneID, - pub parent: RoadID, pub lane_type: LaneType, pub lane_center_pts: PolyLine, pub width: Distance, @@ -362,7 +361,7 @@ impl Lane { pub fn get_directed_parent(&self) -> DirectedRoadID { DirectedRoadID { - id: self.parent, + id: self.id.road, dir: self.dir, } } @@ -478,7 +477,7 @@ impl Lane { //println!("{}, fwd={}, pointing to {}", current, fwd, i); let mut roads = map.get_i(i).get_roads_sorted_by_incoming_angle(map); roads.retain(|r| !map.get_r(*r).is_footway()); - let idx = roads.iter().position(|r| *r == l.parent).unwrap(); + let idx = roads.iter().position(|r| *r == l.id.road).unwrap(); // Get the next road counter-clockwise let next_road = map.get_r(*wraparound_get(&roads, (idx as isize) + 1)); // Depending on if this road points to or from the intersection, get the left- or diff --git a/map_model/src/objects/road.rs b/map_model/src/objects/road.rs index e9ee6d30e7..a09a04c95e 100644 --- a/map_model/src/objects/road.rs +++ b/map_model/src/objects/road.rs @@ -545,7 +545,6 @@ impl Road { dst_i, lane_type: lane.lt, dir: lane.dir, - parent: self.id, bus_stops: BTreeSet::new(), driving_blackhole: false, biking_blackhole: false, diff --git a/map_model/src/objects/stop_signs.rs b/map_model/src/objects/stop_signs.rs index 82b8dada4b..97bbcc8aff 100644 --- a/map_model/src/objects/stop_signs.rs +++ b/map_model/src/objects/stop_signs.rs @@ -162,7 +162,7 @@ impl ControlStopSign { // TODO This actually feels like a policy bit that should be flippable. TurnType::Crosswalk => TurnPriority::Protected, _ => { - if self.roads[&map.get_l(turn.src).parent].must_stop { + if self.roads[&turn.src.road].must_stop { TurnPriority::Yield } else { TurnPriority::Protected diff --git a/map_model/src/objects/turn.rs b/map_model/src/objects/turn.rs index 68716d63cd..609aae9d67 100644 --- a/map_model/src/objects/turn.rs +++ b/map_model/src/objects/turn.rs @@ -115,7 +115,7 @@ impl Turn { // lane? Filters by the lane type and ignores lanes that don't go to the target road. let from_idx = { let mut cnt = 0; - let r = map.get_r(from.parent); + let r = map.get_r(from.id.road); for (l, lt) in r.children(from.dir).iter().rev() { if from.lane_type != *lt { continue; @@ -123,7 +123,7 @@ impl Turn { if map .get_turns_from_lane(*l) .into_iter() - .any(|t| map.get_l(t.id.dst).parent == to.parent) + .any(|t| t.id.dst.road == to.id.road) { cnt += 1; if from.id == *l { @@ -138,7 +138,7 @@ impl Turn { // lane? Filters by the lane type. let to_idx = { let mut cnt = 0; - let r = map.get_r(to.parent); + let r = map.get_r(to.id.road); for (l, lt) in r.children(to.dir).iter().rev() { if to.lane_type != *lt { continue; @@ -220,7 +220,7 @@ impl Turn { } let src = map.get_parent(self.id.src); - let dst = map.get_l(self.id.dst).parent; + let dst = self.id.dst.road; for (restriction, to) in &src.turn_restrictions { // The restriction only applies to one direction of the road. diff --git a/map_model/src/pathfind/mod.rs b/map_model/src/pathfind/mod.rs index e2b33fd38b..2fccf580fd 100644 --- a/map_model/src/pathfind/mod.rs +++ b/map_model/src/pathfind/mod.rs @@ -70,7 +70,7 @@ impl PathConstraints { true } else if lane.is_driving() || (lane.is_bus() && map.config.bikes_can_use_bus_lanes) { - let road = map.get_r(lane.parent); + let road = map.get_r(lane.id.road); !road.osm_tags.is("bicycle", "no") && !road .osm_tags @@ -102,7 +102,8 @@ impl PathConstraints { // practice this isn't an issue; a bus lane often leads to another one, but the next bus // lane won't also be an exclusive turn lane. if lane.is_bus() { - if let Some(types) = lane.get_lane_level_turn_restrictions(map.get_r(lane.parent), true) + if let Some(types) = + lane.get_lane_level_turn_restrictions(map.get_r(lane.id.road), true) { if types.contains(&TurnType::Right) || types.contains(&TurnType::Left) { return true; diff --git a/map_model/src/pathfind/uber_turns.rs b/map_model/src/pathfind/uber_turns.rs index 24a5405091..68a0db53f2 100644 --- a/map_model/src/pathfind/uber_turns.rs +++ b/map_model/src/pathfind/uber_turns.rs @@ -125,9 +125,9 @@ impl IntersectionCluster { uber_turns.retain(|ut| { let mut ok = true; for pair in ut.path.windows(2) { - let r1 = map.get_l(pair[0].src).parent; - let r2 = map.get_l(pair[0].dst).parent; - let r3 = map.get_l(pair[1].dst).parent; + let r1 = pair[0].src.road; + let r2 = pair[0].dst.road; + let r3 = pair[1].dst.road; if all_restrictions.contains(&(r1, r2, r3)) { ok = false; break; diff --git a/map_model/src/pathfind/v1.rs b/map_model/src/pathfind/v1.rs index 741b8e45de..8220eed6df 100644 --- a/map_model/src/pathfind/v1.rs +++ b/map_model/src/pathfind/v1.rs @@ -616,10 +616,10 @@ impl PathRequest { ) -> PathRequest { let alt_start = (|| { let start_lane = map.get_l(start.lane()); - let road = map.get_r(start_lane.parent); + let road = map.get_r(start_lane.id.road); // If start and end road match, don't exit offside // TODO Sometimes this is valid! Just not if we're trying to go behind ourselves - if road.id == map.get_l(end.lane()).parent { + if road.id == end.lane().road { return None; } let offside_dir = start_lane.dir.opposite(); @@ -692,8 +692,8 @@ fn validate_restrictions(map: &Map, steps: &[PathStep]) { (triple[0], triple[2], triple[4]) { let from = map.get_parent(l1); - let via = map.get_l(l2).parent; - let to = map.get_l(l3).parent; + let via = l2.road; + let to = l3.road; for (dont_via, dont_to) in &from.complicated_turn_restrictions { if via == *dont_via && to == *dont_to { diff --git a/map_model/src/traversable.rs b/map_model/src/traversable.rs index ff4dae4213..0d06ebf31a 100644 --- a/map_model/src/traversable.rs +++ b/map_model/src/traversable.rs @@ -82,7 +82,7 @@ impl Position { ) -> Position { let our_lane = map.get_l(self.lane); let other_lane = map.get_l(other_lane); - assert_eq!(our_lane.parent, other_lane.parent); + assert_eq!(our_lane.id.road, other_lane.id.road); let pl = &other_lane.lane_center_pts; let pt = self.pt(map); diff --git a/parking_mapper/src/mapper.rs b/parking_mapper/src/mapper.rs index a1b6642bed..ac64142d70 100644 --- a/parking_mapper/src/mapper.rs +++ b/parking_mapper/src/mapper.rs @@ -194,7 +194,7 @@ impl State for ParkingMapper { if ctx.redo_mouseover() { let mut maybe_r = match app.mouseover_unzoomed_roads_and_intersections(ctx) { Some(ID::Road(r)) => Some(r), - Some(ID::Lane(l)) => Some(map.get_l(l).parent), + Some(ID::Lane(l)) => Some(l.road), _ => None, }; if let Some(r) = maybe_r { diff --git a/sim/src/analytics.rs b/sim/src/analytics.rs index 713b82db29..3f713eed17 100644 --- a/sim/src/analytics.rs +++ b/sim/src/analytics.rs @@ -107,15 +107,10 @@ impl Analytics { if let Event::AgentEntersTraversable(a, _, to, passengers) = ev { match to { Traversable::Lane(l) => { - self.road_thruput - .record(time, map.get_l(l).parent, a.to_type(), 1); + self.road_thruput.record(time, l.road, a.to_type(), 1); if let Some(n) = passengers { - self.road_thruput.record( - time, - map.get_l(l).parent, - AgentType::TransitRider, - n, - ); + self.road_thruput + .record(time, l.road, AgentType::TransitRider, n); } } Traversable::Turn(t) => { diff --git a/sim/src/lib.rs b/sim/src/lib.rs index b3efa934bd..d512ed5959 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -378,7 +378,7 @@ impl DrivingGoal { PathConstraints::Car => { let driving_lane = map.find_driving_lane_near_building(*b); let sidewalk_pos = map.get_b(*b).sidewalk_pos; - if map.get_l(driving_lane).parent == map.get_l(sidewalk_pos.lane()).parent { + if driving_lane.road == sidewalk_pos.lane().road { Some(sidewalk_pos.equiv_pos(driving_lane, map)) } else { Some(Position::start(driving_lane)) diff --git a/sim/src/make/scenario.rs b/sim/src/make/scenario.rs index f4394ece92..8cfe6e8a9a 100644 --- a/sim/src/make/scenario.rs +++ b/sim/src/make/scenario.rs @@ -311,15 +311,15 @@ fn seed_parked_cars( BTreeMap::new(); for spot in sim.get_all_parking_spots().1 { let (r, restriction) = match spot { - ParkingSpot::Onstreet(l, _) => (map.get_l(l).parent, None), + ParkingSpot::Onstreet(l, _) => (l.road, None), ParkingSpot::Offstreet(b, _) => ( - map.get_l(map.get_b(b).sidewalk()).parent, + map.get_b(b).sidewalk().road, match map.get_b(b).parking { OffstreetParking::PublicGarage(_, _) => None, OffstreetParking::Private(_, _) => Some(b), }, ), - ParkingSpot::Lot(pl, _) => (map.get_l(map.get_pl(pl).driving_pos.lane()).parent, None), + ParkingSpot::Lot(pl, _) => (map.get_pl(pl).driving_pos.lane().road, None), }; open_spots_per_road .entry(r) diff --git a/sim/src/mechanics/driving.rs b/sim/src/mechanics/driving.rs index 3bd8731f48..827191fffd 100644 --- a/sim/src/mechanics/driving.rs +++ b/sim/src/mechanics/driving.rs @@ -1081,7 +1081,7 @@ impl DrivingSimState { fn pick_overtaking_lane(&self, car: &Car, map: &Map) -> Option { // Don't overtake in the middle of a turn! let current_lane = map.get_l(car.router.head().maybe_lane()?); - let road = map.get_r(current_lane.parent); + let road = map.get_parent(current_lane.id); let idx = road.offset(current_lane.id); let mut candidates = Vec::new();