Simplify original_roads by recomputing from OSM data

This commit is contained in:
Dustin Carlino 2020-08-26 17:29:41 -07:00
parent b6ab06d51a
commit 1c98dd55b7
4 changed files with 13 additions and 16 deletions

View File

@ -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()

View File

@ -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()

View File

@ -19,8 +19,7 @@ pub struct MapEdits {
pub commands: Vec<EditCmd>,
// 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<RoadID, EditRoad>,
pub changed_roads: BTreeSet<RoadID>,
pub original_intersections: BTreeMap<IntersectionID, EditIntersection>,
pub changed_routes: BTreeSet<BusRouteID>,
@ -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),
});
}

View File

@ -137,7 +137,7 @@ impl PermanentMapEdits {
})
.collect::<Result<Vec<EditCmd>, String>>()?,
original_roads: BTreeMap::new(),
changed_roads: BTreeSet::new(),
original_intersections: BTreeMap::new(),
changed_routes: BTreeSet::new(),
};