mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
dont make u-turns unless really at a dead-end
This commit is contained in:
parent
3fa06fd032
commit
b6a9e2e1a4
@ -3,7 +3,8 @@
|
||||
use dimensioned::si;
|
||||
use geom::Pt2D;
|
||||
use std::fmt;
|
||||
use {LaneID, TurnID};
|
||||
use {LaneID, TurnID, RoadID, Map};
|
||||
use std::collections::HashSet;
|
||||
|
||||
// TODO reconsider pub usize. maybe outside world shouldnt know.
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
@ -33,3 +34,13 @@ impl PartialEq for Intersection {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl Intersection {
|
||||
pub fn is_dead_end(&self, map: &Map) -> bool {
|
||||
let mut roads: HashSet<RoadID> = HashSet::new();
|
||||
for l in self.incoming_lanes.iter().chain(self.outgoing_lanes.iter()) {
|
||||
roads.insert(map.get_l(*l).parent);
|
||||
}
|
||||
roads.len() == 1
|
||||
}
|
||||
}
|
||||
|
@ -107,20 +107,19 @@ fn make_turns(
|
||||
assert_eq!(map.get_l(*l).src_i, parent);
|
||||
}
|
||||
|
||||
let dead_end = incoming.len() == 1 && outgoing.len() == 1;
|
||||
let dead_end = map.get_i(parent).is_dead_end(map);
|
||||
|
||||
let mut result = Vec::new();
|
||||
for src in incoming {
|
||||
let src_l = map.get_l(*src);
|
||||
let other_side = map.get_r(src_l.parent)
|
||||
.get_opposite_lane(src_l.id, src_l.lane_type);
|
||||
|
||||
for dst in outgoing {
|
||||
let dst_l = map.get_l(*dst);
|
||||
// Don't create U-turns unless it's a dead-end
|
||||
if other_side == Some(dst_l.id) && !dead_end {
|
||||
if src_l.parent == dst_l.parent && !dead_end {
|
||||
continue;
|
||||
}
|
||||
// TODO if it's a multi-lane dead-end, ideally match up lanes or something
|
||||
|
||||
result.push(Turn {
|
||||
id: TurnID::new(*src, *dst),
|
||||
|
Loading…
Reference in New Issue
Block a user