make explicit rank enum for road types, instead of using arbitrary numbers. cleanup for #231

This commit is contained in:
Dustin Carlino 2020-08-05 11:40:42 -07:00
parent 8f6a6d40e6
commit 2f618815b1
6 changed files with 42 additions and 60 deletions

View File

@ -13,8 +13,8 @@ use abstutil::Timer;
use ezgui::{Color, Drawable, EventCtx, GeomBatch, GfxCtx, Prerender};
use geom::{Bounds, Circle, Distance, Polygon, Pt2D, Time};
use map_model::{
AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParkingLotID, RoadID, Traversable,
NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS,
osm, AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParkingLotID, RoadID,
Traversable, NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS,
};
use sim::{GetDrawAgents, UnzoomedAgent, VehicleType};
use std::borrow::Borrow;
@ -203,7 +203,7 @@ impl DrawMap {
} else if r.is_private() {
cs.private_road
} else {
osm_rank_to_color(cs, r.get_rank())
rank_to_color(cs, r.get_rank())
},
));
}
@ -217,7 +217,7 @@ impl DrawMap {
} else if i.is_private(map) {
cs.private_road
} else {
osm_rank_to_color(cs, i.get_rank(map))
rank_to_color(cs, i.get_rank(map))
}
} else {
cs.unzoomed_interesting_intersection
@ -522,12 +522,10 @@ impl UnzoomedAgents {
}
}
fn osm_rank_to_color(cs: &ColorScheme, rank: usize) -> Color {
if rank >= 16 {
cs.unzoomed_highway
} else if rank >= 6 {
cs.unzoomed_arterial
} else {
cs.unzoomed_residential
fn rank_to_color(cs: &ColorScheme, rank: osm::RoadRank) -> Color {
match rank {
osm::RoadRank::Highway => cs.unzoomed_highway,
osm::RoadRank::Arterial => cs.unzoomed_arterial,
osm::RoadRank::Local => cs.unzoomed_residential,
}
}

View File

@ -10,7 +10,7 @@ use ezgui::{
Widget,
};
use geom::{Distance, PolyLine, Polygon, Time};
use map_model::{BuildingID, BuildingType, IntersectionID, LaneID, Map, RoadID, TurnType};
use map_model::{osm, BuildingID, BuildingType, IntersectionID, LaneID, Map, RoadID, TurnType};
use maplit::hashset;
use sim::{DontDrawAgents, TripEndpoint, TripInfo, TripMode};
use std::collections::{BTreeSet, HashMap, HashSet};
@ -638,7 +638,6 @@ fn partition_sidewalk_loops(app: &App) -> Vec<Loop> {
// Merge adjacent residential blocks
loop {
// Find a pair of blocks that have at least one residential road in common.
// Rank comes from OSM highway type; < 6 means residential.
let mut any = false;
for mut idx1 in 0..groups.len() {
for mut idx2 in 0..groups.len() {
@ -653,7 +652,7 @@ fn partition_sidewalk_loops(app: &App) -> Vec<Loop> {
&& groups[idx1]
.roads
.intersection(&groups[idx2].roads)
.any(|r| map.get_r(*r).get_rank() < 6)
.any(|r| map.get_r(*r).get_rank() == osm::RoadRank::Local)
{
// Indexing gets messed up, so remove the larger one
if idx1 > idx2 {

View File

@ -1,5 +1,5 @@
use crate::raw::OriginalIntersection;
use crate::{DirectedRoadID, LaneID, Map, PathConstraints, Road, RoadID, TurnID};
use crate::{osm, DirectedRoadID, LaneID, Map, PathConstraints, Road, RoadID, TurnID};
use abstutil::{deserialize_usize, serialize_usize};
use geom::{Distance, Polygon};
use serde::{Deserialize, Serialize};
@ -106,7 +106,7 @@ impl Intersection {
.unwrap()
}
pub fn get_rank(&self, map: &Map) -> usize {
pub fn get_rank(&self, map: &Map) -> osm::RoadRank {
self.roads
.iter()
.map(|r| map.get_r(*r).get_rank())

View File

@ -324,55 +324,20 @@ impl Road {
"???".to_string()
}
// Used to determine which roads have stop signs when roads of different types intersect.
pub fn get_rank(&self) -> usize {
let hwy = if let Some(x) = self.osm_tags.get(osm::HIGHWAY) {
pub fn get_rank(&self) -> osm::RoadRank {
if let Some(x) = self.osm_tags.get(osm::HIGHWAY) {
if x == "construction" {
// What exactly is under construction?
if let Some(x) = self.osm_tags.get("construction") {
x
osm::RoadRank::from_highway(x)
} else {
return 0;
osm::RoadRank::Local
}
} else {
x
osm::RoadRank::from_highway(x)
}
} else {
return 0;
};
match hwy.as_ref() {
"motorway" => 20,
"motorway_link" => 19,
"trunk" => 17,
"trunk_link" => 16,
"primary" => 15,
"primary_link" => 14,
"secondary" => 13,
"secondary_link" => 12,
"tertiary" => 10,
"tertiary_link" => 9,
"residential" => 5,
"living_street" => 3,
"footway" => 1,
"unclassified" => 0,
"road" => 0,
"crossing" => 0,
"service" => 0,
// If you hit this error and the highway type doesn't represent a driveable road,
// you may want to instead filter out the OSM way entirely in
// convert_osm/src/extract.rs's is_road().
_ => panic!(
"Unknown OSM highway {}. Other tags: {:?}",
hwy, self.osm_tags
),
osm::RoadRank::Local
}
}

View File

@ -1,4 +1,4 @@
use crate::{IntersectionID, LaneID, Map, RoadID, TurnID, TurnPriority, TurnType};
use crate::{osm, IntersectionID, LaneID, Map, RoadID, TurnID, TurnPriority, TurnType};
use abstutil::{deserialize_btreemap, serialize_btreemap};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
@ -79,11 +79,11 @@ impl ControlStopSign {
}
// What's the rank of each road?
let mut rank: HashMap<RoadID, usize> = HashMap::new();
let mut rank: HashMap<RoadID, osm::RoadRank> = HashMap::new();
for r in ss.roads.keys() {
rank.insert(*r, map.get_r(*r).get_rank());
}
let mut ranks: Vec<usize> = rank.values().cloned().collect();
let mut ranks: Vec<osm::RoadRank> = rank.values().cloned().collect();
ranks.sort();
ranks.dedup();
// Highest rank is first

View File

@ -24,3 +24,23 @@ pub const ENDPT_BACK: &str = "abst:endpt_back";
// Any roads might have these.
pub const INFERRED_PARKING: &str = "abst:parking_inferred";
pub const INFERRED_SIDEWALKS: &str = "abst:sidewalks_inferred";
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
pub enum RoadRank {
Local,
Arterial,
Highway,
}
impl RoadRank {
pub fn from_highway(hwy: &str) -> RoadRank {
match hwy {
"motorway" | "motorway_link" => RoadRank::Highway,
"trunk" | "trunk_link" => RoadRank::Highway,
"primary" | "primary_link" => RoadRank::Arterial,
"secondary" | "secondary_link" => RoadRank::Arterial,
"tertiary" | "tertiary_link" => RoadRank::Arterial,
_ => RoadRank::Local,
}
}
}