mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 12:12:00 +03:00
easier queries for lane type
This commit is contained in:
parent
f6a302efb9
commit
d3611c6084
@ -62,9 +62,7 @@ impl DrawLane {
|
||||
markings.push(m);
|
||||
}
|
||||
// TODO not all sides of the lane have to stop
|
||||
if lane.lane_type == map_model::LaneType::Driving
|
||||
&& !map.get_i(lane.dst_i).has_traffic_signal
|
||||
{
|
||||
if lane.is_driving() && !map.get_i(lane.dst_i).has_traffic_signal {
|
||||
if let Some(m) = calculate_stop_sign_line(lane) {
|
||||
markings.push(m);
|
||||
}
|
||||
@ -280,7 +278,7 @@ fn calculate_stop_sign_line(lane: &map_model::Lane) -> Option<Marking> {
|
||||
}
|
||||
|
||||
fn calculate_id_positions(lane: &map_model::Lane) -> Option<Vec<Pt2D>> {
|
||||
if lane.lane_type != map_model::LaneType::Driving {
|
||||
if !lane.is_driving() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -523,11 +523,11 @@ impl gui::GUI for UI {
|
||||
return gui::EventLoopMode::InputOnly;
|
||||
}
|
||||
|
||||
if self.map.get_l(id).lane_type == map_model::LaneType::Sidewalk {
|
||||
if input.key_pressed(Key::A, "spawn a pedestrian here") {
|
||||
self.sim_ctrl.sim.spawn_pedestrian(&self.map, id);
|
||||
return gui::EventLoopMode::InputOnly;
|
||||
}
|
||||
if self.map.get_l(id).is_sidewalk()
|
||||
&& input.key_pressed(Key::A, "spawn a pedestrian here")
|
||||
{
|
||||
self.sim_ctrl.sim.spawn_pedestrian(&self.map, id);
|
||||
return gui::EventLoopMode::InputOnly;
|
||||
}
|
||||
}
|
||||
SelectionState::SelectedIntersection(id) => {
|
||||
|
@ -61,7 +61,7 @@ impl RoadEdit {
|
||||
lane: &Lane,
|
||||
new_type: LaneType,
|
||||
) -> Option<RoadEdit> {
|
||||
if lane.lane_type == LaneType::Sidewalk {
|
||||
if lane.is_sidewalk() {
|
||||
println!("Sidewalks are fixed; can't change their type");
|
||||
return None;
|
||||
}
|
||||
@ -98,7 +98,7 @@ impl RoadEdit {
|
||||
|
||||
fn delete_lane(r: &Road, lane: &Lane) -> Option<RoadEdit> {
|
||||
// Sidewalks are fixed
|
||||
if lane.lane_type == LaneType::Sidewalk {
|
||||
if lane.is_sidewalk() {
|
||||
println!("Can't delete sidewalks");
|
||||
return None;
|
||||
}
|
||||
|
@ -125,4 +125,20 @@ impl Lane {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_driving(&self) -> bool {
|
||||
self.lane_type == LaneType::Driving
|
||||
}
|
||||
|
||||
pub fn is_biking(&self) -> bool {
|
||||
self.lane_type == LaneType::Biking
|
||||
}
|
||||
|
||||
pub fn is_sidewalk(&self) -> bool {
|
||||
self.lane_type == LaneType::Sidewalk
|
||||
}
|
||||
|
||||
pub fn is_parking(&self) -> bool {
|
||||
self.lane_type == LaneType::Parking
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use geometry;
|
||||
use ordered_float::NotNaN;
|
||||
use raw_data;
|
||||
use std::collections::BTreeMap;
|
||||
use {Building, BuildingID, Lane, LaneID, LaneType, Road};
|
||||
use {Building, BuildingID, Lane, LaneID, Road};
|
||||
|
||||
pub(crate) fn make_building(
|
||||
b: &raw_data::Building,
|
||||
@ -47,9 +47,7 @@ fn find_front_path(
|
||||
let candidates: Vec<(LaneID, geo::Point<f64>)> = lanes
|
||||
.iter()
|
||||
.filter_map(|l| {
|
||||
if l.lane_type == LaneType::Sidewalk
|
||||
&& roads[l.parent.0].osm_tags.get("name") == Some(street_name)
|
||||
{
|
||||
if l.is_sidewalk() && roads[l.parent.0].osm_tags.get("name") == Some(street_name) {
|
||||
if let geo::Closest::SinglePoint(pt) =
|
||||
lane_to_line_string(&lanes[l.id.0]).closest_point(¢er_pt)
|
||||
{
|
||||
|
@ -26,12 +26,12 @@ fn make_driving_turns(i: &Intersection, m: &Map) -> Vec<Turn> {
|
||||
let incoming: Vec<LaneID> = i.incoming_lanes
|
||||
.iter()
|
||||
// TODO why's this double borrow happen?
|
||||
.filter(|id| m.get_l(**id).lane_type == LaneType::Driving)
|
||||
.filter(|id| m.get_l(**id).is_driving())
|
||||
.map(|id| *id)
|
||||
.collect();
|
||||
let outgoing: Vec<LaneID> = i.outgoing_lanes
|
||||
.iter()
|
||||
.filter(|id| m.get_l(**id).lane_type == LaneType::Driving)
|
||||
.filter(|id| m.get_l(**id).is_driving())
|
||||
.map(|id| *id)
|
||||
.collect();
|
||||
|
||||
@ -95,10 +95,7 @@ fn make_biking_turns(i: &Intersection, m: &Map) -> Vec<Turn> {
|
||||
// will create those, and duplicates are bad. Filter them out here.
|
||||
make_turns(m, i.id, &incoming, &outgoing)
|
||||
.into_iter()
|
||||
.filter(|t| {
|
||||
m.get_l(t.src).lane_type == LaneType::Biking
|
||||
|| m.get_l(t.dst).lane_type == LaneType::Biking
|
||||
})
|
||||
.filter(|t| m.get_l(t.src).is_biking() || m.get_l(t.dst).is_biking())
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ impl Map {
|
||||
.filter(|t| t.src == l)
|
||||
.collect();
|
||||
// Sidewalks are bidirectional
|
||||
if lane.lane_type == LaneType::Sidewalk {
|
||||
if lane.is_sidewalk() {
|
||||
for t in &self.get_i(lane.src_i).turns {
|
||||
let turn = self.get_t(*t);
|
||||
if turn.src == l {
|
||||
|
@ -195,13 +195,7 @@ impl Sim {
|
||||
|
||||
let driving_lanes: Vec<LaneID> = map.all_lanes()
|
||||
.iter()
|
||||
.filter_map(|l| {
|
||||
if l.lane_type == LaneType::Driving {
|
||||
Some(l.id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter_map(|l| if l.is_driving() { Some(l.id) } else { None })
|
||||
.collect();
|
||||
let mut requested_paths: Vec<(CarID, LaneID, LaneID)> = Vec::new();
|
||||
for i in 0..num_cars.min(cars_and_starts.len()) {
|
||||
@ -273,7 +267,7 @@ impl Sim {
|
||||
}
|
||||
|
||||
pub fn spawn_pedestrian(&mut self, map: &Map, sidewalk: LaneID) -> bool {
|
||||
assert!(map.get_l(sidewalk).lane_type == LaneType::Sidewalk);
|
||||
assert!(map.get_l(sidewalk).is_sidewalk());
|
||||
|
||||
if let Some(path) = pick_goal_and_find_path(&mut self.rng, map, sidewalk) {
|
||||
self.walking_state
|
||||
@ -290,7 +284,7 @@ impl Sim {
|
||||
|
||||
let mut sidewalks: Vec<LaneID> = Vec::new();
|
||||
for l in map.all_lanes() {
|
||||
if l.lane_type == LaneType::Sidewalk {
|
||||
if l.is_sidewalk() {
|
||||
sidewalks.push(l.id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user