1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::collections::{BTreeSet, VecDeque};
use geom::Distance;
use crate::osm::NodeID;
use crate::raw::{OriginalRoad, RawMap};
const SHORT_ROAD_THRESHOLD: Distance = Distance::const_meters(0.0);
pub fn merge_short_roads(map: &mut RawMap) -> BTreeSet<NodeID> {
let mut merged = BTreeSet::new();
let mut queue: VecDeque<OriginalRoad> = VecDeque::new();
for r in map.roads.keys() {
queue.push_back(*r);
}
while !queue.is_empty() {
let id = queue.pop_front().unwrap();
if !map.roads.contains_key(&id) {
continue;
}
if map.roads[&id].osm_tags.is("junction", "intersection")
|| map
.trimmed_road_geometry(id)
.map(|pl| pl.length() < SHORT_ROAD_THRESHOLD)
.unwrap_or(false)
{
match map.merge_short_road(id) {
Ok((i, _, _, new_roads)) => {
merged.insert(i);
queue.extend(new_roads);
}
Err(err) => {
warn!("Not merging short road / junction=intersection: {}", err);
}
}
}
}
merged
}