From cf457e671325187552fffcb942dd4552918e3eba Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 5 Dec 2022 15:09:36 +0000 Subject: [PATCH] Pass untrimmed lines into the geometry algorithm. #136 Works sometimes, but brittle. I think we really need to maintain trim distance --- osm2streets/src/lib.rs | 1 + .../src/transform/intersection_geometry.rs | 30 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/osm2streets/src/lib.rs b/osm2streets/src/lib.rs index 36b0be61..237152b3 100644 --- a/osm2streets/src/lib.rs +++ b/osm2streets/src/lib.rs @@ -174,6 +174,7 @@ impl StreetNetwork { for road in self.roads_per_intersection(endpts[1]) { let mut input = road.to_input_road(); if road.id == road_id { + // TODO Does this do something different now? input.center_pts = trimmed_center_pts.clone(); } else { input.center_pts = road.untrimmed_road_geometry(self.config.driving_side); diff --git a/osm2streets/src/transform/intersection_geometry.rs b/osm2streets/src/transform/intersection_geometry.rs index 93671cc9..b7b58510 100644 --- a/osm2streets/src/transform/intersection_geometry.rs +++ b/osm2streets/src/transform/intersection_geometry.rs @@ -12,6 +12,13 @@ pub fn generate(streets: &mut StreetNetwork, timer: &mut Timer) { // It'd be nice to mutate in the loop, but the borrow checker won't let us let mut set_polygons = Vec::new(); let mut make_stop_signs = Vec::new(); + + // And actually, we don't want to mutate center_lines until the very end. The input to the + // geometry algorithm should be UNTRIMMED center lines. Every road will get trimmed twice, once + // at each end. When calculating the opposite end, we want to use the full untrimmed line for + // all roads. + let mut trimmed_center_lines = Vec::new(); + for i in streets.intersections.values() { timer.next(); let input_roads = i @@ -23,7 +30,7 @@ pub fn generate(streets: &mut StreetNetwork, timer: &mut Timer) { Ok(results) => { set_polygons.push((i.id, results.intersection_polygon)); for (r, (pl, _)) in results.trimmed_center_pts { - streets.roads.get_mut(&r).unwrap().center_line = pl; + trimmed_center_lines.push((r, i.id, pl)); } } Err(err) => { @@ -58,6 +65,27 @@ pub fn generate(streets: &mut StreetNetwork, timer: &mut Timer) { streets.intersections.remove(&i).unwrap(); } + for (r, i, pl) in trimmed_center_lines { + let road = streets.roads.get_mut(&r).unwrap(); + let maybe_slice = if i == road.src_i { + // pl is trimmed on the start side + road.center_line.safe_get_slice_starting_at(pl.first_pt()) + } else { + road.center_line.safe_get_slice_ending_at(pl.last_pt()) + }; + if let Some(slice) = maybe_slice { + road.center_line = slice; + } else { + // This happens when trimming on the other side actually "eats away" past this side. + // The road is probably an internal_junction_road. The two intersection polygons will + // physically overlap each other. + // + // TODO Or... service_road_loop's deadend at the bottom. We need to EXTEND the line + // sometimes. + error!("Can't trim {r} on the {i} end"); + } + } + fix_map_edges(streets); }