Skip to content

Commit

Permalink
Treat cyclepaths as lower priority at intersections with regular roads,
Browse files Browse the repository at this point in the history
to more realistically guess stop signs. #330, #450
  • Loading branch information
dabreegster committed Jan 14, 2021
1 parent d49c6c5 commit 7ffb2d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
10 changes: 5 additions & 5 deletions data/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
"compressed_size_bytes": 3387178
},
"data/input/cambridge/screenshots/trumpington.zip": {
"checksum": "a42f59cf1aab838872f7246baa17845c",
"uncompressed_size_bytes": 39274168,
"compressed_size_bytes": 39250810
"checksum": "e1e831d882b4a74b257a03553d5069ad",
"uncompressed_size_bytes": 39239222,
"compressed_size_bytes": 39215655
},
"data/input/krakow/osm/center.osm": {
"checksum": "e64103d37a7009d96f7d8a653db02deb",
Expand Down Expand Up @@ -636,9 +636,9 @@
"compressed_size_bytes": 8020444
},
"data/system/cambridge/maps/trumpington.bin": {
"checksum": "c6f88a7509c4afc0756e86d43088a2ed",
"checksum": "847f473cf8ee383735a23fc1b9494dac",
"uncompressed_size_bytes": 28161452,
"compressed_size_bytes": 9976432
"compressed_size_bytes": 9976483
},
"data/system/krakow/maps/center.bin": {
"checksum": "6b39b2b5a2066603cbe5e4dc087e7071",
Expand Down
28 changes: 17 additions & 11 deletions map_model/src/objects/stop_signs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,31 @@ impl ControlStopSign {
// Degenerate roads and deadends don't need any stop signs.
return ss;
}
if map.get_i(id).is_cycleway(map) {
// Two cyclepaths intersecting can just yield.
return ss;
}

// What's the rank of each road?
let mut rank: HashMap<RoadID, osm::RoadRank> = HashMap::new();
// Rank each road based on OSM highway type, and additionally treat cycleways as lower
// priority than local roads. (Sad but typical reality.)
let mut rank: HashMap<RoadID, (osm::RoadRank, usize)> = HashMap::new();
for r in ss.roads.keys() {
rank.insert(*r, map.get_r(*r).get_rank());
let r = map.get_r(*r);
// Lower number is lower priority
let priority = if r.is_cycleway() { 0 } else { 1 };
rank.insert(r.id, (r.get_rank(), priority));
}
let mut ranks: Vec<osm::RoadRank> = rank.values().cloned().collect();
let mut ranks = rank.values().cloned().collect::<Vec<_>>();
ranks.sort();
ranks.dedup();
// Highest rank is first
ranks.reverse();

// If all roads have the same rank and it's not just intersecting cycleways, all-way stop.
// Otherwise, everything stops except the highest-priority roads.
if !map.get_i(id).is_cycleway(map) {
for (r, cfg) in ss.roads.iter_mut() {
if ranks.len() == 1 || rank[r] != ranks[0] {
cfg.must_stop = true;
}
// If all roads have the same rank, all-way stop. Otherwise, everything stops except the
// highest-priority roads.
for (r, cfg) in ss.roads.iter_mut() {
if ranks.len() == 1 || rank[r] != ranks[0] {
cfg.must_stop = true;
}
}
ss
Expand Down
2 changes: 1 addition & 1 deletion map_model/src/osm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub const ENDPT_BACK: &str = "abst:endpt_back";
pub const INFERRED_PARKING: &str = "abst:parking_inferred";
pub const INFERRED_SIDEWALKS: &str = "abst:sidewalks_inferred";

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
pub enum RoadRank {
Local,
Arterial,
Expand Down

0 comments on commit 7ffb2d1

Please sign in to comment.