From 91920c3e1d71c6727fe7b15f28dcac9d32e544cf Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 18 Jun 2018 14:46:11 -0700 Subject: [PATCH] dont reach into DrawRoad's polygon directly from DrawIntersection --- TODO.md | 8 ++++++++ docs/lanes.md | 19 +++++++++++++++++++ editor/src/render/intersection.rs | 13 ++++++------- editor/src/render/road.rs | 12 ++++++++++++ geom/src/geometry.rs | 3 ++- map_model/src/lib.rs | 9 +++++++-- 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 4b906faccc..c57decb7c1 100644 --- a/TODO.md +++ b/TODO.md @@ -45,6 +45,14 @@ - https://gis-kingcounty.opendata.arcgis.com/datasets/traffic-signs--sign-point/ - multiple lanes + - prep: get rid of other_side + - display + mouseover parking lane and sidewalk + - all roads have sidewalk on both sides, oneways only have parking lane on one side + - model bikes in driving lanes (as slow cars) + - add random bike lanes, figure out how turns would work + - be able to convert between parking and bike lanes, recompute the turns + + - when rendering sidewalks, have an option for a grass buffer ## Code cleanup diff --git a/docs/lanes.md b/docs/lanes.md index 8c03df0dda..aa76df4d8c 100644 --- a/docs/lanes.md +++ b/docs/lanes.md @@ -34,3 +34,22 @@ Some modeling questions: - maintaining directional sanity could be useful - what's the UI for changing lane types? - it's a bit arbitrary which lane should draw the yellow center lines + + + +Initial design: +- "Road" becomes "Lane" with a type +- don't need to know sibling lanes yet +- arbitrarily, one lane might have extra bits/geometry for yellow center line markings +- ideally, get rid of one-wayness and original center points, and plumb along pre-shifted lines + - but due to the polyline problem (affecting both geom center line layer that agents follow, and polygons for drawing), can't do this. encapsulate the messiness at least. + - so, store one way and orig points and index, but have an accessor + - as a compromise, dont interpet OSM points on a one-way road as the center, but as the edge. + + + +The polyline problem: +- https://www.codeproject.com/Articles/226569/Drawing-polylines-by-tessellation +- https://stackoverflow.com/questions/36475254/polylines-outline-construction-drawing-thick-polylines +- Will lengths change? Is this a problem? +- Drawing cars as rectangles is funky, because if their front is aligned to a new line segment, their back juts into the center of the road diff --git a/editor/src/render/intersection.rs b/editor/src/render/intersection.rs index e19ca22915..5183689697 100644 --- a/editor/src/render/intersection.rs +++ b/editor/src/render/intersection.rs @@ -29,16 +29,15 @@ impl DrawIntersection { bounds: &Bounds, ) -> DrawIntersection { let mut pts: Vec = Vec::new(); - // TODO this smashes encapsulation to bits :D for r in &map.get_roads_to_intersection(inter.id) { - let dr = &roads[r.id.0]; - pts.push(dr.polygons.last().unwrap()[2]); - pts.push(dr.polygons.last().unwrap()[3]); + let (pt1, pt2) = roads[r.id.0].get_end_crossing(); + pts.push(pt1); + pts.push(pt2); } for r in &map.get_roads_from_intersection(inter.id) { - let dr = &roads[r.id.0]; - pts.push(dr.polygons[0][0]); - pts.push(dr.polygons[0][1]); + let (pt1, pt2) = roads[r.id.0].get_start_crossing(); + pts.push(pt1); + pts.push(pt2); } let center = geometry::gps_to_screen_space(&inter.point, bounds); diff --git a/editor/src/render/road.rs b/editor/src/render/road.rs index fb8f278869..a4aa8c64d6 100644 --- a/editor/src/render/road.rs +++ b/editor/src/render/road.rs @@ -129,4 +129,16 @@ impl DrawRoad { lines.extend(r.osm_tags.iter().cloned()); lines } + + // Get the line marking the end of the road, perpendicular to the direction of the road + pub(crate) fn get_end_crossing(&self) -> (Vec2d, Vec2d) { + ( + self.polygons.last().unwrap()[2], + self.polygons.last().unwrap()[3], + ) + } + + pub(crate) fn get_start_crossing(&self) -> (Vec2d, Vec2d) { + (self.polygons[0][0], self.polygons[0][1]) + } } diff --git a/geom/src/geometry.rs b/geom/src/geometry.rs index 5bb4d3d84c..84b792757b 100644 --- a/geom/src/geometry.rs +++ b/geom/src/geometry.rs @@ -67,7 +67,8 @@ pub fn thick_multiline(style: &ThickLine, pts: &[Pt2D]) -> Vec> { let quad2 = thick_line(style, pt2, pt3); // Of course, the original quad polygons.push(quad1.clone()); - // Add some triangles to fill in the gaps. + // Add some triangles to fill in the gaps. Comment this out to see part of the polyline + // problem more clearly. polygons.push(vec![ [pt2.x(), pt2.y()], quad1[3], diff --git a/map_model/src/lib.rs b/map_model/src/lib.rs index c78b5d5a8d..cd3f8d217b 100644 --- a/map_model/src/lib.rs +++ b/map_model/src/lib.rs @@ -151,11 +151,16 @@ pub struct Map { #[derive(Debug)] pub struct Road { pub id: RoadID, - // The orientation is implied by the order of these points - pub points: Vec, pub osm_tags: Vec, pub osm_way_id: i64, + + // Ideally all of these would just become translated center points immediately, but this is + // hard due to the polyline problem. + + // The orientation is implied by the order of these points + pub points: Vec, pub other_side: Option, + //offset: u8, } impl PartialEq for Road {