diff --git a/editor/src/plugins/view/warp.rs b/editor/src/plugins/view/warp.rs index 38572cf498..b833be5e6a 100644 --- a/editor/src/plugins/view/warp.rs +++ b/editor/src/plugins/view/warp.rs @@ -125,6 +125,16 @@ fn warp_point(line: String, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Option< 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); return None; diff --git a/map_model/src/make/initial/merge.rs b/map_model/src/make/initial/merge.rs new file mode 100644 index 0000000000..0bfdee8ed2 --- /dev/null +++ b/map_model/src/make/initial/merge.rs @@ -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 = 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);*/ +} diff --git a/map_model/src/make/initial/mod.rs b/map_model/src/make/initial/mod.rs index 8d5c3a20fb..83af8e3a80 100644 --- a/map_model/src/make/initial/mod.rs +++ b/map_model/src/make/initial/mod.rs @@ -1,5 +1,6 @@ mod geometry; pub mod lane_specs; +mod merge; use crate::raw_data::{StableIntersectionID, StableRoadID}; 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); } + merge::short_roads(&mut m); + m } diff --git a/map_model/src/make/mod.rs b/map_model/src/make/mod.rs index 71a36c16ad..040bbef38f 100644 --- a/map_model/src/make/mod.rs +++ b/map_model/src/make/mod.rs @@ -2,7 +2,6 @@ mod buildings; mod bus_stops; mod half_map; mod initial; -mod old_merge_intersections; mod parcels; mod sidewalk_finder; 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::half_map::make_half_map; 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; diff --git a/map_model/src/make/old_merge_intersections.rs b/map_model/src/make/old_merge_intersections.rs deleted file mode 100644 index 34171c1ac4..0000000000 --- a/map_model/src/make/old_merge_intersections.rs +++ /dev/null @@ -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 = 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. -}