From 1c98dd55b78881766c21a0af92781b42b6176f11 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 26 Aug 2020 17:29:41 -0700 Subject: [PATCH] Simplify original_roads by recomputing from OSM data --- game/src/edit/mod.rs | 2 +- game/src/layer/map.rs | 4 ++-- map_model/src/edits/mod.rs | 21 +++++++++------------ map_model/src/edits/perma.rs | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/game/src/edit/mod.rs b/game/src/edit/mod.rs index 68e8551269..104eac1e30 100644 --- a/game/src/edit/mod.rs +++ b/game/src/edit/mod.rs @@ -712,7 +712,7 @@ fn make_changelist(ctx: &mut EventCtx, app: &App) -> Composite { Btn::text_fg("Autosaved!").inactive(ctx) }, Text::from_multiline(vec![ - Line(format!("{} roads changed", edits.original_roads.len())), + Line(format!("{} roads changed", edits.changed_roads.len())), Line(format!( "{} intersections changed", edits.original_intersections.len() diff --git a/game/src/layer/map.rs b/game/src/layer/map.rs index 09e693e78f..3e3425375b 100644 --- a/game/src/layer/map.rs +++ b/game/src/layer/map.rs @@ -224,7 +224,7 @@ impl Static { let edits = app.primary.map.get_edits(); // TODO Actually this loses tons of information; we really should highlight just the // changed lanes - for r in edits.original_roads.keys() { + for r in &edits.changed_roads { colorer.add_r(*r, "modified road/intersection"); } for i in edits.original_intersections.keys() { @@ -237,7 +237,7 @@ impl Static { "map edits", format!("Map edits ({})", edits.edits_name), Text::from_multiline(vec![ - Line(format!("{} roads changed", edits.original_roads.len())), + Line(format!("{} roads changed", edits.changed_roads.len())), Line(format!( "{} intersections changed", edits.original_intersections.len() diff --git a/map_model/src/edits/mod.rs b/map_model/src/edits/mod.rs index 778601412d..183211f988 100644 --- a/map_model/src/edits/mod.rs +++ b/map_model/src/edits/mod.rs @@ -19,8 +19,7 @@ pub struct MapEdits { pub commands: Vec, // Derived from commands, kept up to date by update_derived - // TODO Do we need to store the original? We can just do EditRoad::get_orig_from_osm. - pub original_roads: BTreeMap, + pub changed_roads: BTreeSet, pub original_intersections: BTreeMap, pub changed_routes: BTreeSet, @@ -94,7 +93,7 @@ impl MapEdits { proposal_link: None, commands: Vec::new(), - original_roads: BTreeMap::new(), + changed_roads: BTreeSet::new(), original_intersections: BTreeMap::new(), changed_routes: BTreeSet::new(), } @@ -124,16 +123,14 @@ impl MapEdits { } fn update_derived(&mut self, map: &Map) { - self.original_roads.clear(); + self.changed_roads.clear(); self.original_intersections.clear(); self.changed_routes.clear(); for cmd in &self.commands { match cmd { - EditCmd::ChangeRoad { r, ref old, .. } => { - if !self.original_roads.contains_key(r) { - self.original_roads.insert(*r, old.clone()); - } + EditCmd::ChangeRoad { r, .. } => { + self.changed_roads.insert(*r); } EditCmd::ChangeIntersection { i, ref old, .. } => { if !self.original_intersections.contains_key(i) { @@ -146,8 +143,8 @@ impl MapEdits { } } - retain_btreemap(&mut self.original_roads, |r, orig| { - map.get_r_edit(*r) != orig.clone() + retain_btreeset(&mut self.changed_roads, |r| { + map.get_r_edit(*r) != EditRoad::get_orig_from_osm(map.get_r(*r)) }); retain_btreemap(&mut self.original_intersections, |i, orig| { map.get_i_edit(*i) != orig.clone() @@ -160,10 +157,10 @@ impl MapEdits { // Assumes update_derived has been called. fn compress(&mut self, map: &Map) { - for (r, old) in &self.original_roads { + for r in &self.changed_roads { self.commands.push(EditCmd::ChangeRoad { r: *r, - old: old.clone(), + old: EditRoad::get_orig_from_osm(map.get_r(*r)), new: map.get_r_edit(*r), }); } diff --git a/map_model/src/edits/perma.rs b/map_model/src/edits/perma.rs index 246173811a..173dcdda22 100644 --- a/map_model/src/edits/perma.rs +++ b/map_model/src/edits/perma.rs @@ -137,7 +137,7 @@ impl PermanentMapEdits { }) .collect::, String>>()?, - original_roads: BTreeMap::new(), + changed_roads: BTreeSet::new(), original_intersections: BTreeMap::new(), changed_routes: BTreeSet::new(), };