mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 12:12:00 +03:00
splitting out a mapmaking fxn
This commit is contained in:
parent
6afb71ea5f
commit
2451244344
@ -107,6 +107,9 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s
|
||||
any point, by the magic of easy serialization.
|
||||
- get rid of the protobuf
|
||||
|
||||
- line trimming
|
||||
- just replacing the last pt might not always work. especially with old center lines!
|
||||
|
||||
|
||||
- an mvp release could just be producing high-quality, reusable geometry for seattle
|
||||
- with an editor to quickly fiddle with where sidewalks/different lanes are
|
||||
|
@ -135,48 +135,8 @@ impl Map {
|
||||
}
|
||||
|
||||
for i in &m.intersections {
|
||||
let incoming: Vec<RoadID> = i.incoming_roads
|
||||
.iter()
|
||||
.filter(|id| m.roads[id.0].lane_type == LaneType::Driving)
|
||||
.map(|id| *id)
|
||||
.collect();
|
||||
let outgoing: Vec<RoadID> = i.outgoing_roads
|
||||
.iter()
|
||||
.filter(|id| m.roads[id.0].lane_type == LaneType::Driving)
|
||||
.map(|id| *id)
|
||||
.collect();
|
||||
|
||||
// TODO: Figure out why this happens in the huge map
|
||||
if incoming.is_empty() {
|
||||
println!("WARNING: intersection {:?} has no incoming roads", i);
|
||||
continue;
|
||||
}
|
||||
if outgoing.is_empty() {
|
||||
println!("WARNING: intersection {:?} has no outgoing roads", i);
|
||||
continue;
|
||||
}
|
||||
let dead_end = incoming.len() == 1 && outgoing.len() == 1;
|
||||
|
||||
for src in &incoming {
|
||||
let src_r = &m.roads[src.0];
|
||||
for dst in &outgoing {
|
||||
let dst_r = &m.roads[dst.0];
|
||||
// Don't create U-turns unless it's a dead-end
|
||||
if src_r.other_side == Some(dst_r.id) && !dead_end {
|
||||
continue;
|
||||
}
|
||||
|
||||
let id = TurnID(m.turns.len());
|
||||
m.turns.push(Turn {
|
||||
id,
|
||||
parent: i.id,
|
||||
src: *src,
|
||||
dst: *dst,
|
||||
src_pt: src_r.last_pt(),
|
||||
dst_pt: dst_r.first_pt(),
|
||||
});
|
||||
}
|
||||
}
|
||||
let turns = make_turns(i, &m);
|
||||
m.turns.extend(turns);
|
||||
}
|
||||
for t in &m.turns {
|
||||
m.intersections[t.parent.0].turns.push(t.id);
|
||||
@ -293,3 +253,51 @@ impl Map {
|
||||
self.bounds.clone()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO organize these differently
|
||||
fn make_turns(i: &Intersection, m: &Map) -> Vec<Turn> {
|
||||
let incoming: Vec<RoadID> = i.incoming_roads
|
||||
.iter()
|
||||
.filter(|id| m.roads[id.0].lane_type == LaneType::Driving)
|
||||
.map(|id| *id)
|
||||
.collect();
|
||||
let outgoing: Vec<RoadID> = i.outgoing_roads
|
||||
.iter()
|
||||
.filter(|id| m.roads[id.0].lane_type == LaneType::Driving)
|
||||
.map(|id| *id)
|
||||
.collect();
|
||||
|
||||
// TODO: Figure out why this happens in the huge map
|
||||
if incoming.is_empty() {
|
||||
println!("WARNING: intersection {:?} has no incoming roads", i);
|
||||
return Vec::new();
|
||||
}
|
||||
if outgoing.is_empty() {
|
||||
println!("WARNING: intersection {:?} has no outgoing roads", i);
|
||||
return Vec::new();
|
||||
}
|
||||
let dead_end = incoming.len() == 1 && outgoing.len() == 1;
|
||||
|
||||
let mut result = Vec::new();
|
||||
for src in &incoming {
|
||||
let src_r = &m.roads[src.0];
|
||||
for dst in &outgoing {
|
||||
let dst_r = &m.roads[dst.0];
|
||||
// Don't create U-turns unless it's a dead-end
|
||||
if src_r.other_side == Some(dst_r.id) && !dead_end {
|
||||
continue;
|
||||
}
|
||||
|
||||
let id = TurnID(m.turns.len());
|
||||
result.push(Turn {
|
||||
id,
|
||||
parent: i.id,
|
||||
src: *src,
|
||||
dst: *dst,
|
||||
src_pt: src_r.last_pt(),
|
||||
dst_pt: dst_r.first_pt(),
|
||||
});
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user