Skip to content

Commit

Permalink
Combine the two methods that update an intersection, so it's less eas…
Browse files Browse the repository at this point in the history
…y to make a mistake and forget one. #159
  • Loading branch information
dabreegster committed Jan 21, 2023
1 parent cfea247 commit 629afe2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion osm2streets-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl JsStreetNetwork {
}
}
for i in intersections {
self.inner.update_geometry(i);
self.inner.update_i(i);
}

self.ways.get_mut(&id).unwrap().tags = tags;
Expand Down
11 changes: 8 additions & 3 deletions osm2streets/src/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,15 @@ impl StreetNetwork {
intersection.roads = road_centers.into_iter().map(|(r, _, _)| r).collect();
}

/// Updates the derived properties of an intersection.
///
/// Updates an intersection's derived properties -- geometry (and attached roads) and
/// movements.
pub fn update_i(&mut self, i: IntersectionID) {
self.update_geometry(i);
self.update_movements(i);
}

/// The kind and movements of a `MapEdge` are handled independently, so this method skips them.
pub fn update_movements(&mut self, i: IntersectionID) {
pub(crate) fn update_movements(&mut self, i: IntersectionID) {
if self.intersections[&i].kind == IntersectionKind::MapEdge {
return;
}
Expand Down
6 changes: 2 additions & 4 deletions osm2streets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ impl StreetNetwork {
for i in endpts {
self.intersections.get_mut(&i).unwrap().roads.push(id);
self.sort_roads(i);
self.update_geometry(i);
self.update_movements(i);
self.update_i(i);
}
}

Expand All @@ -112,8 +111,7 @@ impl StreetNetwork {
.roads
.retain(|r| *r != id);
// Since the roads are already sorted, removing doesn't break the sort.
self.update_geometry(i);
self.update_movements(i);
self.update_i(i);
}
self.roads.remove(&id).unwrap()
}
Expand Down
3 changes: 1 addition & 2 deletions osm2streets/src/operations/collapse_short_road.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ impl StreetNetwork {

// We just connected a bunch of things to keep_i. Fix ordering and movements.
self.sort_roads(keep_i);
self.update_geometry(keep_i);
self.update_movements(keep_i);
self.update_i(keep_i);

// TODO Fix up turn restrictions. Many cases:
// [ ] road we're deleting has simple restrictions
Expand Down
2 changes: 1 addition & 1 deletion osm2streets/src/operations/update_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{IntersectionID, Road, StreetNetwork};
impl StreetNetwork {
/// Recalculates trim distances and intersection geometry. This is idempotent; it doesn't use
/// any results from the previous call.
pub fn update_geometry(&mut self, id: IntersectionID) {
pub(crate) fn update_geometry(&mut self, id: IntersectionID) {
let i = &self.intersections[&id];

// Update the polygon and Set trim distances for roads
Expand Down
3 changes: 1 addition & 2 deletions osm2streets/src/transform/sausage_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ fn fix(streets: &mut StreetNetwork, id1: RoadID, id2: RoadID) {
road1.update_center_line(streets.config.driving_side);
let intersections = road1.endpoints();
for i in intersections {
streets.update_geometry(i);
streets.update_movements(i);
streets.update_i(i);
}
}

Expand Down
3 changes: 1 addition & 2 deletions streets_reader/src/split_ways.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ pub fn split_up_roads(
let intersection_ids: Vec<_> = streets.intersections.keys().cloned().collect();
for i in intersection_ids {
streets.sort_roads(i);
streets.update_geometry(i);
streets.update_movements(i);
streets.update_i(i);
}
timer.stop("calculate intersection geometry and movements");

Expand Down

0 comments on commit 629afe2

Please sign in to comment.