port the simpler intersection merging to InitialMap-world. try the

geometry restoration... wait, need more stuff first
This commit is contained in:
Dustin Carlino 2019-01-26 14:27:20 -08:00
parent aa09303b44
commit c58113d631
5 changed files with 122 additions and 88 deletions

View File

@ -125,6 +125,16 @@ fn warp_point(line: String, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Option<
return None; return None;
} }
} }
// TODO "sr"
'O' => {
let stable_id = raw_data::StableRoadID(idx);
if let Some(r) = map.all_roads().iter().find(|r| r.stable_id == stable_id) {
ID::Lane(r.children_forwards[0].0)
} else {
warn!("{} isn't known", stable_id);
return None;
}
}
_ => { _ => {
warn!("{} isn't a valid ID; Should be [libepct][0-9]+", line); warn!("{} isn't a valid ID; Should be [libepct][0-9]+", line);
return None; return None;

View File

@ -0,0 +1,109 @@
use crate::make::initial::{geometry, InitialMap};
use crate::raw_data::StableRoadID;
use abstutil::{note, retain_btreemap};
//use dimensioned::si;
pub fn short_roads(map: &mut InitialMap) {
// o228
merge(map, StableRoadID(311));
/*
// o201
merge(map, StableRoadID(240));
// o37
merge(map, StableRoadID(91));
// o40
merge(map, StableRoadID(59));
// o25
merge(map, StableRoadID(389));
merge(map, StableRoadID(22));
*/
/*
// Road length effectively changes as we merge things, but not till later, so just use original
// length.
let gps_bounds = data.get_gps_bounds();
let all_ids: Vec<StableRoadID> = data.roads.keys().cloned().collect();
for id in all_ids {
if let Some(r) = data.roads.get(&id) {
let center_pts = PolyLine::new(
r.points
.iter()
.map(|coord| Pt2D::from_gps(*coord, &gps_bounds).unwrap())
.collect(),
);
if center_pts.length() <= 15.0 * si::M {
merge(data, id);
}
}
}
*/
}
fn merge(map: &mut InitialMap, merge_road: StableRoadID) {
// Arbitrarily kill off the first intersection and keep the second one.
let (delete_i, keep_i) = {
let r = map.roads.remove(&merge_road).unwrap();
note(format!(
"Deleting {}, which has original length {} and trimmed length {}",
merge_road,
r.original_center_pts.length(),
r.trimmed_center_pts.length()
));
(r.src_i, r.dst_i)
};
map.intersections.remove(&delete_i);
map.intersections
.get_mut(&keep_i)
.unwrap()
.roads
.remove(&merge_road);
for r in map.roads.values_mut() {
if r.src_i == delete_i {
r.src_i = keep_i;
map.intersections
.get_mut(&keep_i)
.unwrap()
.roads
.insert(r.id);
}
if r.dst_i == delete_i {
r.dst_i = keep_i;
map.intersections
.get_mut(&keep_i)
.unwrap()
.roads
.insert(r.id);
}
}
// We might've created some loop roads on the retained intersection; remove them also.
// TODO Need to delete the references to these loops when we do this.
/*retain_btreemap(&mut map.roads, |_, r| {
r.src_i != keep_i || r.dst_i != keep_i
});*/
// TODO Ah, we can also wind up with multiple roads between the same intersections here. Should
// probably auto-remove those too.
// Now recalculate the polygon for the retained intersection. But first, restore the road
// geometry on the relevant side to its original length, since that can affect the polygon.
// TODO Not ready yet, hang on.
/*for id in &map.intersections[&keep_i].roads {
let r = map.get_mut(id).unwrap();
// Safe to do 'else' here, because we removed the loop roads.
if r.src_i == keep_i {
let append = r.original_center_pts.trim_to_pt(r.trimmed_center_pts.last_pt());
r.trimmed_center_pts = r.trimmed_center_pts.append(&append);
} else {
}
}*/
/*let mut i = map.intersections.get_mut(&keep_i).unwrap();
i.polygon = geometry::intersection_polygon(i, &mut map.roads);*/
}

View File

@ -1,5 +1,6 @@
mod geometry; mod geometry;
pub mod lane_specs; pub mod lane_specs;
mod merge;
use crate::raw_data::{StableIntersectionID, StableRoadID}; use crate::raw_data::{StableIntersectionID, StableRoadID};
use crate::{raw_data, MapEdits, LANE_THICKNESS}; use crate::{raw_data, MapEdits, LANE_THICKNESS};
@ -111,5 +112,7 @@ pub fn make_initial_map(
i.polygon = geometry::intersection_polygon(i, &mut m.roads); i.polygon = geometry::intersection_polygon(i, &mut m.roads);
} }
merge::short_roads(&mut m);
m m
} }

