round of rustfmt after 1.27 upgrade

This commit is contained in:
Dustin Carlino 2018-07-09 12:30:59 -07:00
parent 0e6111e86a
commit 2ebc13140b
23 changed files with 87 additions and 56 deletions

View File

@ -2,8 +2,8 @@ extern crate serde;
extern crate serde_cbor; extern crate serde_cbor;
extern crate serde_json; extern crate serde_json;
use serde::Serialize;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize;
use std::fs::File; use std::fs::File;
use std::io::{Error, ErrorKind, Read, Write}; use std::io::{Error, ErrorKind, Read, Write};

View File

@ -1,6 +1,6 @@
use ezgui::GfxCtx;
use ezgui::canvas::Canvas; use ezgui::canvas::Canvas;
use ezgui::input::UserInput; use ezgui::input::UserInput;
use ezgui::GfxCtx;
use geom::{PolyLine, Pt2D}; use geom::{PolyLine, Pt2D};
use graphics; use graphics;
use graphics::types::Color; use graphics::types::Color;

View File

@ -1,5 +1,5 @@
use ezgui::GfxCtx;
use ezgui::input::UserInput; use ezgui::input::UserInput;
use ezgui::GfxCtx;
use piston::window::Size; use piston::window::Size;
pub trait GUI { pub trait GUI {

View File

@ -1,10 +1,10 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use colors::{ColorScheme, Colors}; use colors::{ColorScheme, Colors};
use ezgui::GfxCtx;
use ezgui::canvas::Canvas; use ezgui::canvas::Canvas;
use ezgui::input::UserInput; use ezgui::input::UserInput;
use ezgui::menu; use ezgui::menu;
use ezgui::GfxCtx;
use graphics; use graphics;
use piston::input::{Key, MouseCursorEvent}; use piston::input::{Key, MouseCursorEvent};
use std::str::FromStr; use std::str::FromStr;

View File

@ -2,9 +2,9 @@
use colors::{ColorScheme, Colors}; use colors::{ColorScheme, Colors};
use control::ControlMap; use control::ControlMap;
use ezgui::GfxCtx;
use ezgui::canvas::Canvas; use ezgui::canvas::Canvas;
use ezgui::input::UserInput; use ezgui::input::UserInput;
use ezgui::GfxCtx;
use graphics::types::Color; use graphics::types::Color;
use map_model; use map_model;
use map_model::{BuildingID, IntersectionID, Map, RoadID, TurnID}; use map_model::{BuildingID, IntersectionID, Map, RoadID, TurnID};

View File

@ -1,8 +1,8 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use colors::{ColorScheme, Colors}; use colors::{ColorScheme, Colors};
use control::ControlMap;
use control::stop_signs::TurnPriority; use control::stop_signs::TurnPriority;
use control::ControlMap;
use ezgui::input::UserInput; use ezgui::input::UserInput;
use graphics::types::Color; use graphics::types::Color;
use map_model::IntersectionID; use map_model::IntersectionID;

View File

@ -46,9 +46,10 @@ impl DrawBuilding {
pub fn tooltip_lines(&self, map: &Map) -> Vec<String> { pub fn tooltip_lines(&self, map: &Map) -> Vec<String> {
let b = map.get_b(self.id); let b = map.get_b(self.id);
let mut lines = vec![ let mut lines = vec![format!(
format!("Building #{:?} (from OSM way {})", self.id, b.osm_way_id), "Building #{:?} (from OSM way {})",
]; self.id, b.osm_way_id
)];
for (k, v) in &b.osm_tags { for (k, v) in &b.osm_tags {
lines.push(format!("{} = {}", k, v)); lines.push(format!("{} = {}", k, v));
} }

View File

@ -1,7 +1,7 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use aabb_quadtree::QuadTree;
use aabb_quadtree::geom::{Point, Rect}; use aabb_quadtree::geom::{Point, Rect};
use aabb_quadtree::QuadTree;
use geom::{LonLat, Pt2D}; use geom::{LonLat, Pt2D};
use map_model::{BuildingID, IntersectionID, Map, ParcelID, RoadID, TurnID}; use map_model::{BuildingID, IntersectionID, Map, ParcelID, RoadID, TurnID};
use plugins::selection::Hider; use plugins::selection::Hider;

View File

@ -8,10 +8,12 @@ use graphics;
use graphics::math::Vec2d; use graphics::math::Vec2d;
use graphics::types::Color; use graphics::types::Color;
use map_model; use map_model;
use map_model::TurnID;
use map_model::geometry; use map_model::geometry;
use render::{BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH, TURN_ICON_ARROW_THICKNESS, use map_model::TurnID;
TURN_ICON_ARROW_TIP_LENGTH}; use render::{
BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH, TURN_ICON_ARROW_THICKNESS,
TURN_ICON_ARROW_TIP_LENGTH,
};
use std::f64; use std::f64;
#[derive(Debug)] #[derive(Debug)]

View File

@ -6,10 +6,10 @@ use abstutil;
use colors::{ColorScheme, Colors}; use colors::{ColorScheme, Colors};
use control::ControlMap; use control::ControlMap;
use control::{ModifiedStopSign, ModifiedTrafficSignal}; use control::{ModifiedStopSign, ModifiedTrafficSignal};
use ezgui::GfxCtx;
use ezgui::ToggleableLayer;
use ezgui::canvas::Canvas; use ezgui::canvas::Canvas;
use ezgui::input::UserInput; use ezgui::input::UserInput;
use ezgui::GfxCtx;
use ezgui::ToggleableLayer;
use graphics::types::Color; use graphics::types::Color;
use gui; use gui;
use map_model; use map_model;
@ -336,7 +336,8 @@ impl gui::GUI for UI {
if old_zoom >= MIN_ZOOM_FOR_MOUSEOVER && new_zoom < MIN_ZOOM_FOR_MOUSEOVER { if old_zoom >= MIN_ZOOM_FOR_MOUSEOVER && new_zoom < MIN_ZOOM_FOR_MOUSEOVER {
self.current_selection_state = SelectionState::Empty; self.current_selection_state = SelectionState::Empty;
} }
if !self.canvas.is_dragging() && input.use_event_directly().mouse_cursor_args().is_some() if !self.canvas.is_dragging()
&& input.use_event_directly().mouse_cursor_args().is_some()
&& new_zoom >= MIN_ZOOM_FOR_MOUSEOVER && new_zoom >= MIN_ZOOM_FOR_MOUSEOVER
{ {
let item = self.mouseover_something(); let item = self.mouseover_something();

View File

@ -1,12 +1,13 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use GfxCtx;
use aabb_quadtree::geom::{Point, Rect}; use aabb_quadtree::geom::{Point, Rect};
use graphics::Transformed; use graphics::Transformed;
use piston::input::{Button, Event, MouseButton, MouseCursorEvent, MouseScrollEvent, PressEvent, use piston::input::{
ReleaseEvent}; Button, Event, MouseButton, MouseCursorEvent, MouseScrollEvent, PressEvent, ReleaseEvent,
};
use piston::window::Size; use piston::window::Size;
use text; use text;
use GfxCtx;
const ZOOM_SPEED: f64 = 0.05; const ZOOM_SPEED: f64 = 0.05;
//const PAN_SPEED: f64 = 10.0; //const PAN_SPEED: f64 = 10.0;

View File

@ -1,9 +1,9 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use GfxCtx;
use graphics; use graphics;
use graphics::types::Color; use graphics::types::Color;
use graphics::{Image, Transformed}; use graphics::{Image, Transformed};
use GfxCtx;
const TEXT_FG_COLOR: Color = [0.0, 0.0, 0.0, 1.0]; const TEXT_FG_COLOR: Color = [0.0, 0.0, 0.0, 1.0];
const TEXT_BG_COLOR: Color = [0.0, 1.0, 0.0, 0.5]; const TEXT_BG_COLOR: Color = [0.0, 1.0, 0.0, 0.5];

View File

@ -5,7 +5,7 @@ use map_model;
use quick_xml::events::Event; use quick_xml::events::Event;
use quick_xml::reader::Reader; use quick_xml::reader::Reader;
use std::fs::File; use std::fs::File;
use std::{io, f64}; use std::{f64, io};
pub fn load( pub fn load(
path: &String, path: &String,

View File

@ -146,21 +146,13 @@ fn make_offsets(idx: isize, len: isize) -> Vec<isize> {
#[test] #[test]
fn offsets() { fn offsets() {
let no_offsets: Vec<isize> = Vec::new(); let no_offsets: Vec<isize> = Vec::new();
assert_eq!( assert_eq!(make_offsets(0, 1), no_offsets);
make_offsets(0, 1),
no_offsets);
assert_eq!( assert_eq!(make_offsets(0, 3), vec![1, 2]);
make_offsets(0, 3),
vec![1, 2]);
assert_eq!( assert_eq!(make_offsets(1, 3), vec![-1, 1]);
make_offsets(1, 3),
vec![-1, 1]);
assert_eq!( assert_eq!(make_offsets(2, 3), vec![-2, -1]);
make_offsets(2, 3),
vec![-2, -1]);
} }
#[test] #[test]

View File

@ -2,8 +2,8 @@ use dimensioned::si;
use geom::Line; use geom::Line;
use intersection::Intersection; use intersection::Intersection;
use road::{Road, RoadID}; use road::{Road, RoadID};
use std::collections::HashMap;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::HashMap;
pub(crate) fn trim_lines(roads: &mut Vec<Road>, i: &Intersection) { pub(crate) fn trim_lines(roads: &mut Vec<Road>, i: &Intersection) {
let mut shortest_first_line: HashMap<RoadID, (Line, si::Meter<f64>)> = HashMap::new(); let mut shortest_first_line: HashMap<RoadID, (Line, si::Meter<f64>)> = HashMap::new();

View File

@ -9,7 +9,7 @@ use intersection::{Intersection, IntersectionID};
use make; use make;
use parcel::{Parcel, ParcelID}; use parcel::{Parcel, ParcelID};
use raw_data; use raw_data;
use road::{Road, RoadID, LaneType}; use road::{LaneType, Road, RoadID};
use std::collections::HashMap; use std::collections::HashMap;
use std::io::Error; use std::io::Error;
use turn::{Turn, TurnID}; use turn::{Turn, TurnID};
@ -66,8 +66,10 @@ impl Map {
counter += 1; counter += 1;
let other_side = lane.offset_for_other_id let other_side = lane.offset_for_other_id
.map(|offset| RoadID(((id.0 as isize) + offset) as usize)); .map(|offset| RoadID(((id.0 as isize) + offset) as usize));
let siblings = lane.offsets_for_siblings.iter() let siblings = lane.offsets_for_siblings
.map(|offset| RoadID(((id.0 as isize) + offset) as usize)).collect(); .iter()
.map(|offset| RoadID(((id.0 as isize) + offset) as usize))
.collect();
let mut unshifted_pts = PolyLine::new( let mut unshifted_pts = PolyLine::new(
r.points r.points
@ -234,12 +236,18 @@ impl Map {
let r = self.get_r(parking); let r = self.get_r(parking);
assert_eq!(r.lane_type, LaneType::Parking); assert_eq!(r.lane_type, LaneType::Parking);
// TODO find the closest one to the parking lane, if there are multiple // TODO find the closest one to the parking lane, if there are multiple
r.siblings.iter().find(|&&id| self.get_r(id).lane_type == LaneType::Driving).map(|id| *id) r.siblings
.iter()
.find(|&&id| self.get_r(id).lane_type == LaneType::Driving)
.map(|id| *id)
} }
pub fn find_parking_lane(&self, driving: RoadID) -> Option<RoadID> { pub fn find_parking_lane(&self, driving: RoadID) -> Option<RoadID> {
let r = self.get_r(driving); let r = self.get_r(driving);
assert_eq!(r.lane_type, LaneType::Driving); assert_eq!(r.lane_type, LaneType::Driving);
r.siblings.iter().find(|&&id| self.get_r(id).lane_type == LaneType::Parking).map(|id| *id) r.siblings
.iter()
.find(|&&id| self.get_r(id).lane_type == LaneType::Parking)
.map(|id| *id)
} }
} }

View File

@ -1,12 +1,12 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use IntersectionID;
use dimensioned::si; use dimensioned::si;
use geom::{Angle, Line, PolyLine, Pt2D}; use geom::{Angle, Line, PolyLine, Pt2D};
use std; use std;
use std::collections::HashMap; use std::collections::HashMap;
use std::f64; use std::f64;
use std::fmt; use std::fmt;
use IntersectionID;
const PARKING_SPOT_LENGTH: si::Meter<f64> = si::Meter { const PARKING_SPOT_LENGTH: si::Meter<f64> = si::Meter {
// TODO look up a real value // TODO look up a real value

View File

@ -1,11 +1,11 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use IntersectionID;
use RoadID;
use dimensioned::si; use dimensioned::si;
use geom::{Angle, Line, Pt2D}; use geom::{Angle, Line, Pt2D};
use std::f64; use std::f64;
use std::fmt; use std::fmt;
use IntersectionID;
use RoadID;
// TODO reconsider pub usize. maybe outside world shouldnt know. // TODO reconsider pub usize. maybe outside world shouldnt know.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]

View File

@ -1,12 +1,12 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use CarID;
use driving::{Car, On}; use driving::{Car, On};
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::{Angle, Pt2D}; use geom::{Angle, Pt2D};
use graphics; use graphics;
use graphics::math::Vec2d; use graphics::math::Vec2d;
use map_model::{geometry, Map}; use map_model::{geometry, Map};
use CarID;
const CAR_WIDTH: f64 = 2.0; const CAR_WIDTH: f64 = 2.0;
const CAR_LENGTH: f64 = 4.5; const CAR_LENGTH: f64 = 4.5;

View File

@ -6,9 +6,9 @@ use draw_car::DrawCar;
use geom::{Angle, Pt2D}; use geom::{Angle, Pt2D};
use intersections::{IntersectionPolicy, StopSign, TrafficSignal}; use intersections::{IntersectionPolicy, StopSign, TrafficSignal};
use map_model; use map_model;
use rand::Rng; use map_model::{LaneType, Map, RoadID, TurnID};
use map_model::{Map, RoadID, TurnID, LaneType};
use multimap::MultiMap; use multimap::MultiMap;
use rand::Rng;
use std; use std;
use std::collections::{BTreeMap, HashSet, VecDeque}; use std::collections::{BTreeMap, HashSet, VecDeque};
use std::f64; use std::f64;
@ -400,7 +400,14 @@ impl DrivingSimState {
// beginning of the road. later, we want cars starting at arbitrary points in the middle of the // beginning of the road. later, we want cars starting at arbitrary points in the middle of the
// road (from a building), so just ignore this problem for now. // road (from a building), so just ignore this problem for now.
// True if we spawned one // True if we spawned one
pub fn start_car_on_road<R: Rng + ?Sized>(&mut self, time: Tick, start: RoadID, car: CarID, map: &Map, rng: &mut R) -> bool { pub fn start_car_on_road<R: Rng + ?Sized>(
&mut self,
time: Tick,
start: RoadID,
car: CarID,
map: &Map,
rng: &mut R,
) -> bool {
if !self.roads[start.0].room_at_end(time, &self.cars) { if !self.roads[start.0].room_at_end(time, &self.cars) {
// TODO car should enter Unparking state and wait for room // TODO car should enter Unparking state and wait for room
println!("No room for {} to start driving on {}", car, start); println!("No room for {} to start driving on {}", car, start);

View File

@ -1,7 +1,7 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use control::ControlMap;
use control::stop_signs::{ControlStopSign, TurnPriority}; use control::stop_signs::{ControlStopSign, TurnPriority};
use control::ControlMap;
use dimensioned::si; use dimensioned::si;
use map_model::{IntersectionID, Map, TurnID}; use map_model::{IntersectionID, Map, TurnID};
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -1,7 +1,7 @@
use CarID;
use map_model::{LaneType, Map, Road, RoadID}; use map_model::{LaneType, Map, Road, RoadID};
use rand::Rng; use rand::Rng;
use std::iter; use std::iter;
use CarID;
#[derive(Serialize, Deserialize, PartialEq, Eq)] #[derive(Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct ParkingSimState { pub(crate) struct ParkingSimState {
@ -20,7 +20,12 @@ impl ParkingSimState {
} }
// Kind of vague whether this should handle existing spots or not // Kind of vague whether this should handle existing spots or not
pub(crate) fn seed_random_cars<R: Rng + ?Sized>(&mut self, rng: &mut R, percent_capacity_to_fill: f64, id_counter: &mut usize) { pub(crate) fn seed_random_cars<R: Rng + ?Sized>(
&mut self,
rng: &mut R,
percent_capacity_to_fill: f64,
id_counter: &mut usize,
) {
assert!(percent_capacity_to_fill >= 0.0 && percent_capacity_to_fill <= 1.0); assert!(percent_capacity_to_fill >= 0.0 && percent_capacity_to_fill <= 1.0);
let mut total_capacity = 0; let mut total_capacity = 0;
@ -75,11 +80,17 @@ impl ParkingLane {
} }
fn get_last_parked_car(&self) -> Option<CarID> { fn get_last_parked_car(&self) -> Option<CarID> {
self.spots.iter().rfind(|&&x| x.is_some()).map(|r| r.unwrap()) self.spots
.iter()
.rfind(|&&x| x.is_some())
.map(|r| r.unwrap())
} }
fn remove_last_parked_car(&mut self, car: CarID) { fn remove_last_parked_car(&mut self, car: CarID) {
let idx = self.spots.iter().rposition(|&x| x.is_some()).expect("No parked cars at all now"); let idx = self.spots
.iter()
.rposition(|&x| x.is_some())
.expect("No parked cars at all now");
assert_eq!(self.spots[idx], Some(car)); assert_eq!(self.spots[idx], Some(car));
self.spots[idx] = None; self.spots[idx] = None;
} }

View File

@ -5,8 +5,8 @@ use dimensioned::si;
use draw_car::DrawCar; use draw_car::DrawCar;
use driving::DrivingSimState; use driving::DrivingSimState;
use map_model::{LaneType, Map, RoadID, TurnID}; use map_model::{LaneType, Map, RoadID, TurnID};
use rand::{FromEntropy, Rng, SeedableRng, XorShiftRng};
use parking::ParkingSimState; use parking::ParkingSimState;
use rand::{FromEntropy, Rng, SeedableRng, XorShiftRng};
use std::f64; use std::f64;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use {CarID, Tick}; use {CarID, Tick};
@ -48,11 +48,13 @@ impl Sim {
} }
pub fn seed_parked_cars(&mut self, percent: f64) { pub fn seed_parked_cars(&mut self, percent: f64) {
self.parking_state.seed_random_cars(&mut self.rng, percent, &mut self.id_counter) self.parking_state
.seed_random_cars(&mut self.rng, percent, &mut self.id_counter)
} }
pub fn start_many_parked_cars(&mut self, map: &Map, num_cars: usize) { pub fn start_many_parked_cars(&mut self, map: &Map, num_cars: usize) {
let mut driving_lanes: Vec<RoadID> = map.all_roads().iter() let mut driving_lanes: Vec<RoadID> = map.all_roads()
.iter()
.filter_map(|r| { .filter_map(|r| {
if r.lane_type == LaneType::Driving && self.driving_state.roads[r.id.0].is_empty() { if r.lane_type == LaneType::Driving && self.driving_state.roads[r.id.0].is_empty() {
Some(r.id) Some(r.id)
@ -101,7 +103,13 @@ impl Sim {
}; };
if let Some(car) = self.parking_state.get_last_parked_car(parking_lane) { if let Some(car) = self.parking_state.get_last_parked_car(parking_lane) {
if self.driving_state.start_car_on_road(self.time, driving_lane, car, map, &mut self.rng) { if self.driving_state.start_car_on_road(
self.time,
driving_lane,
car,
map,
&mut self.rng,
) {
self.parking_state.remove_last_parked_car(parking_lane, car); self.parking_state.remove_last_parked_car(parking_lane, car);
} }
true true