matching extra shapes with a particular side of the road

This commit is contained in:
Dustin Carlino 2018-11-21 15:54:56 -08:00
parent af6ead7d56
commit 9e91332b58
4 changed files with 31 additions and 10 deletions

View File

@ -11,7 +11,7 @@ pub enum ShowOwnerState {
Inactive, Inactive,
BuildingSelected(BuildingID, HashSet<CarID>), BuildingSelected(BuildingID, HashSet<CarID>),
CarSelected(CarID, Option<BuildingID>), CarSelected(CarID, Option<BuildingID>),
ShapeSelected(ExtraShapeID, Option<RoadID>), ShapeSelected(ExtraShapeID, Option<(RoadID, bool)>),
} }
impl ShowOwnerState { impl ShowOwnerState {
@ -88,8 +88,11 @@ impl Plugin for ShowOwnerState {
return Some(color); return Some(color);
} }
} }
(ShowOwnerState::ShapeSelected(_, Some(r)), ID::Lane(l)) => { (ShowOwnerState::ShapeSelected(_, Some((r, fwds))), ID::Lane(l)) => {
if ctx.map.get_parent(l).id == *r { let parent = ctx.map.get_parent(l);
if parent.id == *r
&& ((*fwds && parent.is_forwards(l)) || (!fwds && parent.is_backwards(l)))
{
return Some(color); return Some(color);
} }
} }

View File

@ -28,7 +28,7 @@ pub struct DrawExtraShape {
pub id: ExtraShapeID, pub id: ExtraShapeID,
shape: Shape, shape: Shape,
pub attributes: BTreeMap<String, String>, pub attributes: BTreeMap<String, String>,
pub road: Option<RoadID>, pub road: Option<(RoadID, bool)>,
} }
impl DrawExtraShape { impl DrawExtraShape {
@ -36,7 +36,7 @@ impl DrawExtraShape {
id: ExtraShapeID, id: ExtraShapeID,
s: ExtraShape, s: ExtraShape,
gps_bounds: &GPSBounds, gps_bounds: &GPSBounds,
closest: &FindClosest<RoadID>, closest: &FindClosest<(RoadID, bool)>,
) -> Option<DrawExtraShape> { ) -> Option<DrawExtraShape> {
let mut pts: Vec<Pt2D> = Vec::new(); let mut pts: Vec<Pt2D> = Vec::new();
for pt in s.points.into_iter() { for pt in s.points.into_iter() {

View File

@ -7,7 +7,7 @@ use geom::{Bounds, Pt2D};
use kml::ExtraShape; use kml::ExtraShape;
use map_model::{ use map_model::{
AreaID, BuildingID, BusStopID, FindClosest, IntersectionID, Lane, LaneID, Map, ParcelID, AreaID, BuildingID, BusStopID, FindClosest, IntersectionID, Lane, LaneID, Map, ParcelID,
RoadID, Turn, TurnID, RoadID, Turn, TurnID, LANE_THICKNESS,
}; };
use objects::ID; use objects::ID;
use plugins::hider::Hider; use plugins::hider::Hider;
@ -86,11 +86,15 @@ impl DrawMap {
let mut extra_shapes: Vec<DrawExtraShape> = Vec::new(); let mut extra_shapes: Vec<DrawExtraShape> = Vec::new();
if !raw_extra_shapes.is_empty() { if !raw_extra_shapes.is_empty() {
// Match shapes with the nearest road // Match shapes with the nearest road + direction (true for forwards)
let mut closest: FindClosest<RoadID> = map_model::FindClosest::new(&map.get_bounds()); let mut closest: FindClosest<(RoadID, bool)> =
// TODO double each road into two sides... map_model::FindClosest::new(&map.get_bounds());
for r in map.all_roads().iter() { for r in map.all_roads().iter() {
closest.add(r.id, &r.center_pts); closest.add((r.id, true), &r.center_pts.shift_blindly(LANE_THICKNESS));
closest.add(
(r.id, false),
&r.center_pts.reversed().shift_blindly(LANE_THICKNESS),
);
} }
let gps_bounds = map.get_gps_bounds(); let gps_bounds = map.get_gps_bounds();

View File

@ -50,6 +50,20 @@ impl Road {
) )
} }
pub fn is_forwards(&self, lane: LaneID) -> bool {
self.children_forwards
.iter()
.find(|(id, _)| *id == lane)
.is_some()
}
pub fn is_backwards(&self, lane: LaneID) -> bool {
self.children_backwards
.iter()
.find(|(id, _)| *id == lane)
.is_some()
}
// lane must belong to this road. Offset 0 is the centermost lane on each side of a road, then // lane must belong to this road. Offset 0 is the centermost lane on each side of a road, then
// it counts up from there. Returns true for the forwards direction, false for backwards. // it counts up from there. Returns true for the forwards direction, false for backwards.
pub fn dir_and_offset(&self, lane: LaneID) -> (bool, usize) { pub fn dir_and_offset(&self, lane: LaneID) -> (bool, usize) {