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
use abstutil::Timer;
use geom::{Bounds, Distance, FindClosest};

use crate::{Road, RoadID};

// Look for roads underneath bridges, then lower their z-order. OSM tags bridges and tunnels, but
// not the roads that pass under bridges.
pub fn find_bridges(roads: &mut Vec<Road>, bounds: &Bounds, timer: &mut Timer) {
    let mut closest: FindClosest<RoadID> = FindClosest::new(bounds);
    let mut bridges = Vec::new();
    for r in roads.iter() {
        closest.add(r.id, r.center_pts.points());
        if r.osm_tags.contains_key("bridge") {
            bridges.push(r.id);
        }
    }

    timer.start_iter("find roads underneath bridge", bridges.len());
    for bridge in bridges {
        timer.next();
        let bridge_pts = roads[bridge.0].center_pts.clone();
        for (r, _, _) in closest.all_close_pts(bridge_pts.middle(), Distance::meters(500.0)) {
            if bridge != r
                && bridge_pts != roads[r.0].center_pts
                && bridge_pts.intersection(&roads[r.0].center_pts).is_some()
            {
                if roads[r.0].zorder == 0 {
                    roads[r.0].zorder = -1;
                }
            }
        }
    }
}