mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
clippy pt2
This commit is contained in:
parent
ab86835611
commit
f48757c5e7
@ -5,6 +5,7 @@ touch `find * | grep '\.rs' | grep -v target | xargs`
|
|||||||
|
|
||||||
# TODO Remove all of these exceptions
|
# TODO Remove all of these exceptions
|
||||||
cargo clippy -- \
|
cargo clippy -- \
|
||||||
|
-A clippy::cyclomatic_complexity \
|
||||||
-A clippy::expect_fun_call \
|
-A clippy::expect_fun_call \
|
||||||
-A clippy::if_same_then_else \
|
-A clippy::if_same_then_else \
|
||||||
-A clippy::needless_pass_by_value \
|
-A clippy::needless_pass_by_value \
|
||||||
@ -13,4 +14,6 @@ cargo clippy -- \
|
|||||||
-A clippy::new_without_default_derive \
|
-A clippy::new_without_default_derive \
|
||||||
-A clippy::ptr_arg \
|
-A clippy::ptr_arg \
|
||||||
-A clippy::suspicious_arithmetic_impl \
|
-A clippy::suspicious_arithmetic_impl \
|
||||||
-A clippy::type_complexity
|
-A clippy::too_many_arguments \
|
||||||
|
-A clippy::type_complexity \
|
||||||
|
-A clippy::wrong_self_convention
|
||||||
|
@ -53,7 +53,7 @@ fn convert_polygon(input: PolygonType, name: String, map_name: String, gps_bound
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
NeighborhoodBuilder {
|
NeighborhoodBuilder {
|
||||||
map_name: map_name,
|
map_name,
|
||||||
name,
|
name,
|
||||||
points,
|
points,
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ fn panel(ctx: &mut PluginCtx) -> State {
|
|||||||
// TODO More coloring
|
// TODO More coloring
|
||||||
txt.add_line(ctx.primary.sim.get_name().to_string());
|
txt.add_line(ctx.primary.sim.get_name().to_string());
|
||||||
summarize(&mut txt, ctx.primary.sim.get_score());
|
summarize(&mut txt, ctx.primary.sim.get_score());
|
||||||
txt.add_line("".to_string());
|
txt.add_line(String::new());
|
||||||
txt.add_line(s.sim.get_name().to_string());
|
txt.add_line(s.sim.get_name().to_string());
|
||||||
summarize(&mut txt, s.sim.get_score());
|
summarize(&mut txt, s.sim.get_score());
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,13 +81,11 @@ impl Plugin for TimeTravel {
|
|||||||
} else if ctx.input.key_pressed(Key::Return, "exit time traveler") {
|
} else if ctx.input.key_pressed(Key::Return, "exit time traveler") {
|
||||||
self.current_tick = None;
|
self.current_tick = None;
|
||||||
}
|
}
|
||||||
} else {
|
} else if ctx
|
||||||
if ctx
|
.input
|
||||||
.input
|
.unimportant_key_pressed(Key::T, SIM, "start time traveling")
|
||||||
.unimportant_key_pressed(Key::T, SIM, "start time traveling")
|
{
|
||||||
{
|
self.current_tick = Some(ctx.primary.sim.time);
|
||||||
self.current_tick = Some(ctx.primary.sim.time);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(tick) = self.current_tick {
|
if let Some(tick) = self.current_tick {
|
||||||
|
@ -123,7 +123,7 @@ impl<'a> GfxCtx<'a> {
|
|||||||
pub fn draw_polygon(&mut self, color: Color, poly: &geom::Polygon) {
|
pub fn draw_polygon(&mut self, color: Color, poly: &geom::Polygon) {
|
||||||
for tri in &poly.triangles {
|
for tri in &poly.triangles {
|
||||||
graphics::Polygon::new(color.0).draw(
|
graphics::Polygon::new(color.0).draw(
|
||||||
&vec![
|
&[
|
||||||
[tri.pt1.x(), tri.pt1.y()],
|
[tri.pt1.x(), tri.pt1.y()],
|
||||||
[tri.pt2.x(), tri.pt2.y()],
|
[tri.pt2.x(), tri.pt2.y()],
|
||||||
[tri.pt3.x(), tri.pt3.y()],
|
[tri.pt3.x(), tri.pt3.y()],
|
||||||
|
@ -87,7 +87,7 @@ impl Text {
|
|||||||
.iter()
|
.iter()
|
||||||
.max_by_key(|l| l.iter().fold(0, |so_far, span| so_far + span.text.len()))
|
.max_by_key(|l| l.iter().fold(0, |so_far, span| so_far + span.text.len()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut concat = String::from("");
|
let mut concat = String::new();
|
||||||
for span in longest_line {
|
for span in longest_line {
|
||||||
concat.push_str(&span.text);
|
concat.push_str(&span.text);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ impl TextBox {
|
|||||||
pub fn new(prompt: &str, prefilled: Option<String>) -> TextBox {
|
pub fn new(prompt: &str, prefilled: Option<String>) -> TextBox {
|
||||||
TextBox {
|
TextBox {
|
||||||
prompt: prompt.to_string(),
|
prompt: prompt.to_string(),
|
||||||
line: prefilled.unwrap_or(String::from("")),
|
line: prefilled.unwrap_or_else(String::new),
|
||||||
cursor_x: 0,
|
cursor_x: 0,
|
||||||
shift_pressed: false,
|
shift_pressed: false,
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ impl TreeMenu {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let parts: Vec<&str> = path.split("/").collect();
|
let parts: Vec<&str> = path.split('/').collect();
|
||||||
populate_tree(VecDeque::from(parts), &mut self.root, hotkey, action);
|
populate_tree(VecDeque::from(parts), &mut self.root, hotkey, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,10 +43,10 @@ fn print(depth: usize, tree: &BTreeMap<String, Item>, f: &mut fmt::Formatter) ->
|
|||||||
for (name, item) in tree {
|
for (name, item) in tree {
|
||||||
match item {
|
match item {
|
||||||
Item::Action(key) => {
|
Item::Action(key) => {
|
||||||
writeln!(f, "{}- {} ({})", pad, name, describe_maybe_key(key))?;
|
writeln!(f, "{}- {} ({})", pad, name, describe_maybe_key(*key))?;
|
||||||
}
|
}
|
||||||
Item::Tree(key, subtree) => {
|
Item::Tree(key, subtree) => {
|
||||||
writeln!(f, "{}- {} ({})", pad, name, describe_maybe_key(key))?;
|
writeln!(f, "{}- {} ({})", pad, name, describe_maybe_key(*key))?;
|
||||||
print(depth + 1, subtree, f)?;
|
print(depth + 1, subtree, f)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,10 +54,10 @@ fn print(depth: usize, tree: &BTreeMap<String, Item>, f: &mut fmt::Formatter) ->
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn describe_maybe_key(key: &Option<Key>) -> String {
|
fn describe_maybe_key(key: Option<Key>) -> String {
|
||||||
match key {
|
match key {
|
||||||
Some(k) => describe_key(*k),
|
Some(k) => describe_key(k),
|
||||||
None => "".to_string(),
|
None => String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +131,11 @@ impl<'a> WrappedWizard<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn input_string(&mut self, query: &str) -> Option<String> {
|
pub fn input_string(&mut self, query: &str) -> Option<String> {
|
||||||
self.input_something(query, None, Box::new(|line| Some(line)))
|
self.input_something(query, None, Box::new(Some))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn input_string_prefilled(&mut self, query: &str, prefilled: String) -> Option<String> {
|
pub fn input_string_prefilled(&mut self, query: &str, prefilled: String) -> Option<String> {
|
||||||
self.input_something(query, Some(prefilled), Box::new(|line| Some(line)))
|
self.input_something(query, Some(prefilled), Box::new(Some))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn input_usize(&mut self, query: &str) -> Option<usize> {
|
pub fn input_usize(&mut self, query: &str) -> Option<usize> {
|
||||||
|
@ -165,7 +165,7 @@ impl PolyLine {
|
|||||||
let l2 = Line::new(pt2_raw, pt3_raw).shift(width);
|
let l2 = Line::new(pt2_raw, pt3_raw).shift(width);
|
||||||
// When the lines are perfectly parallel, it means pt2_shift_1st == pt2_shift_2nd and the
|
// When the lines are perfectly parallel, it means pt2_shift_1st == pt2_shift_2nd and the
|
||||||
// original geometry is redundant.
|
// original geometry is redundant.
|
||||||
let pt2_shift = line_intersection(&l1, &l2).unwrap_or(l1.pt2());
|
let pt2_shift = line_intersection(&l1, &l2).unwrap_or_else(|| l1.pt2());
|
||||||
|
|
||||||
if pt3_idx == 2 {
|
if pt3_idx == 2 {
|
||||||
result.push(l1.pt1());
|
result.push(l1.pt1());
|
||||||
@ -226,7 +226,7 @@ impl PolyLine {
|
|||||||
let l2 = Line::new(pt2_raw, pt3_raw).shift(width);
|
let l2 = Line::new(pt2_raw, pt3_raw).shift(width);
|
||||||
// When the lines are perfectly parallel, it means pt2_shift_1st == pt2_shift_2nd and the
|
// When the lines are perfectly parallel, it means pt2_shift_1st == pt2_shift_2nd and the
|
||||||
// original geometry is redundant.
|
// original geometry is redundant.
|
||||||
let pt2_shift = line_intersection(&l1, &l2).unwrap_or(l1.pt2());
|
let pt2_shift = line_intersection(&l1, &l2).unwrap_or_else(|| l1.pt2());
|
||||||
|
|
||||||
if pt3_idx == 2 {
|
if pt3_idx == 2 {
|
||||||
result.push(l1.pt1());
|
result.push(l1.pt1());
|
||||||
|
@ -58,7 +58,7 @@ impl Intersection {
|
|||||||
self.incoming_lanes
|
self.incoming_lanes
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|l| map.get_l(**l).lane_type == lt)
|
.filter(|l| map.get_l(**l).lane_type == lt)
|
||||||
.map(|l| *l)
|
.cloned()
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ impl Intersection {
|
|||||||
self.outgoing_lanes
|
self.outgoing_lanes
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|l| map.get_l(**l).lane_type == lt)
|
.filter(|l| map.get_l(**l).lane_type == lt)
|
||||||
.map(|l| *l)
|
.cloned()
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ pub fn make_all_buildings(
|
|||||||
osm_way_id: input[idx].osm_way_id,
|
osm_way_id: input[idx].osm_way_id,
|
||||||
front_path: FrontPath {
|
front_path: FrontPath {
|
||||||
bldg: id,
|
bldg: id,
|
||||||
sidewalk: sidewalk_pos.clone(),
|
sidewalk: *sidewalk_pos,
|
||||||
line,
|
line,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -76,7 +76,7 @@ pub fn make_bus_stops(
|
|||||||
let stops: Vec<BusStopID> = stop_points
|
let stops: Vec<BusStopID> = stop_points
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|pt| point_to_stop_id.get(pt))
|
.filter_map(|pt| point_to_stop_id.get(pt))
|
||||||
.map(|stop| *stop)
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
if stops.len() < 2 {
|
if stops.len() < 2 {
|
||||||
warn!(
|
warn!(
|
||||||
|
@ -143,7 +143,6 @@ pub fn intersection_polygon(i: &Intersection, roads: &Vec<Road>) -> Vec<Pt2D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close off the polygon
|
// Close off the polygon
|
||||||
let first_pt = endpoints[0].clone();
|
endpoints.push(endpoints[0]);
|
||||||
endpoints.push(first_pt);
|
|
||||||
endpoints
|
endpoints
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ pub fn find_sidewalk_points(
|
|||||||
timer.next();
|
timer.next();
|
||||||
if let Some((sidewalk, sidewalk_pt)) = closest.closest_pt(query_pt.into(), max_dist_away) {
|
if let Some((sidewalk, sidewalk_pt)) = closest.closest_pt(query_pt.into(), max_dist_away) {
|
||||||
if let Some(dist_along) = lanes[sidewalk.0].dist_along_of_point(sidewalk_pt) {
|
if let Some(dist_along) = lanes[sidewalk.0].dist_along_of_point(sidewalk_pt) {
|
||||||
results.insert(query_pt.into(), Position::new(sidewalk, dist_along));
|
results.insert(query_pt, Position::new(sidewalk, dist_along));
|
||||||
} else {
|
} else {
|
||||||
panic!("{} isn't on {} according to dist_along_of_point, even though closest_point thinks it is.\n{}", sidewalk_pt, sidewalk, lanes[sidewalk.0].lane_center_pts);
|
panic!("{} isn't on {} according to dist_along_of_point, even though closest_point thinks it is.\n{}", sidewalk_pt, sidewalk, lanes[sidewalk.0].lane_center_pts);
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ fn make_vehicle_turn(map: &Map, i: IntersectionID, l1: LaneID, l2: LaneID) -> Tu
|
|||||||
let pieces = 5;
|
let pieces = 5;
|
||||||
PolyLine::new(
|
PolyLine::new(
|
||||||
(0..=pieces)
|
(0..=pieces)
|
||||||
.map(|i| from_pt(curve.interp(1.0 / (pieces as f64) * (i as f64)).unwrap()))
|
.map(|i| from_pt(curve.interp(1.0 / f64::from(i * pieces)).unwrap()))
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -172,7 +172,7 @@ impl Map {
|
|||||||
// TODO probably different behavior for oneways
|
// TODO probably different behavior for oneways
|
||||||
// TODO need to factor in yellow center lines (but what's the right thing to even do?
|
// TODO need to factor in yellow center lines (but what's the right thing to even do?
|
||||||
// Reverse points for British-style driving on the left
|
// Reverse points for British-style driving on the left
|
||||||
let width = LANE_THICKNESS * ((lane.offset as f64) + 0.5);
|
let width = LANE_THICKNESS * (0.5 + f64::from(lane.offset));
|
||||||
let (lane_center_pts, probably_broken) = match unshifted_pts.shift(width) {
|
let (lane_center_pts, probably_broken) = match unshifted_pts.shift(width) {
|
||||||
Some(pts) => (pts, false),
|
Some(pts) => (pts, false),
|
||||||
// TODO wasteful to calculate again, but eh
|
// TODO wasteful to calculate again, but eh
|
||||||
@ -465,7 +465,7 @@ impl Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup_turn_by_idx(&self, idx: usize) -> Option<TurnID> {
|
pub fn lookup_turn_by_idx(&self, idx: usize) -> Option<TurnID> {
|
||||||
self.turn_lookup.get(idx).map(|id| *id)
|
self.turn_lookup.get(idx).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
// All these helpers should take IDs and return objects.
|
// All these helpers should take IDs and return objects.
|
||||||
@ -668,8 +668,7 @@ impl Map {
|
|||||||
} else if let Some(ts) = self.traffic_signals.get(&t.parent) {
|
} else if let Some(ts) = self.traffic_signals.get(&t.parent) {
|
||||||
ts.cycles
|
ts.cycles
|
||||||
.iter()
|
.iter()
|
||||||
.find(|c| c.get_priority(t) != TurnPriority::Banned)
|
.any(|c| c.get_priority(t) != TurnPriority::Banned)
|
||||||
.is_some()
|
|
||||||
} else {
|
} else {
|
||||||
// Border nodes have no turns...
|
// Border nodes have no turns...
|
||||||
panic!("{}'s intersection isn't a stop sign or traffic signal", t);
|
panic!("{}'s intersection isn't a stop sign or traffic signal", t);
|
||||||
@ -685,12 +684,10 @@ fn is_border(intersection: &Intersection, map: &Map) -> bool {
|
|||||||
let has_driving_in = intersection
|
let has_driving_in = intersection
|
||||||
.incoming_lanes
|
.incoming_lanes
|
||||||
.iter()
|
.iter()
|
||||||
.find(|l| map.get_l(**l).is_driving())
|
.any(|l| map.get_l(*l).is_driving());
|
||||||
.is_some();
|
|
||||||
let has_driving_out = intersection
|
let has_driving_out = intersection
|
||||||
.outgoing_lanes
|
.outgoing_lanes
|
||||||
.iter()
|
.iter()
|
||||||
.find(|l| map.get_l(**l).is_driving())
|
.any(|l| map.get_l(*l).is_driving());
|
||||||
.is_some();
|
|
||||||
has_driving_in != has_driving_out
|
has_driving_in != has_driving_out
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ impl Path {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(pts_so_far.unwrap());
|
Some(pts_so_far.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_steps(&self) -> &VecDeque<PathStep> {
|
pub fn get_steps(&self) -> &VecDeque<PathStep> {
|
||||||
@ -285,7 +285,7 @@ impl Pathfinder {
|
|||||||
steps.last().unwrap().as_traversable(),
|
steps.last().unwrap().as_traversable(),
|
||||||
Traversable::Lane(req.end.lane())
|
Traversable::Lane(req.end.lane())
|
||||||
);
|
);
|
||||||
return Some(Path::new(map, steps, req.end.dist_along()));
|
Some(Path::new(map, steps, req.end.dist_along()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt the pathfinding and see if riding a bus is a step.
|
// Attempt the pathfinding and see if riding a bus is a step.
|
||||||
@ -435,12 +435,13 @@ impl Pathfinder {
|
|||||||
|
|
||||||
// Expand
|
// Expand
|
||||||
for next in self.expand(map, current).into_iter() {
|
for next in self.expand(map, current).into_iter() {
|
||||||
if !backrefs.contains_key(&next) {
|
backrefs.entry(next).or_insert_with(|| {
|
||||||
backrefs.insert(next, current);
|
|
||||||
let cost = next.cost(map);
|
let cost = next.cost(map);
|
||||||
let heuristic = next.heuristic(self.goal_pt, map);
|
let heuristic = next.heuristic(self.goal_pt, map);
|
||||||
queue.push((dist_to_pri_queue(cost + heuristic) + cost_sofar, next));
|
queue.push((dist_to_pri_queue(cost + heuristic) + cost_sofar, next));
|
||||||
}
|
|
||||||
|
current
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,17 +52,11 @@ impl Road {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_forwards(&self, lane: LaneID) -> bool {
|
pub fn is_forwards(&self, lane: LaneID) -> bool {
|
||||||
self.children_forwards
|
self.children_forwards.iter().any(|(id, _)| *id == lane)
|
||||||
.iter()
|
|
||||||
.find(|(id, _)| *id == lane)
|
|
||||||
.is_some()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_backwards(&self, lane: LaneID) -> bool {
|
pub fn is_backwards(&self, lane: LaneID) -> bool {
|
||||||
self.children_backwards
|
self.children_backwards.iter().any(|(id, _)| *id == lane)
|
||||||
.iter()
|
|
||||||
.find(|(id, _)| *id == lane)
|
|
||||||
.is_some()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// lane must belong to this road. Offset 0 is the centermost lane on each side of a road, then
|
// lane must belong to this road. Offset 0 is the centermost lane on each side of a road, then
|
||||||
|
@ -55,52 +55,52 @@ pub enum Traversable {
|
|||||||
|
|
||||||
impl Traversable {
|
impl Traversable {
|
||||||
pub fn as_lane(&self) -> LaneID {
|
pub fn as_lane(&self) -> LaneID {
|
||||||
match self {
|
match *self {
|
||||||
&Traversable::Lane(id) => id,
|
Traversable::Lane(id) => id,
|
||||||
&Traversable::Turn(_) => panic!("not a lane"),
|
Traversable::Turn(_) => panic!("not a lane"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_turn(&self) -> TurnID {
|
pub fn as_turn(&self) -> TurnID {
|
||||||
match self {
|
match *self {
|
||||||
&Traversable::Turn(id) => id,
|
Traversable::Turn(id) => id,
|
||||||
&Traversable::Lane(_) => panic!("not a turn"),
|
Traversable::Lane(_) => panic!("not a turn"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_turn(&self) -> Option<TurnID> {
|
pub fn maybe_turn(&self) -> Option<TurnID> {
|
||||||
match self {
|
match *self {
|
||||||
&Traversable::Turn(id) => Some(id),
|
Traversable::Turn(id) => Some(id),
|
||||||
&Traversable::Lane(_) => None,
|
Traversable::Lane(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_lane(&self) -> Option<LaneID> {
|
pub fn maybe_lane(&self) -> Option<LaneID> {
|
||||||
match self {
|
match *self {
|
||||||
&Traversable::Turn(_) => None,
|
Traversable::Turn(_) => None,
|
||||||
&Traversable::Lane(id) => Some(id),
|
Traversable::Lane(id) => Some(id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Just expose the PolyLine instead of all these layers of helpers
|
// TODO Just expose the PolyLine instead of all these layers of helpers
|
||||||
pub fn length(&self, map: &Map) -> si::Meter<f64> {
|
pub fn length(&self, map: &Map) -> si::Meter<f64> {
|
||||||
match self {
|
match *self {
|
||||||
&Traversable::Lane(id) => map.get_l(id).length(),
|
Traversable::Lane(id) => map.get_l(id).length(),
|
||||||
&Traversable::Turn(id) => map.get_t(id).length(),
|
Traversable::Turn(id) => map.get_t(id).length(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dist_along(&self, dist: si::Meter<f64>, map: &Map) -> (Pt2D, Angle) {
|
pub fn dist_along(&self, dist: si::Meter<f64>, map: &Map) -> (Pt2D, Angle) {
|
||||||
match self {
|
match *self {
|
||||||
&Traversable::Lane(id) => map.get_l(id).dist_along(dist),
|
Traversable::Lane(id) => map.get_l(id).dist_along(dist),
|
||||||
&Traversable::Turn(id) => map.get_t(id).dist_along(dist),
|
Traversable::Turn(id) => map.get_t(id).dist_along(dist),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn speed_limit(&self, map: &Map) -> si::MeterPerSecond<f64> {
|
pub fn speed_limit(&self, map: &Map) -> si::MeterPerSecond<f64> {
|
||||||
match self {
|
match *self {
|
||||||
&Traversable::Lane(id) => map.get_parent(id).get_speed_limit(),
|
Traversable::Lane(id) => map.get_parent(id).get_speed_limit(),
|
||||||
&Traversable::Turn(id) => map.get_parent(id.dst).get_speed_limit(),
|
Traversable::Turn(id) => map.get_parent(id.dst).get_speed_limit(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ use geom::{PolyLine, Pt2D};
|
|||||||
// Copied from map_model; no need to have to rebuild that crate
|
// Copied from map_model; no need to have to rebuild that crate
|
||||||
const LANE_THICKNESS: f64 = 2.5;
|
const LANE_THICKNESS: f64 = 2.5;
|
||||||
|
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
pub fn run(g: &mut GfxCtx) {
|
pub fn run(g: &mut GfxCtx) {
|
||||||
let thin = 0.25;
|
let thin = 0.25;
|
||||||
let shift1_width = LANE_THICKNESS * 0.5;
|
let shift1_width = LANE_THICKNESS * 0.5;
|
||||||
|
@ -2,6 +2,7 @@ use crate::common::BLUE;
|
|||||||
use ezgui::GfxCtx;
|
use ezgui::GfxCtx;
|
||||||
use geom::{Polygon, Pt2D};
|
use geom::{Polygon, Pt2D};
|
||||||
|
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
pub fn run(g: &mut GfxCtx, labels: &mut Vec<(Pt2D, String)>) {
|
pub fn run(g: &mut GfxCtx, labels: &mut Vec<(Pt2D, String)>) {
|
||||||
let pts = vec![
|
let pts = vec![
|
||||||
Pt2D::new(1158.5480421283125, 759.4168710122531), // 0
|
Pt2D::new(1158.5480421283125, 759.4168710122531), // 0
|
||||||
|
@ -2,6 +2,7 @@ use crate::common::{draw_polyline, BLACK, RED};
|
|||||||
use ezgui::GfxCtx;
|
use ezgui::GfxCtx;
|
||||||
use geom::{PolyLine, Pt2D};
|
use geom::{PolyLine, Pt2D};
|
||||||
|
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
pub fn run(g: &mut GfxCtx, labels: &mut Vec<(Pt2D, String)>) {
|
pub fn run(g: &mut GfxCtx, labels: &mut Vec<(Pt2D, String)>) {
|
||||||
let thin = 1.0;
|
let thin = 1.0;
|
||||||
let width = 50.0;
|
let width = 50.0;
|
||||||
|
@ -2,6 +2,7 @@ use crate::common::{draw_polyline, BLUE, GREEN, RED};
|
|||||||
use ezgui::GfxCtx;
|
use ezgui::GfxCtx;
|
||||||
use geom::{Circle, PolyLine, Pt2D};
|
use geom::{Circle, PolyLine, Pt2D};
|
||||||
|
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
pub fn run(g: &mut GfxCtx) {
|
pub fn run(g: &mut GfxCtx) {
|
||||||
let mut vertical_pl = PolyLine::new(vec![
|
let mut vertical_pl = PolyLine::new(vec![
|
||||||
Pt2D::new(1333.9512635794777, 413.3946082988369),
|
Pt2D::new(1333.9512635794777, 413.3946082988369),
|
||||||
|
@ -185,7 +185,8 @@ impl Car {
|
|||||||
parking_sim,
|
parking_sim,
|
||||||
transit_sim,
|
transit_sim,
|
||||||
);
|
);
|
||||||
let dist_to_maybe_stop_at = maybe_stop_early.unwrap_or(current_on.length(map));
|
let dist_to_maybe_stop_at =
|
||||||
|
maybe_stop_early.unwrap_or_else(|| current_on.length(map));
|
||||||
let dist_from_stop = dist_to_maybe_stop_at - current_dist_along;
|
let dist_from_stop = dist_to_maybe_stop_at - current_dist_along;
|
||||||
|
|
||||||
// If our lookahead doesn't even hit the intersection / early stopping point, then
|
// If our lookahead doesn't even hit the intersection / early stopping point, then
|
||||||
@ -614,7 +615,7 @@ impl DrivingSimState {
|
|||||||
}
|
}
|
||||||
Action::StartParkingBike => {
|
Action::StartParkingBike => {
|
||||||
{
|
{
|
||||||
let c = self.cars.get(&id).unwrap();
|
let c = &self.cars[&id];
|
||||||
done_biking.push((*id, Position::new(c.on.as_lane(), c.dist_along)));
|
done_biking.push((*id, Position::new(c.on.as_lane(), c.dist_along)));
|
||||||
}
|
}
|
||||||
self.cars.remove(&id);
|
self.cars.remove(&id);
|
||||||
@ -822,7 +823,7 @@ impl DrivingSimState {
|
|||||||
if let Some(queue) = self.queues.get(&on) {
|
if let Some(queue) = self.queues.get(&on) {
|
||||||
return queue.get_draw_cars(self, map, time);
|
return queue.get_draw_cars(self, map, time);
|
||||||
}
|
}
|
||||||
return Vec::new();
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_all_draw_cars(&self, time: Tick, map: &Map) -> Vec<DrawCarInput> {
|
pub fn get_all_draw_cars(&self, time: Tick, map: &Map) -> Vec<DrawCarInput> {
|
||||||
|
@ -175,10 +175,7 @@ impl Sim {
|
|||||||
self.spawner.start_trip_using_parked_car(
|
self.spawner.start_trip_using_parked_car(
|
||||||
Tick::zero(),
|
Tick::zero(),
|
||||||
map,
|
map,
|
||||||
self.parking_state
|
self.parking_state.lookup_car(car).cloned().unwrap(),
|
||||||
.lookup_car(car)
|
|
||||||
.map(|p| p.clone())
|
|
||||||
.unwrap(),
|
|
||||||
&self.parking_state,
|
&self.parking_state,
|
||||||
from_bldg,
|
from_bldg,
|
||||||
DrivingGoal::ParkNear(to_bldg),
|
DrivingGoal::ParkNear(to_bldg),
|
||||||
|
@ -16,7 +16,7 @@ pub fn capture_backtrace(event: &str) {
|
|||||||
// TODO compiler flag so capture_backtrace is usually a no-op. actually, looks like this
|
// TODO compiler flag so capture_backtrace is usually a no-op. actually, looks like this
|
||||||
// doesn't work in --release mode, so use that.
|
// doesn't work in --release mode, so use that.
|
||||||
let symbol_name = f.symbols()[0].name();
|
let symbol_name = f.symbols()[0].name();
|
||||||
if !symbol_name.is_some() {
|
if symbol_name.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,10 +30,8 @@ pub fn capture_backtrace(event: &str) {
|
|||||||
if name == "sim::sim::Sim::inner_step" {
|
if name == "sim::sim::Sim::inner_step" {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else if name.ends_with("::capture_backtrace") {
|
||||||
if name.ends_with("::capture_backtrace") {
|
found_this_fxn = true;
|
||||||
found_this_fxn = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,13 +51,11 @@ impl IntersectionSimState {
|
|||||||
let mut intersections: Vec<IntersectionPolicy> = Vec::new();
|
let mut intersections: Vec<IntersectionPolicy> = Vec::new();
|
||||||
for i in map.all_intersections() {
|
for i in map.all_intersections() {
|
||||||
intersections.push(match i.intersection_type {
|
intersections.push(match i.intersection_type {
|
||||||
IntersectionType::StopSign => {
|
IntersectionType::StopSign => IntersectionPolicy::StopSign(StopSign::new(i.id)),
|
||||||
IntersectionPolicy::StopSignPolicy(StopSign::new(i.id))
|
|
||||||
}
|
|
||||||
IntersectionType::TrafficSignal => {
|
IntersectionType::TrafficSignal => {
|
||||||
IntersectionPolicy::TrafficSignalPolicy(TrafficSignal::new(i.id))
|
IntersectionPolicy::TrafficSignal(TrafficSignal::new(i.id))
|
||||||
}
|
}
|
||||||
IntersectionType::Border => IntersectionPolicy::BorderPolicy,
|
IntersectionType::Border => IntersectionPolicy::Border,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
IntersectionSimState {
|
IntersectionSimState {
|
||||||
@ -78,31 +76,29 @@ impl IntersectionSimState {
|
|||||||
// agent is the leader vehicle and at the end of the lane). The request may have been
|
// agent is the leader vehicle and at the end of the lane). The request may have been
|
||||||
// previously granted, but the agent might not have been able to start the turn.
|
// previously granted, but the agent might not have been able to start the turn.
|
||||||
pub fn submit_request(&mut self, req: Request) {
|
pub fn submit_request(&mut self, req: Request) {
|
||||||
let i = self.intersections.get_mut(req.turn.parent.0).unwrap();
|
let i = &mut self.intersections[req.turn.parent.0];
|
||||||
if i.is_accepted(&req) {
|
if i.is_accepted(&req) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match i {
|
match i {
|
||||||
IntersectionPolicy::StopSignPolicy(ref mut p) => {
|
IntersectionPolicy::StopSign(ref mut p) => {
|
||||||
if !p.started_waiting_at.contains_key(&req) {
|
if !p.started_waiting_at.contains_key(&req) {
|
||||||
p.approaching_agents.insert(req);
|
p.approaching_agents.insert(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => {
|
IntersectionPolicy::TrafficSignal(ref mut p) => {
|
||||||
p.requests.insert(req);
|
p.requests.insert(req);
|
||||||
}
|
}
|
||||||
IntersectionPolicy::BorderPolicy => {}
|
IntersectionPolicy::Border => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn step(&mut self, events: &mut Vec<Event>, time: Tick, map: &Map, view: &WorldView) {
|
pub fn step(&mut self, events: &mut Vec<Event>, time: Tick, map: &Map, view: &WorldView) {
|
||||||
for i in self.intersections.iter_mut() {
|
for i in self.intersections.iter_mut() {
|
||||||
match i {
|
match i {
|
||||||
IntersectionPolicy::StopSignPolicy(ref mut p) => p.step(events, time, map, view),
|
IntersectionPolicy::StopSign(ref mut p) => p.step(events, time, map, view),
|
||||||
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => {
|
IntersectionPolicy::TrafficSignal(ref mut p) => p.step(events, time, map, view),
|
||||||
p.step(events, time, map, view)
|
IntersectionPolicy::Border => {}
|
||||||
}
|
|
||||||
IntersectionPolicy::BorderPolicy => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,16 +112,16 @@ impl IntersectionSimState {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::new(format!(
|
Err(Error::new(format!(
|
||||||
"{:?} entered, but wasn't accepted by the intersection yet",
|
"{:?} entered, but wasn't accepted by the intersection yet",
|
||||||
req
|
req
|
||||||
)));
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_exit(&mut self, req: Request) {
|
pub fn on_exit(&mut self, req: Request) {
|
||||||
let id = req.turn.parent;
|
let id = req.turn.parent;
|
||||||
let i = self.intersections.get_mut(id.0).unwrap();
|
let i = &mut self.intersections[id.0];
|
||||||
assert!(i.is_accepted(&req));
|
assert!(i.is_accepted(&req));
|
||||||
i.on_exit(&req);
|
i.on_exit(&req);
|
||||||
if self.debug == Some(id) {
|
if self.debug == Some(id) {
|
||||||
@ -135,28 +131,28 @@ impl IntersectionSimState {
|
|||||||
|
|
||||||
pub fn debug(&mut self, id: IntersectionID, map: &Map) {
|
pub fn debug(&mut self, id: IntersectionID, map: &Map) {
|
||||||
if let Some(old) = self.debug {
|
if let Some(old) = self.debug {
|
||||||
match self.intersections.get_mut(old.0).unwrap() {
|
match self.intersections[old.0] {
|
||||||
IntersectionPolicy::StopSignPolicy(ref mut p) => {
|
IntersectionPolicy::StopSign(ref mut p) => {
|
||||||
p.debug = false;
|
p.debug = false;
|
||||||
}
|
}
|
||||||
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => {
|
IntersectionPolicy::TrafficSignal(ref mut p) => {
|
||||||
p.debug = false;
|
p.debug = false;
|
||||||
}
|
}
|
||||||
IntersectionPolicy::BorderPolicy => {}
|
IntersectionPolicy::Border => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{}", abstutil::to_json(&self.intersections[id.0]));
|
println!("{}", abstutil::to_json(&self.intersections[id.0]));
|
||||||
match self.intersections.get_mut(id.0).unwrap() {
|
match self.intersections[id.0] {
|
||||||
IntersectionPolicy::StopSignPolicy(ref mut p) => {
|
IntersectionPolicy::StopSign(ref mut p) => {
|
||||||
p.debug = true;
|
p.debug = true;
|
||||||
println!("{}", abstutil::to_json(map.get_stop_sign(id)));
|
println!("{}", abstutil::to_json(map.get_stop_sign(id)));
|
||||||
}
|
}
|
||||||
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => {
|
IntersectionPolicy::TrafficSignal(ref mut p) => {
|
||||||
p.debug = true;
|
p.debug = true;
|
||||||
println!("{}", abstutil::to_json(map.get_traffic_signal(id)));
|
println!("{}", abstutil::to_json(map.get_traffic_signal(id)));
|
||||||
}
|
}
|
||||||
IntersectionPolicy::BorderPolicy => {
|
IntersectionPolicy::Border => {
|
||||||
println!("{} is a border", id);
|
println!("{} is a border", id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -166,25 +162,25 @@ impl IntersectionSimState {
|
|||||||
// Use an enum instead of traits so that serialization works. I couldn't figure out erased_serde.
|
// Use an enum instead of traits so that serialization works. I couldn't figure out erased_serde.
|
||||||
#[derive(Serialize, Deserialize, PartialEq)]
|
#[derive(Serialize, Deserialize, PartialEq)]
|
||||||
enum IntersectionPolicy {
|
enum IntersectionPolicy {
|
||||||
StopSignPolicy(StopSign),
|
StopSign(StopSign),
|
||||||
TrafficSignalPolicy(TrafficSignal),
|
TrafficSignal(TrafficSignal),
|
||||||
BorderPolicy,
|
Border,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntersectionPolicy {
|
impl IntersectionPolicy {
|
||||||
fn is_accepted(&self, req: &Request) -> bool {
|
fn is_accepted(&self, req: &Request) -> bool {
|
||||||
match self {
|
match self {
|
||||||
IntersectionPolicy::StopSignPolicy(ref p) => p.accepted.contains(req),
|
IntersectionPolicy::StopSign(ref p) => p.accepted.contains(req),
|
||||||
IntersectionPolicy::TrafficSignalPolicy(ref p) => p.accepted.contains(req),
|
IntersectionPolicy::TrafficSignal(ref p) => p.accepted.contains(req),
|
||||||
IntersectionPolicy::BorderPolicy => true,
|
IntersectionPolicy::Border => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_exit(&mut self, req: &Request) {
|
fn on_exit(&mut self, req: &Request) {
|
||||||
match self {
|
match self {
|
||||||
IntersectionPolicy::StopSignPolicy(ref mut p) => p.accepted.remove(&req),
|
IntersectionPolicy::StopSign(ref mut p) => p.accepted.remove(&req),
|
||||||
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => p.accepted.remove(&req),
|
IntersectionPolicy::TrafficSignal(ref mut p) => p.accepted.remove(&req),
|
||||||
IntersectionPolicy::BorderPolicy => {
|
IntersectionPolicy::Border => {
|
||||||
panic!("{:?} called on_exit for a border node; how?!", req);
|
panic!("{:?} called on_exit for a border node; how?!", req);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -225,8 +221,7 @@ impl StopSign {
|
|||||||
let base_t = map.get_t(turn);
|
let base_t = map.get_t(turn);
|
||||||
self.accepted
|
self.accepted
|
||||||
.iter()
|
.iter()
|
||||||
.find(|req| base_t.conflicts_with(map.get_t(req.turn)))
|
.any(|req| base_t.conflicts_with(map.get_t(req.turn)))
|
||||||
.is_some()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn conflicts_with_waiting_with_higher_priority(
|
fn conflicts_with_waiting_with_higher_priority(
|
||||||
@ -237,13 +232,9 @@ impl StopSign {
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
let base_t = map.get_t(turn);
|
let base_t = map.get_t(turn);
|
||||||
let base_priority = ss.get_priority(turn);
|
let base_priority = ss.get_priority(turn);
|
||||||
self.started_waiting_at
|
self.started_waiting_at.keys().any(|req| {
|
||||||
.keys()
|
base_t.conflicts_with(map.get_t(req.turn)) && ss.get_priority(req.turn) > base_priority
|
||||||
.find(|req| {
|
})
|
||||||
base_t.conflicts_with(map.get_t(req.turn))
|
|
||||||
&& ss.get_priority(req.turn) > base_priority
|
|
||||||
})
|
|
||||||
.is_some()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn step(&mut self, events: &mut Vec<Event>, time: Tick, map: &Map, view: &WorldView) {
|
fn step(&mut self, events: &mut Vec<Event>, time: Tick, map: &Map, view: &WorldView) {
|
||||||
@ -379,8 +370,7 @@ impl TrafficSignal {
|
|||||||
let base_t = map.get_t(req.turn);
|
let base_t = map.get_t(req.turn);
|
||||||
if priority_requests
|
if priority_requests
|
||||||
.iter()
|
.iter()
|
||||||
.find(|t| base_t.conflicts_with(map.get_t(**t)))
|
.any(|t| base_t.conflicts_with(map.get_t(*t)))
|
||||||
.is_some()
|
|
||||||
{
|
{
|
||||||
keep_requests.insert(req.clone());
|
keep_requests.insert(req.clone());
|
||||||
continue;
|
continue;
|
||||||
@ -407,7 +397,6 @@ impl TrafficSignal {
|
|||||||
let base_t = map.get_t(turn);
|
let base_t = map.get_t(turn);
|
||||||
self.accepted
|
self.accepted
|
||||||
.iter()
|
.iter()
|
||||||
.find(|req| base_t.conflicts_with(map.get_t(req.turn)))
|
.any(|req| base_t.conflicts_with(map.get_t(req.turn)))
|
||||||
.is_some()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use serde_derive::{Deserialize, Serialize};
|
|||||||
use std;
|
use std;
|
||||||
|
|
||||||
pub const EPSILON_SPEED: Speed = si::MeterPerSecond {
|
pub const EPSILON_SPEED: Speed = si::MeterPerSecond {
|
||||||
value_unsafe: 0.00000001,
|
value_unsafe: 0.000_000_01,
|
||||||
_marker: std::marker::PhantomData,
|
_marker: std::marker::PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ pub struct ABTest {
|
|||||||
impl ABTest {
|
impl ABTest {
|
||||||
pub fn describe(&self) -> Vec<String> {
|
pub fn describe(&self) -> Vec<String> {
|
||||||
abstutil::to_json(self)
|
abstutil::to_json(self)
|
||||||
.split("\n")
|
.split('\n')
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ pub struct SeedParkedCars {
|
|||||||
impl Scenario {
|
impl Scenario {
|
||||||
pub fn describe(&self) -> Vec<String> {
|
pub fn describe(&self) -> Vec<String> {
|
||||||
abstutil::to_json(self)
|
abstutil::to_json(self)
|
||||||
.split("\n")
|
.split('\n')
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@ -153,42 +153,40 @@ impl Scenario {
|
|||||||
&mut sim.rng,
|
&mut sim.rng,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(goal) =
|
||||||
if let Some(goal) =
|
s.goal
|
||||||
s.goal
|
.pick_walking_goal(map, &bldgs_per_neighborhood, &mut sim.rng)
|
||||||
.pick_walking_goal(map, &bldgs_per_neighborhood, &mut sim.rng)
|
{
|
||||||
{
|
let start_spot = SidewalkSpot::building(from_bldg, map);
|
||||||
let start_spot = SidewalkSpot::building(from_bldg, map);
|
|
||||||
|
|
||||||
if sim.rng.gen_bool(s.percent_use_transit) {
|
if sim.rng.gen_bool(s.percent_use_transit) {
|
||||||
// TODO This throws away some work. It also sequentially does expensive
|
// TODO This throws away some work. It also sequentially does expensive
|
||||||
// work right here.
|
// work right here.
|
||||||
if let Some((stop1, stop2, route)) = Pathfinder::should_use_transit(
|
if let Some((stop1, stop2, route)) = Pathfinder::should_use_transit(
|
||||||
|
map,
|
||||||
|
start_spot.sidewalk_pos,
|
||||||
|
goal.sidewalk_pos,
|
||||||
|
) {
|
||||||
|
sim.spawner.start_trip_using_bus(
|
||||||
|
spawn_time,
|
||||||
map,
|
map,
|
||||||
start_spot.sidewalk_pos,
|
start_spot,
|
||||||
goal.sidewalk_pos,
|
goal,
|
||||||
) {
|
route,
|
||||||
sim.spawner.start_trip_using_bus(
|
stop1,
|
||||||
spawn_time,
|
stop2,
|
||||||
map,
|
&mut sim.trips_state,
|
||||||
start_spot,
|
);
|
||||||
goal,
|
continue;
|
||||||
route,
|
|
||||||
stop1,
|
|
||||||
stop2,
|
|
||||||
&mut sim.trips_state,
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sim.spawner.start_trip_just_walking(
|
|
||||||
spawn_time,
|
|
||||||
start_spot,
|
|
||||||
goal,
|
|
||||||
&mut sim.trips_state,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sim.spawner.start_trip_just_walking(
|
||||||
|
spawn_time,
|
||||||
|
start_spot,
|
||||||
|
goal,
|
||||||
|
&mut sim.trips_state,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ impl ParkingSimState {
|
|||||||
pub fn edit_remove_lane(&mut self, id: LaneID) {
|
pub fn edit_remove_lane(&mut self, id: LaneID) {
|
||||||
assert!(self.lanes[id.0].is_empty());
|
assert!(self.lanes[id.0].is_empty());
|
||||||
self.lanes[id.0] = ParkingLane {
|
self.lanes[id.0] = ParkingLane {
|
||||||
id: id,
|
id,
|
||||||
spots: Vec::new(),
|
spots: Vec::new(),
|
||||||
occupants: Vec::new(),
|
occupants: Vec::new(),
|
||||||
};
|
};
|
||||||
@ -90,8 +90,8 @@ impl ParkingSimState {
|
|||||||
id: p.car,
|
id: p.car,
|
||||||
vehicle_length: p.vehicle.length,
|
vehicle_length: p.vehicle.length,
|
||||||
waiting_for_turn: None,
|
waiting_for_turn: None,
|
||||||
front: front,
|
front,
|
||||||
angle: angle,
|
angle,
|
||||||
stopping_trace: None,
|
stopping_trace: None,
|
||||||
state: CarState::Parked,
|
state: CarState::Parked,
|
||||||
vehicle_type: VehicleType::Car,
|
vehicle_type: VehicleType::Car,
|
||||||
@ -224,7 +224,7 @@ impl ParkingLane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
!self.occupants.iter().find(|x| x.is_some()).is_some()
|
!self.occupants.iter().any(|x| x.is_some())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ pub type Acceleration = si::MeterPerSecond2<f64>;
|
|||||||
pub struct Tick(u32);
|
pub struct Tick(u32);
|
||||||
|
|
||||||
impl Tick {
|
impl Tick {
|
||||||
pub fn as_usize(&self) -> usize {
|
pub fn as_usize(self) -> usize {
|
||||||
self.0 as usize
|
self.0 as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,14 +42,14 @@ impl Tick {
|
|||||||
|
|
||||||
// TODO Why have these two forms? Consolidate
|
// TODO Why have these two forms? Consolidate
|
||||||
pub fn parse(string: &str) -> Option<Tick> {
|
pub fn parse(string: &str) -> Option<Tick> {
|
||||||
let parts: Vec<&str> = string.split(":").collect();
|
let parts: Vec<&str> = string.split(':').collect();
|
||||||
if parts.is_empty() {
|
if parts.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ticks: u32 = 0;
|
let mut ticks: u32 = 0;
|
||||||
if parts.last().unwrap().contains(".") {
|
if parts.last().unwrap().contains('.') {
|
||||||
let last_parts: Vec<&str> = parts.last().unwrap().split(".").collect();
|
let last_parts: Vec<&str> = parts.last().unwrap().split('.').collect();
|
||||||
if last_parts.len() != 2 {
|
if last_parts.len() != 2 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@ -87,8 +87,8 @@ impl Tick {
|
|||||||
Some(Tick(hours + minutes + seconds + ms))
|
Some(Tick(hours + minutes + seconds + ms))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_time(&self) -> Time {
|
pub fn as_time(self) -> Time {
|
||||||
(self.0 as f64) * TIMESTEP
|
f64::from(self.0) * TIMESTEP
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(self) -> Tick {
|
pub fn next(self) -> Tick {
|
||||||
@ -99,11 +99,11 @@ impl Tick {
|
|||||||
Tick(self.0 - 1)
|
Tick(self.0 - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_multiple_of(&self, other: Tick) -> bool {
|
pub fn is_multiple_of(self, other: Tick) -> bool {
|
||||||
self.0 % other.0 == 0
|
self.0 % other.0 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_parts(&self) -> (u32, u32, u32, u32) {
|
fn get_parts(self) -> (u32, u32, u32, u32) {
|
||||||
// TODO hardcoding these to avoid floating point issues... urgh. :\
|
// TODO hardcoding these to avoid floating point issues... urgh. :\
|
||||||
let ticks_per_second = 10;
|
let ticks_per_second = 10;
|
||||||
let ticks_per_minute = 60 * ticks_per_second;
|
let ticks_per_minute = 60 * ticks_per_second;
|
||||||
@ -112,14 +112,14 @@ impl Tick {
|
|||||||
let hours = self.0 / ticks_per_hour;
|
let hours = self.0 / ticks_per_hour;
|
||||||
let mut remainder = self.0 % ticks_per_hour;
|
let mut remainder = self.0 % ticks_per_hour;
|
||||||
let minutes = remainder / ticks_per_minute;
|
let minutes = remainder / ticks_per_minute;
|
||||||
remainder = remainder % ticks_per_minute;
|
remainder %= ticks_per_minute;
|
||||||
let seconds = remainder / ticks_per_second;
|
let seconds = remainder / ticks_per_second;
|
||||||
remainder = remainder % ticks_per_second;
|
remainder %= ticks_per_second;
|
||||||
|
|
||||||
(hours, minutes, seconds, remainder)
|
(hours, minutes, seconds, remainder)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_filename(&self) -> String {
|
pub fn as_filename(self) -> String {
|
||||||
let (hours, minutes, seconds, remainder) = self.get_parts();
|
let (hours, minutes, seconds, remainder) = self.get_parts();
|
||||||
format!(
|
format!(
|
||||||
"{0:02}h{1:02}m{2:02}.{3}s",
|
"{0:02}h{1:02}m{2:02}.{3}s",
|
||||||
|
@ -312,7 +312,7 @@ impl Sim {
|
|||||||
pub fn load_most_recent(&self) -> Result<Sim, std::io::Error> {
|
pub fn load_most_recent(&self) -> Result<Sim, std::io::Error> {
|
||||||
let (_, load) = self
|
let (_, load) = self
|
||||||
.find_all_savestates()
|
.find_all_savestates()
|
||||||
.and_then(|mut list| list.pop().ok_or(io_error("empty directory")))?;
|
.and_then(|mut list| list.pop().ok_or_else(|| io_error("empty directory")))?;
|
||||||
info!("Loading {}", load);
|
info!("Loading {}", load);
|
||||||
abstutil::read_json(&load)
|
abstutil::read_json(&load)
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ impl Spawner {
|
|||||||
now,
|
now,
|
||||||
CreateCar {
|
CreateCar {
|
||||||
car,
|
car,
|
||||||
trip: trip,
|
trip,
|
||||||
owner: parked_car.owner,
|
owner: parked_car.owner,
|
||||||
maybe_parked_car: Some(parked_car.clone()),
|
maybe_parked_car: Some(parked_car.clone()),
|
||||||
vehicle: parked_car.vehicle.clone(),
|
vehicle: parked_car.vehicle.clone(),
|
||||||
@ -216,7 +216,7 @@ impl Spawner {
|
|||||||
now,
|
now,
|
||||||
CreateCar {
|
CreateCar {
|
||||||
car,
|
car,
|
||||||
trip: trip,
|
trip,
|
||||||
// TODO need a way to specify this in the scenario
|
// TODO need a way to specify this in the scenario
|
||||||
owner: None,
|
owner: None,
|
||||||
maybe_parked_car: None,
|
maybe_parked_car: None,
|
||||||
@ -247,7 +247,7 @@ impl Spawner {
|
|||||||
now,
|
now,
|
||||||
CreateCar {
|
CreateCar {
|
||||||
car: vehicle.id,
|
car: vehicle.id,
|
||||||
trip: trip,
|
trip,
|
||||||
owner: None,
|
owner: None,
|
||||||
maybe_parked_car: None,
|
maybe_parked_car: None,
|
||||||
vehicle: vehicle.clone(),
|
vehicle: vehicle.clone(),
|
||||||
|
@ -208,15 +208,12 @@ impl TripManager {
|
|||||||
spawned_at,
|
spawned_at,
|
||||||
finished_at: None,
|
finished_at: None,
|
||||||
ped,
|
ped,
|
||||||
uses_car: legs
|
uses_car: legs.iter().any(|l| match l {
|
||||||
.iter()
|
TripLeg::Drive(_, _) => true,
|
||||||
.find(|l| match l {
|
TripLeg::DriveFromBorder(_, _) => true,
|
||||||
TripLeg::Drive(_, _) => true,
|
TripLeg::ServeBusRoute(_, _) => true,
|
||||||
TripLeg::DriveFromBorder(_, _) => true,
|
_ => false,
|
||||||
TripLeg::ServeBusRoute(_, _) => true,
|
}),
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
.is_some(),
|
|
||||||
legs: VecDeque::from(legs),
|
legs: VecDeque::from(legs),
|
||||||
});
|
});
|
||||||
id
|
id
|
||||||
@ -226,7 +223,7 @@ impl TripManager {
|
|||||||
pub fn get_trip_using_car(&self, car: CarID) -> Option<TripID> {
|
pub fn get_trip_using_car(&self, car: CarID) -> Option<TripID> {
|
||||||
self.trips
|
self.trips
|
||||||
.iter()
|
.iter()
|
||||||
.find(|t| t.legs.iter().find(|l| l.uses_car(car)).is_some())
|
.find(|t| t.legs.iter().any(|l| l.uses_car(car)))
|
||||||
.map(|t| t.id)
|
.map(|t| t.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,11 +289,11 @@ impl TripManager {
|
|||||||
|
|
||||||
// This will be None for parked cars
|
// This will be None for parked cars
|
||||||
pub fn agent_to_trip(&self, id: AgentID) -> Option<TripID> {
|
pub fn agent_to_trip(&self, id: AgentID) -> Option<TripID> {
|
||||||
self.active_trip_mode.get(&id).map(|id| *id)
|
self.active_trip_mode.get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_active_trips(&self) -> Vec<TripID> {
|
pub fn get_active_trips(&self) -> Vec<TripID> {
|
||||||
self.active_trip_mode.values().map(|id| *id).collect()
|
self.active_trip_mode.values().cloned().collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,14 +455,7 @@ impl WalkingSimState {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
Action::KeepPreparingBike => {
|
Action::KeepPreparingBike => {
|
||||||
let state = self
|
let state = self.peds[&id].bike_parking.as_ref().unwrap().clone();
|
||||||
.peds
|
|
||||||
.get(&id)
|
|
||||||
.unwrap()
|
|
||||||
.bike_parking
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
|
||||||
if (now - state.started_at).as_time() >= TIME_TO_PREPARE_BIKE {
|
if (now - state.started_at).as_time() >= TIME_TO_PREPARE_BIKE {
|
||||||
if state.is_parking {
|
if state.is_parking {
|
||||||
// Now they'll start walking somewhere
|
// Now they'll start walking somewhere
|
||||||
@ -687,7 +680,7 @@ impl WalkingSimState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn ped_tooltip(&self, id: PedestrianID) -> Vec<String> {
|
pub fn ped_tooltip(&self, id: PedestrianID) -> Vec<String> {
|
||||||
let p = self.peds.get(&id).unwrap();
|
let p = &self.peds[&id];
|
||||||
vec![format!("{} is part of {}", p.id, p.trip)]
|
vec![format!("{} is part of {}", p.id, p.trip)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ impl GUI<Text> for UI {
|
|||||||
State::LabelingBuilding(id, ref mut wizard) => {
|
State::LabelingBuilding(id, ref mut wizard) => {
|
||||||
if let Some(label) = wizard.wrap(&mut input).input_string_prefilled(
|
if let Some(label) = wizard.wrap(&mut input).input_string_prefilled(
|
||||||
"Label the building",
|
"Label the building",
|
||||||
self.model.get_b_label(id).unwrap_or("".to_string()),
|
self.model.get_b_label(id).unwrap_or_else(String::new),
|
||||||
) {
|
) {
|
||||||
self.model.set_b_label(id, label);
|
self.model.set_b_label(id, label);
|
||||||
self.state = State::Viewing;
|
self.state = State::Viewing;
|
||||||
@ -72,7 +72,7 @@ impl GUI<Text> for UI {
|
|||||||
State::LabelingRoad(pair, ref mut wizard) => {
|
State::LabelingRoad(pair, ref mut wizard) => {
|
||||||
if let Some(label) = wizard.wrap(&mut input).input_string_prefilled(
|
if let Some(label) = wizard.wrap(&mut input).input_string_prefilled(
|
||||||
"Label this side of the road",
|
"Label this side of the road",
|
||||||
self.model.get_r_label(pair).unwrap_or("".to_string()),
|
self.model.get_r_label(pair).unwrap_or_else(String::new),
|
||||||
) {
|
) {
|
||||||
self.model.set_r_label(pair, label);
|
self.model.set_r_label(pair, label);
|
||||||
self.state = State::Viewing;
|
self.state = State::Viewing;
|
||||||
|
@ -2,6 +2,7 @@ use crate::runner::TestRunner;
|
|||||||
use geom::{line_intersection, Line, PolyLine, Pt2D};
|
use geom::{line_intersection, Line, PolyLine, Pt2D};
|
||||||
use rand;
|
use rand;
|
||||||
|
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
pub fn run(t: &mut TestRunner) {
|
pub fn run(t: &mut TestRunner) {
|
||||||
t.run_fast(
|
t.run_fast(
|
||||||
"dist_along_horiz_line",
|
"dist_along_horiz_line",
|
||||||
|
Loading…
Reference in New Issue
Block a user