clippy pt2

This commit is contained in:
Dustin Carlino 2018-12-08 18:25:05 -08:00
parent ab86835611
commit f48757c5e7
39 changed files with 179 additions and 209 deletions

View File

@ -5,6 +5,7 @@ touch `find * | grep '\.rs' | grep -v target | xargs`
# TODO Remove all of these exceptions
cargo clippy -- \
-A clippy::cyclomatic_complexity \
-A clippy::expect_fun_call \
-A clippy::if_same_then_else \
-A clippy::needless_pass_by_value \
@ -13,4 +14,6 @@ cargo clippy -- \
-A clippy::new_without_default_derive \
-A clippy::ptr_arg \
-A clippy::suspicious_arithmetic_impl \
-A clippy::type_complexity
-A clippy::too_many_arguments \
-A clippy::type_complexity \
-A clippy::wrong_self_convention

View File

@ -53,7 +53,7 @@ fn convert_polygon(input: PolygonType, name: String, map_name: String, gps_bound
}
}
NeighborhoodBuilder {
map_name: map_name,
map_name,
name,
points,
}

View File

@ -60,7 +60,7 @@ fn panel(ctx: &mut PluginCtx) -> State {
// TODO More coloring
txt.add_line(ctx.primary.sim.get_name().to_string());
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());
summarize(&mut txt, s.sim.get_score());
} else {

View File

@ -81,14 +81,12 @@ impl Plugin for TimeTravel {
} else if ctx.input.key_pressed(Key::Return, "exit time traveler") {
self.current_tick = None;
}
} else {
if ctx
} else if ctx
.input
.unimportant_key_pressed(Key::T, SIM, "start time traveling")
{
self.current_tick = Some(ctx.primary.sim.time);
}
}
if let Some(tick) = self.current_tick {
ctx.hints.osd.add_line(format!("Time traveling: {}", tick));

View File

@ -123,7 +123,7 @@ impl<'a> GfxCtx<'a> {
pub fn draw_polygon(&mut self, color: Color, poly: &geom::Polygon) {
for tri in &poly.triangles {
graphics::Polygon::new(color.0).draw(
&vec![
&[
[tri.pt1.x(), tri.pt1.y()],
[tri.pt2.x(), tri.pt2.y()],
[tri.pt3.x(), tri.pt3.y()],

View File

@ -87,7 +87,7 @@ impl Text {
.iter()
.max_by_key(|l| l.iter().fold(0, |so_far, span| so_far + span.text.len()))
.unwrap();
let mut concat = String::from("");
let mut concat = String::new();
for span in longest_line {
concat.push_str(&span.text);
}

View File

@ -17,7 +17,7 @@ impl TextBox {
pub fn new(prompt: &str, prefilled: Option<String>) -> TextBox {
TextBox {
prompt: prompt.to_string(),
line: prefilled.unwrap_or(String::from("")),
line: prefilled.unwrap_or_else(String::new),
cursor_x: 0,
shift_pressed: false,
}

View File

@ -21,7 +21,7 @@ impl TreeMenu {
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);
}
}
@ -43,10 +43,10 @@ fn print(depth: usize, tree: &BTreeMap<String, Item>, f: &mut fmt::Formatter) ->
for (name, item) in tree {
match item {
Item::Action(key) => {
writeln!(f, "{}- {} ({})", pad, name, describe_maybe_key(key))?;
writeln!(f, "{}- {} ({})", pad, name, describe_maybe_key(*key))?;
}
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)?;
}
}
@ -54,10 +54,10 @@ fn print(depth: usize, tree: &BTreeMap<String, Item>, f: &mut fmt::Formatter) ->
Ok(())
}
fn describe_maybe_key(key: &Option<Key>) -> String {
fn describe_maybe_key(key: Option<Key>) -> String {
match key {
Some(k) => describe_key(*k),
None => "".to_string(),
Some(k) => describe_key(k),
None => String::new(),
}
}

View File

@ -131,11 +131,11 @@ impl<'a> WrappedWizard<'a> {
}
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> {
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> {

View File

@ -165,7 +165,7 @@ impl PolyLine {
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
// 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 {
result.push(l1.pt1());
@ -226,7 +226,7 @@ impl PolyLine {
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
// 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 {
result.push(l1.pt1());

View File

@ -58,7 +58,7 @@ impl Intersection {
self.incoming_lanes
.iter()
.filter(|l| map.get_l(**l).lane_type == lt)
.map(|l| *l)
.cloned()
.collect()
}
@ -66,7 +66,7 @@ impl Intersection {
self.outgoing_lanes
.iter()
.filter(|l| map.get_l(**l).lane_type == lt)
.map(|l| *l)
.cloned()
.collect()
}

View File

@ -52,7 +52,7 @@ pub fn make_all_buildings(
osm_way_id: input[idx].osm_way_id,
front_path: FrontPath {
bldg: id,
sidewalk: sidewalk_pos.clone(),
sidewalk: *sidewalk_pos,
line,
},
});

View File

@ -76,7 +76,7 @@ pub fn make_bus_stops(
let stops: Vec<BusStopID> = stop_points
.iter()
.filter_map(|pt| point_to_stop_id.get(pt))
.map(|stop| *stop)
.cloned()
.collect();
if stops.len() < 2 {
warn!(

View File

@ -143,7 +143,6 @@ pub fn intersection_polygon(i: &Intersection, roads: &Vec<Road>) -> Vec<Pt2D> {
}
// Close off the polygon
let first_pt = endpoints[0].clone();
endpoints.push(first_pt);
endpoints.push(endpoints[0]);
endpoints
}

View File

@ -34,7 +34,7 @@ pub fn find_sidewalk_points(
timer.next();
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) {
results.insert(query_pt.into(), Position::new(sidewalk, dist_along));
results.insert(query_pt, Position::new(sidewalk, dist_along));
} 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);
}

View File

@ -318,7 +318,7 @@ fn make_vehicle_turn(map: &Map, i: IntersectionID, l1: LaneID, l2: LaneID) -> Tu
let pieces = 5;
PolyLine::new(
(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(),
)
};

View File

@ -172,7 +172,7 @@ impl Map {
// TODO probably different behavior for oneways
// 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
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) {
Some(pts) => (pts, false),
// TODO wasteful to calculate again, but eh
@ -465,7 +465,7 @@ impl Map {
}
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.
@ -668,8 +668,7 @@ impl Map {
} else if let Some(ts) = self.traffic_signals.get(&t.parent) {
ts.cycles
.iter()
.find(|c| c.get_priority(t) != TurnPriority::Banned)
.is_some()
.any(|c| c.get_priority(t) != TurnPriority::Banned)
} else {
// Border nodes have no turns...
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
.incoming_lanes
.iter()
.find(|l| map.get_l(**l).is_driving())
.is_some();
.any(|l| map.get_l(*l).is_driving());
let has_driving_out = intersection
.outgoing_lanes
.iter()
.find(|l| map.get_l(**l).is_driving())
.is_some();
.any(|l| map.get_l(*l).is_driving());
has_driving_in != has_driving_out
}

View File

@ -230,7 +230,7 @@ impl Path {
}
}
return Some(pts_so_far.unwrap());
Some(pts_so_far.unwrap())
}
pub fn get_steps(&self) -> &VecDeque<PathStep> {
@ -285,7 +285,7 @@ impl Pathfinder {
steps.last().unwrap().as_traversable(),
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.
@ -435,12 +435,13 @@ impl Pathfinder {
// Expand
for next in self.expand(map, current).into_iter() {
if !backrefs.contains_key(&next) {
backrefs.insert(next, current);
backrefs.entry(next).or_insert_with(|| {
let cost = next.cost(map);
let heuristic = next.heuristic(self.goal_pt, map);
queue.push((dist_to_pri_queue(cost + heuristic) + cost_sofar, next));
}
current
});
}
}

View File

@ -52,17 +52,11 @@ impl Road {
}
pub fn is_forwards(&self, lane: LaneID) -> bool {
self.children_forwards
.iter()
.find(|(id, _)| *id == lane)
.is_some()
self.children_forwards.iter().any(|(id, _)| *id == lane)
}
pub fn is_backwards(&self, lane: LaneID) -> bool {
self.children_backwards
.iter()
.find(|(id, _)| *id == lane)
.is_some()
self.children_backwards.iter().any(|(id, _)| *id == lane)
}
// lane must belong to this road. Offset 0 is the centermost lane on each side of a road, then

View File

@ -55,52 +55,52 @@ pub enum Traversable {
impl Traversable {
pub fn as_lane(&self) -> LaneID {
match self {
&Traversable::Lane(id) => id,
&Traversable::Turn(_) => panic!("not a lane"),
match *self {
Traversable::Lane(id) => id,
Traversable::Turn(_) => panic!("not a lane"),
}
}
pub fn as_turn(&self) -> TurnID {
match self {
&Traversable::Turn(id) => id,
&Traversable::Lane(_) => panic!("not a turn"),
match *self {
Traversable::Turn(id) => id,
Traversable::Lane(_) => panic!("not a turn"),
}
}
pub fn maybe_turn(&self) -> Option<TurnID> {
match self {
&Traversable::Turn(id) => Some(id),
&Traversable::Lane(_) => None,
match *self {
Traversable::Turn(id) => Some(id),
Traversable::Lane(_) => None,
}
}
pub fn maybe_lane(&self) -> Option<LaneID> {
match self {
&Traversable::Turn(_) => None,
&Traversable::Lane(id) => Some(id),
match *self {
Traversable::Turn(_) => None,
Traversable::Lane(id) => Some(id),
}
}
// TODO Just expose the PolyLine instead of all these layers of helpers
pub fn length(&self, map: &Map) -> si::Meter<f64> {
match self {
&Traversable::Lane(id) => map.get_l(id).length(),
&Traversable::Turn(id) => map.get_t(id).length(),
match *self {
Traversable::Lane(id) => map.get_l(id).length(),
Traversable::Turn(id) => map.get_t(id).length(),
}
}
pub fn dist_along(&self, dist: si::Meter<f64>, map: &Map) -> (Pt2D, Angle) {
match self {
&Traversable::Lane(id) => map.get_l(id).dist_along(dist),
&Traversable::Turn(id) => map.get_t(id).dist_along(dist),
match *self {
Traversable::Lane(id) => map.get_l(id).dist_along(dist),
Traversable::Turn(id) => map.get_t(id).dist_along(dist),
}
}
pub fn speed_limit(&self, map: &Map) -> si::MeterPerSecond<f64> {
match self {
&Traversable::Lane(id) => map.get_parent(id).get_speed_limit(),
&Traversable::Turn(id) => map.get_parent(id.dst).get_speed_limit(),
match *self {
Traversable::Lane(id) => map.get_parent(id).get_speed_limit(),
Traversable::Turn(id) => map.get_parent(id.dst).get_speed_limit(),
}
}
}

View File

@ -5,6 +5,7 @@ use geom::{PolyLine, Pt2D};
// Copied from map_model; no need to have to rebuild that crate
const LANE_THICKNESS: f64 = 2.5;
#[allow(clippy::unreadable_literal)]
pub fn run(g: &mut GfxCtx) {
let thin = 0.25;
let shift1_width = LANE_THICKNESS * 0.5;

View File

@ -2,6 +2,7 @@ use crate::common::BLUE;
use ezgui::GfxCtx;
use geom::{Polygon, Pt2D};
#[allow(clippy::unreadable_literal)]
pub fn run(g: &mut GfxCtx, labels: &mut Vec<(Pt2D, String)>) {
let pts = vec![
Pt2D::new(1158.5480421283125, 759.4168710122531), // 0

View File

@ -2,6 +2,7 @@ use crate::common::{draw_polyline, BLACK, RED};
use ezgui::GfxCtx;
use geom::{PolyLine, Pt2D};
#[allow(clippy::unreadable_literal)]
pub fn run(g: &mut GfxCtx, labels: &mut Vec<(Pt2D, String)>) {
let thin = 1.0;
let width = 50.0;

View File

@ -2,6 +2,7 @@ use crate::common::{draw_polyline, BLUE, GREEN, RED};
use ezgui::GfxCtx;
use geom::{Circle, PolyLine, Pt2D};
#[allow(clippy::unreadable_literal)]
pub fn run(g: &mut GfxCtx) {
let mut vertical_pl = PolyLine::new(vec![
Pt2D::new(1333.9512635794777, 413.3946082988369),

View File

@ -185,7 +185,8 @@ impl Car {
parking_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;
// If our lookahead doesn't even hit the intersection / early stopping point, then
@ -614,7 +615,7 @@ impl DrivingSimState {
}
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)));
}
self.cars.remove(&id);
@ -822,7 +823,7 @@ impl DrivingSimState {
if let Some(queue) = self.queues.get(&on) {
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> {

View File

@ -175,10 +175,7 @@ impl Sim {
self.spawner.start_trip_using_parked_car(
Tick::zero(),
map,
self.parking_state
.lookup_car(car)
.map(|p| p.clone())
.unwrap(),
self.parking_state.lookup_car(car).cloned().unwrap(),
&self.parking_state,
from_bldg,
DrivingGoal::ParkNear(to_bldg),

View File

@ -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
// doesn't work in --release mode, so use that.
let symbol_name = f.symbols()[0].name();
if !symbol_name.is_some() {
if symbol_name.is_none() {
return;
}
@ -30,12 +30,10 @@ pub fn capture_backtrace(event: &str) {
if name == "sim::sim::Sim::inner_step" {
break;
}
} else {
if name.ends_with("::capture_backtrace") {
} else if name.ends_with("::capture_backtrace") {
found_this_fxn = true;
}
}
}
BACKTRACES.lock().unwrap().insert(calls);
}

View File

@ -51,13 +51,11 @@ impl IntersectionSimState {
let mut intersections: Vec<IntersectionPolicy> = Vec::new();
for i in map.all_intersections() {
intersections.push(match i.intersection_type {
IntersectionType::StopSign => {
IntersectionPolicy::StopSignPolicy(StopSign::new(i.id))
}
IntersectionType::StopSign => IntersectionPolicy::StopSign(StopSign::new(i.id)),
IntersectionType::TrafficSignal => {
IntersectionPolicy::TrafficSignalPolicy(TrafficSignal::new(i.id))
IntersectionPolicy::TrafficSignal(TrafficSignal::new(i.id))
}
IntersectionType::Border => IntersectionPolicy::BorderPolicy,
IntersectionType::Border => IntersectionPolicy::Border,
});
}
IntersectionSimState {
@ -78,31 +76,29 @@ impl IntersectionSimState {
// 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.
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) {
return;
}
match i {
IntersectionPolicy::StopSignPolicy(ref mut p) => {
IntersectionPolicy::StopSign(ref mut p) => {
if !p.started_waiting_at.contains_key(&req) {
p.approaching_agents.insert(req);
}
}
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => {
IntersectionPolicy::TrafficSignal(ref mut p) => {
p.requests.insert(req);
}
IntersectionPolicy::BorderPolicy => {}
IntersectionPolicy::Border => {}
}
}
pub fn step(&mut self, events: &mut Vec<Event>, time: Tick, map: &Map, view: &WorldView) {
for i in self.intersections.iter_mut() {
match i {
IntersectionPolicy::StopSignPolicy(ref mut p) => p.step(events, time, map, view),
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => {
p.step(events, time, map, view)
}
IntersectionPolicy::BorderPolicy => {}
IntersectionPolicy::StopSign(ref mut p) => p.step(events, time, map, view),
IntersectionPolicy::TrafficSignal(ref mut p) => p.step(events, time, map, view),
IntersectionPolicy::Border => {}
}
}
}
@ -116,16 +112,16 @@ impl IntersectionSimState {
}
Ok(())
} else {
return Err(Error::new(format!(
Err(Error::new(format!(
"{:?} entered, but wasn't accepted by the intersection yet",
req
)));
)))
}
}
pub fn on_exit(&mut self, req: Request) {
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));
i.on_exit(&req);
if self.debug == Some(id) {
@ -135,28 +131,28 @@ impl IntersectionSimState {
pub fn debug(&mut self, id: IntersectionID, map: &Map) {
if let Some(old) = self.debug {
match self.intersections.get_mut(old.0).unwrap() {
IntersectionPolicy::StopSignPolicy(ref mut p) => {
match self.intersections[old.0] {
IntersectionPolicy::StopSign(ref mut p) => {
p.debug = false;
}
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => {
IntersectionPolicy::TrafficSignal(ref mut p) => {
p.debug = false;
}
IntersectionPolicy::BorderPolicy => {}
IntersectionPolicy::Border => {}
};
}
println!("{}", abstutil::to_json(&self.intersections[id.0]));
match self.intersections.get_mut(id.0).unwrap() {
IntersectionPolicy::StopSignPolicy(ref mut p) => {
match self.intersections[id.0] {
IntersectionPolicy::StopSign(ref mut p) => {
p.debug = true;
println!("{}", abstutil::to_json(map.get_stop_sign(id)));
}
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => {
IntersectionPolicy::TrafficSignal(ref mut p) => {
p.debug = true;
println!("{}", abstutil::to_json(map.get_traffic_signal(id)));
}
IntersectionPolicy::BorderPolicy => {
IntersectionPolicy::Border => {
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.
#[derive(Serialize, Deserialize, PartialEq)]
enum IntersectionPolicy {
StopSignPolicy(StopSign),
TrafficSignalPolicy(TrafficSignal),
BorderPolicy,
StopSign(StopSign),
TrafficSignal(TrafficSignal),
Border,
}
impl IntersectionPolicy {
fn is_accepted(&self, req: &Request) -> bool {
match self {
IntersectionPolicy::StopSignPolicy(ref p) => p.accepted.contains(req),
IntersectionPolicy::TrafficSignalPolicy(ref p) => p.accepted.contains(req),
IntersectionPolicy::BorderPolicy => true,
IntersectionPolicy::StopSign(ref p) => p.accepted.contains(req),
IntersectionPolicy::TrafficSignal(ref p) => p.accepted.contains(req),
IntersectionPolicy::Border => true,
}
}
fn on_exit(&mut self, req: &Request) {
match self {
IntersectionPolicy::StopSignPolicy(ref mut p) => p.accepted.remove(&req),
IntersectionPolicy::TrafficSignalPolicy(ref mut p) => p.accepted.remove(&req),
IntersectionPolicy::BorderPolicy => {
IntersectionPolicy::StopSign(ref mut p) => p.accepted.remove(&req),
IntersectionPolicy::TrafficSignal(ref mut p) => p.accepted.remove(&req),
IntersectionPolicy::Border => {
panic!("{:?} called on_exit for a border node; how?!", req);
}
};
@ -225,8 +221,7 @@ impl StopSign {
let base_t = map.get_t(turn);
self.accepted
.iter()
.find(|req| base_t.conflicts_with(map.get_t(req.turn)))
.is_some()
.any(|req| base_t.conflicts_with(map.get_t(req.turn)))
}
fn conflicts_with_waiting_with_higher_priority(
@ -237,13 +232,9 @@ impl StopSign {
) -> bool {
let base_t = map.get_t(turn);
let base_priority = ss.get_priority(turn);
self.started_waiting_at
.keys()
.find(|req| {
base_t.conflicts_with(map.get_t(req.turn))
&& ss.get_priority(req.turn) > base_priority
self.started_waiting_at.keys().any(|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) {
@ -379,8 +370,7 @@ impl TrafficSignal {
let base_t = map.get_t(req.turn);
if priority_requests
.iter()
.find(|t| base_t.conflicts_with(map.get_t(**t)))
.is_some()
.any(|t| base_t.conflicts_with(map.get_t(*t)))
{
keep_requests.insert(req.clone());
continue;
@ -407,7 +397,6 @@ impl TrafficSignal {
let base_t = map.get_t(turn);
self.accepted
.iter()
.find(|req| base_t.conflicts_with(map.get_t(req.turn)))
.is_some()
.any(|req| base_t.conflicts_with(map.get_t(req.turn)))
}
}

View File

@ -8,7 +8,7 @@ use serde_derive::{Deserialize, Serialize};
use std;
pub const EPSILON_SPEED: Speed = si::MeterPerSecond {
value_unsafe: 0.00000001,
value_unsafe: 0.000_000_01,
_marker: std::marker::PhantomData,
};

View File

@ -15,7 +15,7 @@ pub struct ABTest {
impl ABTest {
pub fn describe(&self) -> Vec<String> {
abstutil::to_json(self)
.split("\n")
.split('\n')
.map(|s| s.to_string())
.collect()
}

View File

@ -56,7 +56,7 @@ pub struct SeedParkedCars {
impl Scenario {
pub fn describe(&self) -> Vec<String> {
abstutil::to_json(self)
.split("\n")
.split('\n')
.map(|s| s.to_string())
.collect()
}
@ -153,8 +153,7 @@ impl Scenario {
&mut sim.rng,
);
}
} else {
if let Some(goal) =
} else if let Some(goal) =
s.goal
.pick_walking_goal(map, &bldgs_per_neighborhood, &mut sim.rng)
{
@ -191,7 +190,6 @@ impl Scenario {
}
}
}
}
for s in &self.border_spawn_over_time {
if let Some(start) = SidewalkSpot::start_at_border(s.start_from_border, map) {

View File

@ -29,7 +29,7 @@ impl ParkingSimState {
pub fn edit_remove_lane(&mut self, id: LaneID) {
assert!(self.lanes[id.0].is_empty());
self.lanes[id.0] = ParkingLane {
id: id,
id,
spots: Vec::new(),
occupants: Vec::new(),
};
@ -90,8 +90,8 @@ impl ParkingSimState {
id: p.car,
vehicle_length: p.vehicle.length,
waiting_for_turn: None,
front: front,
angle: angle,
front,
angle,
stopping_trace: None,
state: CarState::Parked,
vehicle_type: VehicleType::Car,
@ -224,7 +224,7 @@ impl ParkingLane {
}
fn is_empty(&self) -> bool {
!self.occupants.iter().find(|x| x.is_some()).is_some()
!self.occupants.iter().any(|x| x.is_some())
}
}

View File

@ -20,7 +20,7 @@ pub type Acceleration = si::MeterPerSecond2<f64>;
pub struct Tick(u32);
impl Tick {
pub fn as_usize(&self) -> usize {
pub fn as_usize(self) -> usize {
self.0 as usize
}
@ -42,14 +42,14 @@ impl Tick {
// TODO Why have these two forms? Consolidate
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() {
return None;
}
let mut ticks: u32 = 0;
if parts.last().unwrap().contains(".") {
let last_parts: Vec<&str> = parts.last().unwrap().split(".").collect();
if parts.last().unwrap().contains('.') {
let last_parts: Vec<&str> = parts.last().unwrap().split('.').collect();
if last_parts.len() != 2 {
return None;
}
@ -87,8 +87,8 @@ impl Tick {
Some(Tick(hours + minutes + seconds + ms))
}
pub fn as_time(&self) -> Time {
(self.0 as f64) * TIMESTEP
pub fn as_time(self) -> Time {
f64::from(self.0) * TIMESTEP
}
pub fn next(self) -> Tick {
@ -99,11 +99,11 @@ impl Tick {
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
}
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. :\
let ticks_per_second = 10;
let ticks_per_minute = 60 * ticks_per_second;
@ -112,14 +112,14 @@ impl Tick {
let hours = self.0 / ticks_per_hour;
let mut remainder = self.0 % ticks_per_hour;
let minutes = remainder / ticks_per_minute;
remainder = remainder % ticks_per_minute;
remainder %= ticks_per_minute;
let seconds = remainder / ticks_per_second;
remainder = remainder % ticks_per_second;
remainder %= ticks_per_second;
(hours, minutes, seconds, remainder)
}
pub fn as_filename(&self) -> String {
pub fn as_filename(self) -> String {
let (hours, minutes, seconds, remainder) = self.get_parts();
format!(
"{0:02}h{1:02}m{2:02}.{3}s",

View File

@ -312,7 +312,7 @@ impl Sim {
pub fn load_most_recent(&self) -> Result<Sim, std::io::Error> {
let (_, load) = self
.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);
abstutil::read_json(&load)
}

View File

@ -188,7 +188,7 @@ impl Spawner {
now,
CreateCar {
car,
trip: trip,
trip,
owner: parked_car.owner,
maybe_parked_car: Some(parked_car.clone()),
vehicle: parked_car.vehicle.clone(),
@ -216,7 +216,7 @@ impl Spawner {
now,
CreateCar {
car,
trip: trip,
trip,
// TODO need a way to specify this in the scenario
owner: None,
maybe_parked_car: None,
@ -247,7 +247,7 @@ impl Spawner {
now,
CreateCar {
car: vehicle.id,
trip: trip,
trip,
owner: None,
maybe_parked_car: None,
vehicle: vehicle.clone(),

View File

@ -208,15 +208,12 @@ impl TripManager {
spawned_at,
finished_at: None,
ped,
uses_car: legs
.iter()
.find(|l| match l {
uses_car: legs.iter().any(|l| match l {
TripLeg::Drive(_, _) => true,
TripLeg::DriveFromBorder(_, _) => true,
TripLeg::ServeBusRoute(_, _) => true,
_ => false,
})
.is_some(),
}),
legs: VecDeque::from(legs),
});
id
@ -226,7 +223,7 @@ impl TripManager {
pub fn get_trip_using_car(&self, car: CarID) -> Option<TripID> {
self.trips
.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)
}
@ -292,11 +289,11 @@ impl TripManager {
// This will be None for parked cars
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> {
self.active_trip_mode.values().map(|id| *id).collect()
self.active_trip_mode.values().cloned().collect()
}
}

View File

@ -455,14 +455,7 @@ impl WalkingSimState {
});
}
Action::KeepPreparingBike => {
let state = self
.peds
.get(&id)
.unwrap()
.bike_parking
.as_ref()
.unwrap()
.clone();
let state = self.peds[&id].bike_parking.as_ref().unwrap().clone();
if (now - state.started_at).as_time() >= TIME_TO_PREPARE_BIKE {
if state.is_parking {
// Now they'll start walking somewhere
@ -687,7 +680,7 @@ impl WalkingSimState {
}
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)]
}

View File

@ -61,7 +61,7 @@ impl GUI<Text> for UI {
State::LabelingBuilding(id, ref mut wizard) => {
if let Some(label) = wizard.wrap(&mut input).input_string_prefilled(
"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.state = State::Viewing;
@ -72,7 +72,7 @@ impl GUI<Text> for UI {
State::LabelingRoad(pair, ref mut wizard) => {
if let Some(label) = wizard.wrap(&mut input).input_string_prefilled(
"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.state = State::Viewing;

View File

@ -2,6 +2,7 @@ use crate::runner::TestRunner;
use geom::{line_intersection, Line, PolyLine, Pt2D};
use rand;
#[allow(clippy::unreadable_literal)]
pub fn run(t: &mut TestRunner) {
t.run_fast(
"dist_along_horiz_line",