View File

@ -2,7 +2,6 @@ mod buildings;
mod bus_stops; mod bus_stops;
mod half_map; mod half_map;
mod initial; mod initial;
mod old_merge_intersections;
mod parcels; mod parcels;
mod sidewalk_finder; mod sidewalk_finder;
mod turns; mod turns;
@ -11,5 +10,4 @@ pub use self::buildings::make_all_buildings;
pub use self::bus_stops::{make_bus_stops, verify_bus_routes}; pub use self::bus_stops::{make_bus_stops, verify_bus_routes};
pub use self::half_map::make_half_map; pub use self::half_map::make_half_map;
pub use self::initial::lane_specs::{get_lane_types, RoadSpec}; pub use self::initial::lane_specs::{get_lane_types, RoadSpec};
pub use self::old_merge_intersections::old_merge_intersections;
pub use self::parcels::make_all_parcels; pub use self::parcels::make_all_parcels;

View File

@ -1,86 +0,0 @@
use crate::raw_data;
use abstutil::{note, retain_btreemap, Timer};
use dimensioned::si;
use geom::{PolyLine, Pt2D};
pub fn old_merge_intersections(data: &mut raw_data::Map, _timer: &mut Timer) {
if true {
return;
}
// o228
merge(data, raw_data::StableRoadID(311));
// o201
merge(data, raw_data::StableRoadID(240));
// o37
merge(data, raw_data::StableRoadID(91));
// o40
merge(data, raw_data::StableRoadID(59));
// o25
merge(data, raw_data::StableRoadID(389));
merge(data, raw_data::StableRoadID(22));
if true {
return;
}
// Road length effectively changes as we merge things, but not till later, so just use original
// length.
let gps_bounds = data.get_gps_bounds();
let all_ids: Vec<raw_data::StableRoadID> = data.roads.keys().cloned().collect();
for id in all_ids {
if let Some(r) = data.roads.get(&id) {
let center_pts = PolyLine::new(
r.points
.iter()
.map(|coord| Pt2D::from_gps(*coord, &gps_bounds).unwrap())
.collect(),
);
if center_pts.length() <= 15.0 * si::M {
merge(data, id);
}
}
}
}
fn merge(data: &mut raw_data::Map, merge_road: raw_data::StableRoadID) {
// Arbitrarily kill off the first intersection and keep the second one.
let (delete_i, keep_i) = {
let r = data.roads.remove(&merge_road).unwrap();
let gps_bounds = data.get_gps_bounds();
let center_pts = PolyLine::new(
r.points
.iter()
.map(|coord| Pt2D::from_gps(*coord, &gps_bounds).unwrap())
.collect(),
);
note(format!(
"Deleting {}, which has original length {}",
merge_road,
center_pts.length()
));
(r.i1, r.i2)
};
data.intersections.remove(&delete_i);
for r in data.roads.values_mut() {
if r.i1 == delete_i {
r.i1 = keep_i;
}
if r.i2 == delete_i {
r.i2 = keep_i;
}
}
// We might've created some loop roads on the retained intersection; remove them also.
retain_btreemap(&mut data.roads, |_, r| r.i1 != keep_i || r.i2 != keep_i);
// TODO Ah, we can also wind up with multiple roads between the same intersections here. Should
// probably auto-remove those too.
}