Undo some uses of impl trait. Originally added for performance in a big

refactor, they complicate the function signatures significantly and have
no observable perf impact, since all of the methods just happen in map
importing.
This commit is contained in:
Dustin Carlino 2020-09-29 15:53:08 -07:00
parent a64fe01c3a
commit 2c63a485cc
11 changed files with 66 additions and 74 deletions

View File

@ -123,6 +123,7 @@ pub fn edit_entire_signal(
.primary
.map
.get_turns_in_intersection(i)
.into_iter()
.any(|t| t.between_sidewalks());
let use_template = "use template";

View File

@ -114,11 +114,11 @@ pub fn debug(ctx: &EventCtx, app: &App, details: &mut Details, id: LaneID) -> Ve
));
}
if let Some(types) = l
.get_turn_restrictions(r)
.map(|types| types.collect::<Vec<_>>())
{
kv.push(("Turn restrictions".to_string(), format!("{:?}", types)));
if let Some(types) = l.get_turn_restrictions(r) {
kv.push((
"Turn restrictions".to_string(),
format!("{:?}", types.into_iter().collect::<Vec<_>>()),
));
}
for (restriction, to) in &r.turn_restrictions {
kv.push((

View File

@ -182,30 +182,21 @@ fn clip_trips(map: &Map, popdat: &PopDat, huge_map: &Map, timer: &mut Timer) ->
.all_outgoing_borders()
.into_iter()
.filter(|i| {
i.get_incoming_lanes(map, PathConstraints::Pedestrian)
.next()
.is_some()
!i.get_incoming_lanes(map, PathConstraints::Pedestrian)
.is_empty()
})
.map(|i| (i.id, i.polygon.center().to_gps(bounds)))
.collect();
let outgoing_borders_driving: Vec<(IntersectionID, LonLat)> = map
.all_outgoing_borders()
.into_iter()
.filter(|i| {
i.get_incoming_lanes(map, PathConstraints::Car)
.next()
.is_some()
})
.filter(|i| !i.get_incoming_lanes(map, PathConstraints::Car).is_empty())
.map(|i| (i.id, i.polygon.center().to_gps(bounds)))
.collect();
let outgoing_borders_biking: Vec<(IntersectionID, LonLat)> = map
.all_outgoing_borders()
.into_iter()
.filter(|i| {
i.get_incoming_lanes(map, PathConstraints::Bike)
.next()
.is_some()
})
.filter(|i| !i.get_incoming_lanes(map, PathConstraints::Bike).is_empty())
.map(|i| (i.id, i.polygon.center().to_gps(bounds)))
.collect();

View File

@ -115,8 +115,8 @@ fn make_route(
let last_stop_l = map.get_bs(*stops.last().unwrap()).driving_pos.lane();
if map.get_l(last_stop_l).dst_i == i.id {
end_border = Some(last_stop_l);
} else if let Some(l) = i.get_incoming_lanes(map, route_type).next() {
end_border = Some(l);
} else if let Some(l) = i.get_incoming_lanes(map, route_type).get(0) {
end_border = Some(*l);
} else {
// TODO Should panic
println!(

View File

@ -127,11 +127,11 @@ fn ensure_unique(turns: Vec<Turn>) -> Vec<Turn> {
}
fn is_turn_allowed(turn: &Turn, map: &Map) -> bool {
if let Some(mut types) = map
if let Some(types) = map
.get_l(turn.id.src)
.get_turn_restrictions(map.get_parent(turn.id.src))
{
types.any(|turn_type| turn_type == turn.turn_type)
types.contains(&turn.turn_type)
} else {
true
}

View File

@ -289,7 +289,7 @@ fn make_degenerate_crosswalks(
lanes: &Vec<Lane>,
r1: &Road,
r2: &Road,
) -> Option<impl Iterator<Item = Turn>> {
) -> Option<Vec<Turn>> {
let l1_in = get_sidewalk(lanes, r1.incoming_lanes(i))?;
let l1_out = get_sidewalk(lanes, r1.outgoing_lanes(i))?;
let l2_in = get_sidewalk(lanes, r2.incoming_lanes(i))?;
@ -343,7 +343,8 @@ fn make_degenerate_crosswalks(
.map(|mut t| {
t.other_crosswalk_ids.remove(&t.id);
t
}),
})
.collect(),
)
}

View File

@ -282,11 +282,12 @@ impl Map {
// All these helpers should take IDs and return objects.
pub fn get_turns_in_intersection<'a>(
&'a self,
id: IntersectionID,
) -> impl Iterator<Item = &'a Turn> + 'a {
self.get_i(id).turns.iter().map(move |t| self.get_t(*t))
pub fn get_turns_in_intersection(&self, id: IntersectionID) -> Vec<&Turn> {
self.get_i(id)
.turns
.iter()
.map(|t| self.get_t(*t))
.collect()
}
// The turns may belong to two different intersections!
@ -343,16 +344,17 @@ impl Map {
.cloned()
}
pub fn get_next_turns_and_lanes<'a>(
&'a self,
pub fn get_next_turns_and_lanes(
&self,
from: LaneID,
parent: IntersectionID,
) -> impl Iterator<Item = (&'a Turn, &'a Lane)> + 'a {
) -> Vec<(&Turn, &Lane)> {
self.get_i(parent)
.turns
.iter()
.filter(move |t| t.src == from)
.map(move |t| (self.get_t(*t), self.get_l(t.dst)))
.filter(|t| t.src == from)
.map(|t| (self.get_t(*t), self.get_l(t.dst)))
.collect()
}
pub fn get_turns_for(&self, from: LaneID, constraints: PathConstraints) -> Vec<&Turn> {
@ -374,16 +376,13 @@ impl Map {
turns
}
// These come back sorted
pub fn get_next_roads(&self, from: RoadID) -> impl Iterator<Item = RoadID> {
pub fn get_next_roads(&self, from: RoadID) -> BTreeSet<RoadID> {
let mut roads: BTreeSet<RoadID> = BTreeSet::new();
let r = self.get_r(from);
for id in vec![r.src_i, r.dst_i].into_iter() {
roads.extend(self.get_i(id).roads.clone());
}
roads.into_iter()
roads
}
pub fn get_parent(&self, id: LaneID) -> &Road {

View File

@ -85,15 +85,12 @@ impl Intersection {
self.roads.iter().all(|r| map.get_r(*r).is_private())
}
pub fn get_incoming_lanes<'a>(
&'a self,
map: &'a Map,
constraints: PathConstraints,
) -> impl Iterator<Item = LaneID> + 'a {
pub fn get_incoming_lanes(&self, map: &Map, constraints: PathConstraints) -> Vec<LaneID> {
self.incoming_lanes
.iter()
.filter(move |l| constraints.can_use(map.get_l(**l), map))
.cloned()
.collect()
}
// Strict for bikes. If there are bike lanes, not allowed to use other lanes.

View File

@ -228,10 +228,7 @@ impl Lane {
}
}
pub fn get_turn_restrictions<'a>(
&'a self,
road: &'a Road,
) -> Option<impl Iterator<Item = TurnType> + 'a> {
pub fn get_turn_restrictions(&self, road: &Road) -> Option<BTreeSet<TurnType>> {
if !self.is_driving() {
return None;
}
@ -268,27 +265,31 @@ impl Lane {
if part == "" {
return None;
}
Some(part.split(';').flat_map(|s| match s {
"left" | "left\\left" => vec![TurnType::Left],
"right" => vec![TurnType::Right],
// TODO What is blank supposed to mean? From few observed cases, same as through
"through" | "" => vec![TurnType::Straight],
// TODO Check this more carefully
"slight_right" | "slight right" | "merge_to_right" | "sharp_right" => {
vec![TurnType::Straight, TurnType::Right]
}
"slight_left" | "slight left" | "merge_to_left" | "sharp_left" => {
vec![TurnType::Straight, TurnType::Left]
}
"reverse" => {
// TODO We need TurnType::UTurn. Until then, u-turns usually show up as
// left turns.
vec![TurnType::Left]
}
s => {
warn!("Unknown turn restriction {}", s);
vec![]
}
}))
Some(
part.split(';')
.flat_map(|s| match s {
"left" | "left\\left" => vec![TurnType::Left],
"right" => vec![TurnType::Right],
// TODO What is blank supposed to mean? From few observed cases, same as through
"through" | "" => vec![TurnType::Straight],
// TODO Check this more carefully
"slight_right" | "slight right" | "merge_to_right" | "sharp_right" => {
vec![TurnType::Straight, TurnType::Right]
}
"slight_left" | "slight left" | "merge_to_left" | "sharp_left" => {
vec![TurnType::Straight, TurnType::Left]
}
"reverse" => {
// TODO We need TurnType::UTurn. Until then, u-turns usually show up as
// left turns.
vec![TurnType::Left]
}
s => {
warn!("Unknown turn restriction {}", s);
vec![]
}
})
.collect(),
)
}
}

View File

@ -157,6 +157,7 @@ impl ContractionHierarchyPathfinder {
// are actually connected by a turn.
let src_choices = i
.get_incoming_lanes(map, req.constraints)
.into_iter()
.filter(|l| zone.members.contains(&map.get_l(*l).parent))
.collect::<Vec<_>>();
let dst_choices = i
@ -240,6 +241,7 @@ impl ContractionHierarchyPathfinder {
// are actually connected by a turn.
let src_choices = i
.get_incoming_lanes(map, req.constraints)
.into_iter()
.filter(|l| !zone.members.contains(&map.get_l(*l).parent))
.collect::<Vec<_>>();
let dst_choices = i

View File

@ -472,9 +472,9 @@ impl SidewalkSpot {
map.get_i(i)
.get_incoming_lanes(map, PathConstraints::Pedestrian)
.next()
.get(0)
.map(|l| SidewalkSpot {
sidewalk_pos: Position::end(l, map),
sidewalk_pos: Position::end(*l, map),
connection: SidewalkPOI::Border(i, origin),
})
}
@ -487,10 +487,10 @@ impl SidewalkSpot {
if let Some(l) = map
.get_i(i)
.get_incoming_lanes(map, PathConstraints::Pedestrian)
.next()
.get(0)
{
return Some(SidewalkSpot {
sidewalk_pos: Position::end(l, map),
sidewalk_pos: Position::end(*l, map),
connection: SidewalkPOI::Border(i, destination),
});
}