mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
force synthetic intersections into being border nodes too
This commit is contained in:
parent
4805892acd
commit
dbfd410b0a
@ -9,7 +9,7 @@ use crate::srtm::Elevation;
|
||||
use dimensioned::si;
|
||||
use geom::{GPSBounds, PolyLine, Pt2D};
|
||||
use kml::ExtraShapes;
|
||||
use map_model::{raw_data, FindClosest, LANE_THICKNESS};
|
||||
use map_model::{raw_data, FindClosest, IntersectionType, LANE_THICKNESS};
|
||||
use ordered_float::NotNaN;
|
||||
use std::path::Path;
|
||||
use structopt::StructOpt;
|
||||
@ -108,10 +108,10 @@ pub fn convert(flags: &Flags, timer: &mut abstutil::Timer) -> raw_data::Map {
|
||||
.unwrap();
|
||||
let dist = distance(closest_intersection);
|
||||
if dist <= MAX_METERS_BTWN_INTERSECTION_AND_SIGNAL {
|
||||
if closest_intersection.has_traffic_signal {
|
||||
if closest_intersection.intersection_type == IntersectionType::TrafficSignal {
|
||||
println!("WARNING: {:?} already has a traffic signal, but there's another one that's {} from it", closest_intersection, dist);
|
||||
}
|
||||
closest_intersection.has_traffic_signal = true;
|
||||
closest_intersection.intersection_type = IntersectionType::TrafficSignal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
use crate::srtm;
|
||||
use dimensioned::si;
|
||||
use geom::{HashablePt2D, LonLat};
|
||||
use map_model::raw_data;
|
||||
use map_model::{raw_data, IntersectionType};
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
|
||||
pub fn split_up_roads(input: &raw_data::Map, elevation: &srtm::Elevation) -> raw_data::Map {
|
||||
@ -36,7 +36,7 @@ pub fn split_up_roads(input: &raw_data::Map, elevation: &srtm::Elevation) -> raw
|
||||
map.intersections.push(raw_data::Intersection {
|
||||
point: LonLat::new(pt.x(), pt.y()),
|
||||
elevation: elevation.get(pt.x(), pt.y()) * si::M,
|
||||
has_traffic_signal: false,
|
||||
intersection_type: IntersectionType::StopSign,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
"x": 375.2584876887879,
|
||||
"y": 394.4733648122756
|
||||
},
|
||||
"has_traffic_signal": false
|
||||
"intersection_type": "StopSign"
|
||||
}
|
||||
],
|
||||
[
|
||||
@ -18,7 +18,7 @@
|
||||
"x": 426.5473937988281,
|
||||
"y": 394.67230224609377
|
||||
},
|
||||
"has_traffic_signal": true
|
||||
"intersection_type": "TrafficSignal"
|
||||
}
|
||||
],
|
||||
[
|
||||
@ -28,7 +28,7 @@
|
||||
"x": 426.9548681897562,
|
||||
"y": 338.6898394428313
|
||||
},
|
||||
"has_traffic_signal": false
|
||||
"intersection_type": "StopSign"
|
||||
}
|
||||
],
|
||||
[
|
||||
@ -38,7 +38,7 @@
|
||||
"x": 481.2515387041076,
|
||||
"y": 338.6877104503858
|
||||
},
|
||||
"has_traffic_signal": false
|
||||
"intersection_type": "StopSign"
|
||||
}
|
||||
],
|
||||
[
|
||||
@ -48,7 +48,7 @@
|
||||
"x": 426.9279815253348,
|
||||
"y": 456.09920803179929
|
||||
},
|
||||
"has_traffic_signal": false
|
||||
"intersection_type": "Border"
|
||||
}
|
||||
],
|
||||
[
|
||||
@ -58,7 +58,7 @@
|
||||
"x": 427.35826112518097,
|
||||
"y": 285.7304272008598
|
||||
},
|
||||
"has_traffic_signal": false
|
||||
"intersection_type": "StopSign"
|
||||
}
|
||||
]
|
||||
],
|
||||
|
@ -8,7 +8,7 @@
|
||||
"x": 288.5454406738281,
|
||||
"y": 486.2385864257813
|
||||
},
|
||||
"has_traffic_signal": false
|
||||
"intersection_type": "StopSign"
|
||||
}
|
||||
],
|
||||
[
|
||||
@ -18,7 +18,7 @@
|
||||
"x": 512.0357055664063,
|
||||
"y": 486.63079833984377
|
||||
},
|
||||
"has_traffic_signal": false
|
||||
"intersection_type": "StopSign"
|
||||
}
|
||||
]
|
||||
],
|
||||
@ -70,4 +70,4 @@
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -108,11 +108,7 @@ impl Map {
|
||||
turns: Vec::new(),
|
||||
elevation: i.elevation,
|
||||
// Might change later
|
||||
intersection_type: if i.has_traffic_signal {
|
||||
IntersectionType::TrafficSignal
|
||||
} else {
|
||||
IntersectionType::StopSign
|
||||
},
|
||||
intersection_type: i.intersection_type,
|
||||
incoming_lanes: Vec::new(),
|
||||
outgoing_lanes: Vec::new(),
|
||||
roads: BTreeSet::new(),
|
||||
@ -677,6 +673,16 @@ impl Map {
|
||||
}
|
||||
|
||||
fn is_border(intersection: &Intersection, map: &Map) -> bool {
|
||||
// Raw data said it is.
|
||||
if intersection.intersection_type == IntersectionType::Border {
|
||||
if !intersection.is_dead_end() {
|
||||
panic!(
|
||||
"{:?} isn't a dead-end, but raw data said it's a border node",
|
||||
intersection
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Bias for driving
|
||||
if !intersection.is_dead_end() {
|
||||
return false;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::AreaType;
|
||||
use crate::{AreaType, IntersectionType};
|
||||
use dimensioned::si;
|
||||
use geom::{GPSBounds, LonLat};
|
||||
use gtfs::Route;
|
||||
@ -86,7 +86,8 @@ impl Road {
|
||||
pub struct Intersection {
|
||||
pub point: LonLat,
|
||||
pub elevation: si::Meter<f64>,
|
||||
pub has_traffic_signal: bool,
|
||||
// A raw Intersection can be forced into being a Border.
|
||||
pub intersection_type: IntersectionType,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
||||
|
@ -312,15 +312,11 @@ impl Car {
|
||||
// turn.
|
||||
// But if we stop right at the end of a lane, we want to stay there and not enter the
|
||||
// intersection.
|
||||
if leftover_dist <= EPSILON_DIST {
|
||||
if self.on.maybe_lane().is_some() {
|
||||
// But do force them to be right at the end of the lane, otherwise we're in
|
||||
// this bizarre, illegal state where dist_along is > the current Traversable's
|
||||
// length.
|
||||
self.dist_along = self.on.length(map);
|
||||
break;
|
||||
}
|
||||
// Otherwise finish the turn.
|
||||
if leftover_dist <= EPSILON_DIST && self.on.maybe_lane().is_some() {
|
||||
// But do force them to be right at the end of the lane, otherwise we're in this
|
||||
// bizarre, illegal state where dist_along is > the current Traversable's length.
|
||||
self.dist_along = self.on.length(map);
|
||||
break;
|
||||
}
|
||||
|
||||
if let Traversable::Turn(t) = self.on {
|
||||
|
@ -153,7 +153,7 @@ impl IntersectionSimState {
|
||||
println!("{}", abstutil::to_json(map.get_traffic_signal(id)));
|
||||
}
|
||||
IntersectionPolicy::Border => {
|
||||
println!("{} is a border", id);
|
||||
println!("{} has no IntersectionPolicy since it's a border", id);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use abstutil::{deserialize_btreemap, serialize_btreemap, write_json};
|
||||
use dimensioned::si;
|
||||
use ezgui::{Canvas, Color, GfxCtx, Text};
|
||||
use geom::{Circle, LonLat, PolyLine, Polygon, Pt2D};
|
||||
use map_model::{raw_data, LaneType, RoadSpec, LANE_THICKNESS};
|
||||
use map_model::{raw_data, IntersectionType, LaneType, RoadSpec, LANE_THICKNESS};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use std::mem;
|
||||
@ -44,7 +44,7 @@ pub struct Model {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Intersection {
|
||||
center: Pt2D,
|
||||
has_traffic_signal: bool,
|
||||
intersection_type: IntersectionType,
|
||||
}
|
||||
|
||||
impl Intersection {
|
||||
@ -192,10 +192,12 @@ impl Model {
|
||||
for (id, i) in &self.intersections {
|
||||
let color = if Some(*id) == current_i {
|
||||
HIGHLIGHT_COLOR
|
||||
} else if i.has_traffic_signal {
|
||||
Color::GREEN
|
||||
} else {
|
||||
Color::RED
|
||||
match i.intersection_type {
|
||||
IntersectionType::TrafficSignal => Color::GREEN,
|
||||
IntersectionType::StopSign => Color::RED,
|
||||
IntersectionType::Border => Color::BLUE,
|
||||
}
|
||||
};
|
||||
g.draw_circle(color, &i.circle());
|
||||
}
|
||||
@ -258,7 +260,7 @@ impl Model {
|
||||
map.intersections.push(raw_data::Intersection {
|
||||
point: pt(i.center),
|
||||
elevation: 0.0 * si::M,
|
||||
has_traffic_signal: i.has_traffic_signal,
|
||||
intersection_type: i.intersection_type,
|
||||
});
|
||||
}
|
||||
|
||||
@ -291,7 +293,7 @@ impl Model {
|
||||
id,
|
||||
Intersection {
|
||||
center,
|
||||
has_traffic_signal: false,
|
||||
intersection_type: IntersectionType::StopSign,
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -302,7 +304,22 @@ impl Model {
|
||||
|
||||
pub fn toggle_i_type(&mut self, id: IntersectionID) {
|
||||
let i = self.intersections.get_mut(&id).unwrap();
|
||||
i.has_traffic_signal = !i.has_traffic_signal;
|
||||
i.intersection_type = match i.intersection_type {
|
||||
IntersectionType::StopSign => IntersectionType::TrafficSignal,
|
||||
IntersectionType::TrafficSignal => {
|
||||
let num_roads = self
|
||||
.roads
|
||||
.values()
|
||||
.filter(|r| r.i1 == id || r.i2 == id)
|
||||
.count();
|
||||
if num_roads == 1 {
|
||||
IntersectionType::Border
|
||||
} else {
|
||||
IntersectionType::StopSign
|
||||
}
|
||||
}
|
||||
IntersectionType::Border => IntersectionType::StopSign,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn remove_i(&mut self, id: IntersectionID) {
|
||||
|
Loading…
Reference in New Issue
Block a user