mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
consider again the possibility of merging some degenerate roads
This commit is contained in:
parent
e50cd77675
commit
187c8ad4c5
@ -15,9 +15,9 @@ use ezgui::{
|
||||
HorizontalAlignment, Key, Line, Outcome, Text, UpdateType, VerticalAlignment, Widget, Wizard,
|
||||
};
|
||||
use geom::Pt2D;
|
||||
use map_model::{ControlTrafficSignal, NORMAL_LANE_THICKNESS};
|
||||
use map_model::{osm, ControlTrafficSignal, NORMAL_LANE_THICKNESS};
|
||||
use sim::{AgentID, Sim};
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
|
||||
pub struct DebugMode {
|
||||
composite: Composite,
|
||||
@ -60,6 +60,7 @@ impl DebugMode {
|
||||
(hotkey(Key::U), "load next sim state"),
|
||||
(None, "pick a savestate to load"),
|
||||
(None, "find bad traffic signals"),
|
||||
(None, "find degenerate roads"),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(key, action)| Btn::text_fg(action).build_def(ctx, key))
|
||||
@ -210,6 +211,9 @@ impl State for DebugMode {
|
||||
"find bad traffic signals" => {
|
||||
find_bad_signals(app);
|
||||
}
|
||||
"find degenerate roads" => {
|
||||
find_degenerate_roads(app);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
None => {}
|
||||
@ -602,3 +606,70 @@ fn find_bad_signals(app: &App) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn find_degenerate_roads(app: &App) {
|
||||
let map = &app.primary.map;
|
||||
for i in map.all_intersections() {
|
||||
if i.roads.len() != 2 {
|
||||
continue;
|
||||
}
|
||||
if i.turns.iter().any(|t| map.get_t(*t).between_sidewalks()) {
|
||||
continue;
|
||||
}
|
||||
let (r1, r2) = {
|
||||
let mut iter = i.roads.iter();
|
||||
(*iter.next().unwrap(), *iter.next().unwrap())
|
||||
};
|
||||
let r1 = map.get_r(r1);
|
||||
let r2 = map.get_r(r2);
|
||||
if r1.zorder != r2.zorder {
|
||||
continue;
|
||||
}
|
||||
if r1
|
||||
.children_forwards
|
||||
.iter()
|
||||
.map(|(_, lt)| *lt)
|
||||
.collect::<Vec<_>>()
|
||||
!= r2
|
||||
.children_forwards
|
||||
.iter()
|
||||
.map(|(_, lt)| *lt)
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if r1
|
||||
.children_backwards
|
||||
.iter()
|
||||
.map(|(_, lt)| *lt)
|
||||
.collect::<Vec<_>>()
|
||||
!= r2
|
||||
.children_backwards
|
||||
.iter()
|
||||
.map(|(_, lt)| *lt)
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
println!("Maybe merge {}", i.id);
|
||||
diff_tags(&r1.osm_tags, &r2.osm_tags);
|
||||
}
|
||||
}
|
||||
|
||||
fn diff_tags(t1: &BTreeMap<String, String>, t2: &BTreeMap<String, String>) {
|
||||
for (k, v1) in t1 {
|
||||
if k == osm::OSM_WAY_ID {
|
||||
continue;
|
||||
}
|
||||
let v2 = t2.get(k).cloned().unwrap_or_else(String::new);
|
||||
if v1 != &v2 {
|
||||
println!("- {} = \"{}\" vs \"{}\"", k, v1, v2);
|
||||
}
|
||||
}
|
||||
for (k, v2) in t2 {
|
||||
if !t1.contains_key(k) {
|
||||
println!("- {} = \"\" vs \"{}\"", k, v2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,13 +76,24 @@ fn generalized_trim_back(
|
||||
lines: &Vec<(OriginalRoad, Line, PolyLine, PolyLine)>,
|
||||
timer: &mut Timer,
|
||||
) -> (Vec<Pt2D>, Vec<(String, Polygon)>) {
|
||||
let debug = Vec::new();
|
||||
let mut debug = Vec::new();
|
||||
|
||||
let mut road_lines: Vec<(OriginalRoad, PolyLine, PolyLine)> = Vec::new();
|
||||
for (r, _, pl1, pl2) in lines {
|
||||
// TODO Argh, just use original lines.
|
||||
road_lines.push((*r, pl1.clone(), pl2.clone()));
|
||||
road_lines.push((*r, pl2.clone(), pl1.clone()));
|
||||
|
||||
if false {
|
||||
debug.push((
|
||||
format!("{} fwd", r.osm_way_id),
|
||||
pl1.make_polygons(Distance::meters(1.0)),
|
||||
));
|
||||
debug.push((
|
||||
format!("{} back", r.osm_way_id),
|
||||
pl2.make_polygons(Distance::meters(1.0)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let mut new_road_centers: BTreeMap<OriginalRoad, PolyLine> = BTreeMap::new();
|
||||
|
Loading…
Reference in New Issue
Block a user