From 55fea2d5a7414acf58b5a0188eb4248d7541de85 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 19 Jun 2018 09:15:32 -0700 Subject: [PATCH] moving to new way of generating lanes from osm ways --- editor/src/render/road.rs | 6 ++-- geom/src/road.rs | 2 +- map_model/src/lib.rs | 68 +++++++++++++++++++-------------------- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/editor/src/render/road.rs b/editor/src/render/road.rs index 06e0e16453..36a026a222 100644 --- a/editor/src/render/road.rs +++ b/editor/src/render/road.rs @@ -27,10 +27,10 @@ impl DrawRoad { pub fn new(road: &map_model::Road, geom_map: &geom::GeomMap) -> DrawRoad { let geom_r = geom_map.get_r(road.id); - let thick_line = if road.other_side.is_some() { - geometry::ThickLine::DrivingDirectionOnly(geom::LANE_THICKNESS) - } else { + let thick_line = if road.one_way_road { geometry::ThickLine::Centered(geom::LANE_THICKNESS) + } else { + geometry::ThickLine::DrivingDirectionOnly(geom::LANE_THICKNESS) }; DrawRoad { diff --git a/geom/src/road.rs b/geom/src/road.rs index 2b1bc70615..289309d83a 100644 --- a/geom/src/road.rs +++ b/geom/src/road.rs @@ -40,7 +40,7 @@ impl GeomRoad { pts[0] = Pt2D::from(new_first_pt); pts[num_pts - 1] = Pt2D::from(new_last_pt); - let lane_center_shift = if road.other_side.is_none() { + let lane_center_shift = if road.one_way_road { 0.0 } else if road.use_yellow_center_lines { // TODO I think this is unfair to one side, right? If we hover over the yellow line, it diff --git a/map_model/src/lib.rs b/map_model/src/lib.rs index 0afbf4d4e5..a76d6fad73 100644 --- a/map_model/src/lib.rs +++ b/map_model/src/lib.rs @@ -165,16 +165,18 @@ pub struct Road { // Ideally all of these would just become translated center points immediately, but this is // hard due to the polyline problem. + // All roads are two-way (since even one-way streets have sidewalks on both sides). Offset 0 is + // the centermost lane on each side, then it counts up. + offset: u8, // The orientation is implied by the order of these points pub points: Vec, // Should this lane own the drawing of the yellow center lines? For two-way roads, this is // arbitrarily grouped with one of the lanes. Ideally it would be owned by something else. pub use_yellow_center_lines: bool, - - pub other_side: Option, - // All roads are two-way (since even one-way streets have sidewalks on both sides). Offset 0 is - // the centermost lane on each side, then it counts up. - offset: u8, + // Ugly hack, preserving whether the original road geometry represents a one-way road or not. + pub one_way_road: bool, + // Need to remember this just for detecting U-turns here. + other_side: Option, } impl PartialEq for Road { @@ -271,42 +273,38 @@ impl Map { let orig_direction = true; let reverse_direction = false; - let mut lanes = vec![ - (LaneType::Driving, 0, orig_direction), - (LaneType::Parking, 1, orig_direction), - (LaneType::Sidewalk, 2, orig_direction), + // lane_type, offset, reverse the points or not, offset to get the other_side's ID + let mut lanes: Vec<(LaneType, u8, bool, Option)> = vec![ + ( + LaneType::Driving, + 0, + orig_direction, + if oneway { None } else { Some(1) }, + ), + //(LaneType::Parking, 1, orig_direction, None), + //(LaneType::Sidewalk, 2, orig_direction, None), ]; if oneway { - lanes.push((LaneType::Sidewalk, 0, reverse_direction)); + //lanes.push((LaneType::Sidewalk, 0, reverse_direction, None)); } else { lanes.extend(vec![ - (LaneType::Driving, 0, reverse_direction), - (LaneType::Parking, 1, reverse_direction), - (LaneType::Sidewalk, 2, reverse_direction), + (LaneType::Driving, 0, reverse_direction, Some(-1)), + //(LaneType::Parking, 1, reverse_direction, None), + //(LaneType::Sidewalk, 2, reverse_direction, None), ]); } - // TODO I made a second iter of cloned roads and tried to chain, but couldn't make the - // types work :( so here's this hackier version - for &idx_offset in &vec![0, 1] { - if idx_offset == 1 && r.get_osm_tags().contains(&String::from("oneway=yes")) { - continue; - } - let other_side = match idx_offset { - _ if oneway => None, - 0 => Some(RoadID(counter + 1)), - 1 => Some(RoadID(counter - 1)), - _ => panic!("not possible"), - }; - + for lane in &lanes { let id = RoadID(counter); counter += 1; - let pts: Vec = match idx_offset { - 0 => r.get_points().iter().map(Pt2D::from).collect(), - 1 => r.get_points().iter().rev().map(Pt2D::from).collect(), - _ => panic!("not possible"), - }; + let other_side = lane.3 + .map(|offset| RoadID(((id.0 as isize) + offset) as usize)); + let pts: Vec = if lane.2 == orig_direction { + r.get_points().iter().map(Pt2D::from).collect() + } else { + r.get_points().iter().rev().map(Pt2D::from).collect() + }; let i1 = m.pt_to_intersection[&pts[0]]; let i2 = m.pt_to_intersection[pts.last().unwrap()]; m.intersection_to_roads @@ -321,17 +319,17 @@ impl Map { m.roads.push(Road { id, other_side, - points: pts, osm_tags: r.get_osm_tags().to_vec(), osm_way_id: r.get_osm_way_id(), + lane_type: lane.0, + offset: lane.1, + points: pts, use_yellow_center_lines: if let Some(other) = other_side { id.0 < other.0 } else { false }, - - offset: 0, - lane_type: LaneType::Driving, + one_way_road: oneway, }); } }