Whittle down more deprecated Road stuff

This commit is contained in:
Dustin Carlino 2020-08-24 16:21:20 -07:00
parent aa3bd5073b
commit b6a4657dbb
7 changed files with 32 additions and 62 deletions

View File

@ -136,8 +136,7 @@ pub fn try_change_lt(
// TODO Ban two adjacent parking lanes (What about dppd though?)
// A parking lane must have a driving lane somewhere on the road.
let (fwd, back) = r.get_lane_types();
let all_types: BTreeSet<LaneType> = fwd.chain(back).collect();
let all_types: BTreeSet<LaneType> = r.lanes_ltr().into_iter().map(|(_, _, lt)| lt).collect();
if all_types.contains(&LaneType::Parking) && !all_types.contains(&LaneType::Driving) {
errors.push(format!(
"A parking lane needs a driving lane somewhere on the same road"

View File

@ -69,8 +69,14 @@ impl BikeNetwork {
// Show throughput, broken down by bike lanes or not
for ((r, agent_type, _), count) in &app.primary.sim.get_analytics().road_thruput.counts {
if *agent_type == AgentType::Bike {
let (mut fwd, mut back) = app.primary.map.get_r(*r).get_lane_types();
if fwd.any(|lt| lt == LaneType::Biking) || back.any(|lt| lt == LaneType::Biking) {
if app
.primary
.map
.get_r(*r)
.lanes_ltr()
.into_iter()
.any(|(_, _, lt)| lt == LaneType::Biking)
{
on_bike_lanes.add(*r, *count);
} else {
off_bike_lanes.add(*r, *count);

View File

@ -353,9 +353,11 @@ fn calculate_turn_markings(map: &Map, lane: &Lane) -> Vec<Polygon> {
fn calculate_one_way_markings(lane: &Lane, parent: &Road) -> Vec<Polygon> {
let mut results = Vec::new();
if parent
.any_on_other_side(lane.id, LaneType::Driving)
.is_some()
let lanes = parent.lanes_ltr();
let dir = parent.dir(lane.id);
if lanes
.into_iter()
.any(|(_, d, lt)| dir != d && lt == LaneType::Driving)
{
// Not a one-way
return results;

View File

@ -115,8 +115,6 @@ pub struct Road {
pub dst_i: IntersectionID,
}
type HomogenousTuple2<T> = (T, T);
impl Road {
// Returns all lanes from the left side of the road to right. Left/right is determined by the
// orientation of center_pts.
@ -172,15 +170,6 @@ impl Road {
}
}
// TODO Deprecated
pub fn get_lane_types<'a>(&'a self) -> HomogenousTuple2<impl Iterator<Item = LaneType> + 'a> {
let get_lanetype = |(_, lt): &(_, LaneType)| *lt;
(
self.children_forwards.iter().map(get_lanetype.clone()),
self.children_backwards.iter().map(get_lanetype),
)
}
// TODO Deprecated
pub fn get_dir(&self, lane: LaneID) -> Direction {
self.dir_and_offset(lane).0
@ -292,11 +281,6 @@ impl Road {
.collect()
}
// TODO Deprecated
pub fn lanes_on_side<'a>(&'a self, dir: Direction) -> impl Iterator<Item = LaneID> + 'a {
self.children(dir).iter().map(|(id, _)| *id)
}
// TODO Deprecated
// This is the yellow line where the direction of the road changes.
pub fn get_current_center(&self, map: &Map) -> PolyLine {
@ -308,12 +292,6 @@ impl Road {
map.must_left_shift(lane.lane_center_pts.clone(), lane.width / 2.0)
}
// TODO Deprecated
pub fn any_on_other_side(&self, l: LaneID, lt: LaneType) -> Option<LaneID> {
let search = self.children(self.get_dir(l).opposite());
search.iter().find(|(_, t)| lt == *t).map(|(id, _)| *id)
}
pub fn get_half_width(&self, map: &Map) -> Distance {
self.all_lanes()
.into_iter()

View File

@ -281,39 +281,29 @@ impl TurnGroup {
// Polyline points FROM intersection
pub fn src_center_and_width(&self, map: &Map) -> (PolyLine, Distance) {
let r = map.get_r(self.id.from.id);
let dir = self.id.from.dir;
// Points towards the intersection
let pl = if dir == Direction::Fwd {
r.get_current_center(map)
} else {
r.get_current_center(map).reversed()
};
// TODO Poorly expressed. We just want the first leftmost value, and the last rightmost.
let mut leftmost = Distance::meters(99999.0);
let mut rightmost = Distance::ZERO;
let mut left = Distance::ZERO;
let mut right = Distance::ZERO;
for l in r.lanes_on_side(dir) {
right += map.get_l(l).width;
for (l, _, _) in r.lanes_ltr() {
let right = left + map.get_l(l).width;
if self.members.iter().any(|t| t.src == l) {
leftmost = leftmost.min(left);
rightmost = rightmost.max(right);
}
left += map.get_l(l).width;
left = right;
}
let pl = map.must_right_shift(pl, (leftmost + rightmost) / 2.0);
let mut pl = map.must_right_shift(r.get_left_side(map), (leftmost + rightmost) / 2.0);
if self.id.from.dir == Direction::Back {
pl = pl.reversed();
}
// Flip direction, so we point away from the intersection
let pl = if self.id.crosswalk
&& map.get_l(self.members[0].src).src_i == self.members[0].parent
{
pl
} else {
pl.reversed()
if !self.id.crosswalk || map.get_l(self.members[0].src).src_i != self.members[0].parent {
pl = pl.reversed()
};
(pl, rightmost - leftmost)
}

View File

@ -297,32 +297,27 @@ impl UberTurnGroup {
// Polyline points FROM intersection
pub fn src_center_and_width(&self, map: &Map) -> (PolyLine, Distance) {
let r = map.get_r(self.from.id);
let dir = self.from.dir;
// Points towards the intersection
let pl = if dir == Direction::Fwd {
r.get_current_center(map)
} else {
r.get_current_center(map).reversed()
};
// TODO Poorly expressed. We just want the first leftmost value, and the last rightmost.
let mut leftmost = Distance::meters(99999.0);
let mut rightmost = Distance::ZERO;
let mut left = Distance::ZERO;
let mut right = Distance::ZERO;
for l in r.lanes_on_side(dir) {
right += map.get_l(l).width;
for (l, _, _) in r.lanes_ltr() {
let right = left + map.get_l(l).width;
if self.members.iter().any(|ut| ut.entry() == l) {
leftmost = leftmost.min(left);
rightmost = rightmost.max(right);
}
left += map.get_l(l).width;
left = right;
}
let pl = map.must_right_shift(pl, (leftmost + rightmost) / 2.0);
let mut pl = map.must_right_shift(r.get_left_side(map), (leftmost + rightmost) / 2.0);
// Point towards the intersection
if self.from.dir == Direction::Back {
pl = pl.reversed();
}
// Flip direction, so we point away from the intersection
(pl.reversed(), rightmost - leftmost)
}

View File

@ -131,7 +131,7 @@ impl Car {
let driving_offset = r.offset(self.router.head().as_lane());
let parking_offset = r.offset(*parking_l);
let mut diff = (parking_offset as isize) - (driving_offset as isize);
if r.get_dir(self.router.head().as_lane()) == Direction::Back {
if r.dir(self.router.head().as_lane()) == Direction::Back {
diff *= -1;
}
// TODO Sum widths in between, don't assume they're all the same as the