mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 15:02:59 +03:00
Refactor constructors for RawRoad and RawIntersection. #893
This commit is contained in:
parent
8a23b347e5
commit
8244a900cf
@ -1,4 +1,4 @@
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
|
||||
use abstio::{CityName, MapName};
|
||||
@ -185,15 +185,9 @@ impl Model {
|
||||
|
||||
pub fn create_i(&mut self, ctx: &EventCtx, point: Pt2D) {
|
||||
let id = self.map.new_osm_node_id(time_to_id());
|
||||
self.map.intersections.insert(
|
||||
id,
|
||||
RawIntersection {
|
||||
point,
|
||||
intersection_type: IntersectionType::StopSign,
|
||||
elevation: Distance::ZERO,
|
||||
trim_roads_for_merging: BTreeMap::new(),
|
||||
},
|
||||
);
|
||||
self.map
|
||||
.intersections
|
||||
.insert(id, RawIntersection::new(point, IntersectionType::StopSign));
|
||||
self.intersection_added(ctx, id);
|
||||
}
|
||||
|
||||
@ -338,19 +332,13 @@ impl Model {
|
||||
|
||||
self.map.roads.insert(
|
||||
id,
|
||||
RawRoad {
|
||||
center_points: vec![
|
||||
RawRoad::new(
|
||||
vec![
|
||||
self.map.intersections[&i1].point,
|
||||
self.map.intersections[&i2].point,
|
||||
],
|
||||
scale_width: 1.0,
|
||||
osm_tags,
|
||||
turn_restrictions: Vec::new(),
|
||||
complicated_turn_restrictions: Vec::new(),
|
||||
percent_incline: 0.0,
|
||||
crosswalk_forward: true,
|
||||
crosswalk_backward: true,
|
||||
},
|
||||
),
|
||||
);
|
||||
self.road_added(ctx, id);
|
||||
|
||||
|
@ -109,21 +109,8 @@ pub fn extract_osm(
|
||||
way.tags.insert(osm::SIDEWALK, "right");
|
||||
}
|
||||
|
||||
out.roads.push((
|
||||
id,
|
||||
RawRoad {
|
||||
center_points: way.pts.clone(),
|
||||
scale_width: 1.0,
|
||||
osm_tags: way.tags.clone(),
|
||||
turn_restrictions: Vec::new(),
|
||||
complicated_turn_restrictions: Vec::new(),
|
||||
percent_incline: 0.0,
|
||||
// Start assuming there's a crosswalk everywhere, and maybe filter it down
|
||||
// later
|
||||
crosswalk_forward: true,
|
||||
crosswalk_backward: true,
|
||||
},
|
||||
));
|
||||
out.roads
|
||||
.push((id, RawRoad::new(way.pts.clone(), way.tags.clone())));
|
||||
continue;
|
||||
} else if way.tags.is(osm::HIGHWAY, "service") {
|
||||
// If we got here, is_road didn't interpret it as a normal road
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::collections::{hash_map::Entry, BTreeMap, HashMap, HashSet};
|
||||
use std::collections::{hash_map::Entry, HashMap, HashSet};
|
||||
|
||||
use abstutil::{Counter, Timer};
|
||||
use geom::{Distance, HashablePt2D, Pt2D};
|
||||
@ -61,32 +61,21 @@ pub fn split_up_roads(map: &mut RawMap, mut input: OsmExtract, timer: &mut Timer
|
||||
for (pt, id) in &pt_to_intersection {
|
||||
map.intersections.insert(
|
||||
*id,
|
||||
RawIntersection {
|
||||
point: pt.to_pt2d(),
|
||||
intersection_type: if input.traffic_signals.remove(pt).is_some() {
|
||||
RawIntersection::new(
|
||||
pt.to_pt2d(),
|
||||
if input.traffic_signals.remove(pt).is_some() {
|
||||
IntersectionType::TrafficSignal
|
||||
} else {
|
||||
IntersectionType::StopSign
|
||||
},
|
||||
// Filled out later
|
||||
elevation: Distance::ZERO,
|
||||
trim_roads_for_merging: BTreeMap::new(),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Set roundabouts to their center
|
||||
for (id, point) in roundabout_centers {
|
||||
map.intersections.insert(
|
||||
id,
|
||||
RawIntersection {
|
||||
point,
|
||||
intersection_type: IntersectionType::StopSign,
|
||||
// Filled out later
|
||||
elevation: Distance::ZERO,
|
||||
trim_roads_for_merging: BTreeMap::new(),
|
||||
},
|
||||
);
|
||||
map.intersections
|
||||
.insert(id, RawIntersection::new(point, IntersectionType::StopSign));
|
||||
}
|
||||
|
||||
let mut pt_to_road: HashMap<HashablePt2D, OriginalRoad> = HashMap::new();
|
||||
|
@ -381,6 +381,21 @@ pub struct RawRoad {
|
||||
}
|
||||
|
||||
impl RawRoad {
|
||||
pub fn new(osm_center_points: Vec<Pt2D>, osm_tags: Tags) -> Self {
|
||||
Self {
|
||||
center_points: osm_center_points,
|
||||
scale_width: 1.0,
|
||||
osm_tags,
|
||||
turn_restrictions: Vec::new(),
|
||||
complicated_turn_restrictions: Vec::new(),
|
||||
percent_incline: 0.0,
|
||||
// Start assuming there's a crosswalk everywhere, and maybe filter it down
|
||||
// later
|
||||
crosswalk_forward: true,
|
||||
crosswalk_backward: true,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO For the moment, treating all rail things as light rail
|
||||
pub fn is_light_rail(&self) -> bool {
|
||||
self.osm_tags.is_any("railway", vec!["light_rail", "rail"])
|
||||
@ -469,6 +484,16 @@ pub struct RawIntersection {
|
||||
}
|
||||
|
||||
impl RawIntersection {
|
||||
pub fn new(point: Pt2D, intersection_type: IntersectionType) -> Self {
|
||||
Self {
|
||||
point,
|
||||
intersection_type,
|
||||
// Filled out later
|
||||
elevation: Distance::ZERO,
|
||||
trim_roads_for_merging: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_border(&self) -> bool {
|
||||
self.intersection_type == IntersectionType::Border
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user