mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
round of rustfmt after 1.27 upgrade
This commit is contained in:
parent
0e6111e86a
commit
2ebc13140b
@ -2,8 +2,8 @@ extern crate serde;
|
||||
extern crate serde_cbor;
|
||||
extern crate serde_json;
|
||||
|
||||
use serde::Serialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use std::fs::File;
|
||||
use std::io::{Error, ErrorKind, Read, Write};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use ezgui::GfxCtx;
|
||||
use ezgui::canvas::Canvas;
|
||||
use ezgui::input::UserInput;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{PolyLine, Pt2D};
|
||||
use graphics;
|
||||
use graphics::types::Color;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use ezgui::GfxCtx;
|
||||
use ezgui::input::UserInput;
|
||||
use ezgui::GfxCtx;
|
||||
use piston::window::Size;
|
||||
|
||||
pub trait GUI {
|
||||
|
@ -1,10 +1,10 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use colors::{ColorScheme, Colors};
|
||||
use ezgui::GfxCtx;
|
||||
use ezgui::canvas::Canvas;
|
||||
use ezgui::input::UserInput;
|
||||
use ezgui::menu;
|
||||
use ezgui::GfxCtx;
|
||||
use graphics;
|
||||
use piston::input::{Key, MouseCursorEvent};
|
||||
use std::str::FromStr;
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
use colors::{ColorScheme, Colors};
|
||||
use control::ControlMap;
|
||||
use ezgui::GfxCtx;
|
||||
use ezgui::canvas::Canvas;
|
||||
use ezgui::input::UserInput;
|
||||
use ezgui::GfxCtx;
|
||||
use graphics::types::Color;
|
||||
use map_model;
|
||||
use map_model::{BuildingID, IntersectionID, Map, RoadID, TurnID};
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use colors::{ColorScheme, Colors};
|
||||
use control::ControlMap;
|
||||
use control::stop_signs::TurnPriority;
|
||||
use control::ControlMap;
|
||||
use ezgui::input::UserInput;
|
||||
use graphics::types::Color;
|
||||
use map_model::IntersectionID;
|
||||
|
@ -46,9 +46,10 @@ impl DrawBuilding {
|
||||
|
||||
pub fn tooltip_lines(&self, map: &Map) -> Vec<String> {
|
||||
let b = map.get_b(self.id);
|
||||
let mut lines = vec![
|
||||
format!("Building #{:?} (from OSM way {})", self.id, b.osm_way_id),
|
||||
];
|
||||
let mut lines = vec![format!(
|
||||
"Building #{:?} (from OSM way {})",
|
||||
self.id, b.osm_way_id
|
||||
)];
|
||||
for (k, v) in &b.osm_tags {
|
||||
lines.push(format!("{} = {}", k, v));
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// 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::QuadTree;
|
||||
use geom::{LonLat, Pt2D};
|
||||
use map_model::{BuildingID, IntersectionID, Map, ParcelID, RoadID, TurnID};
|
||||
use plugins::selection::Hider;
|
||||
|
@ -8,10 +8,12 @@ use graphics;
|
||||
use graphics::math::Vec2d;
|
||||
use graphics::types::Color;
|
||||
use map_model;
|
||||
use map_model::TurnID;
|
||||
use map_model::geometry;
|
||||
use render::{BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH, TURN_ICON_ARROW_THICKNESS,
|
||||
TURN_ICON_ARROW_TIP_LENGTH};
|
||||
use map_model::TurnID;
|
||||
use render::{
|
||||
BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH, TURN_ICON_ARROW_THICKNESS,
|
||||
TURN_ICON_ARROW_TIP_LENGTH,
|
||||
};
|
||||
use std::f64;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -6,10 +6,10 @@ use abstutil;
|
||||
use colors::{ColorScheme, Colors};
|
||||
use control::ControlMap;
|
||||
use control::{ModifiedStopSign, ModifiedTrafficSignal};
|
||||
use ezgui::GfxCtx;
|
||||
use ezgui::ToggleableLayer;
|
||||
use ezgui::canvas::Canvas;
|
||||
use ezgui::input::UserInput;
|
||||
use ezgui::GfxCtx;
|
||||
use ezgui::ToggleableLayer;
|
||||
use graphics::types::Color;
|
||||
use gui;
|
||||
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 {
|
||||
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
|
||||
{
|
||||
let item = self.mouseover_something();
|
||||
|
@ -1,12 +1,13 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use GfxCtx;
|
||||
use aabb_quadtree::geom::{Point, Rect};
|
||||
use graphics::Transformed;
|
||||
use piston::input::{Button, Event, MouseButton, MouseCursorEvent, MouseScrollEvent, PressEvent,
|
||||
ReleaseEvent};
|
||||
use piston::input::{
|
||||
Button, Event, MouseButton, MouseCursorEvent, MouseScrollEvent, PressEvent, ReleaseEvent,
|
||||
};
|
||||
use piston::window::Size;
|
||||
use text;
|
||||
use GfxCtx;
|
||||
|
||||
const ZOOM_SPEED: f64 = 0.05;
|
||||
//const PAN_SPEED: f64 = 10.0;
|
||||
|
@ -1,9 +1,9 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use GfxCtx;
|
||||
use graphics;
|
||||
use graphics::types::Color;
|
||||
use graphics::{Image, Transformed};
|
||||
use GfxCtx;
|
||||
|
||||
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];
|
||||
|
@ -5,7 +5,7 @@ use map_model;
|
||||
use quick_xml::events::Event;
|
||||
use quick_xml::reader::Reader;
|
||||
use std::fs::File;
|
||||
use std::{io, f64};
|
||||
use std::{f64, io};
|
||||
|
||||
pub fn load(
|
||||
path: &String,
|
||||
|
@ -135,7 +135,7 @@ fn lane_specs_for((side1_types, side2_types): (Vec<LaneType>, Vec<LaneType>)) ->
|
||||
|
||||
fn make_offsets(idx: isize, len: isize) -> Vec<isize> {
|
||||
let mut offsets = Vec::new();
|
||||
for i in 0 .. len {
|
||||
for i in 0..len {
|
||||
if i != idx {
|
||||
offsets.push(i - idx);
|
||||
}
|
||||
@ -146,21 +146,13 @@ fn make_offsets(idx: isize, len: isize) -> Vec<isize> {
|
||||
#[test]
|
||||
fn offsets() {
|
||||
let no_offsets: Vec<isize> = Vec::new();
|
||||
assert_eq!(
|
||||
make_offsets(0, 1),
|
||||
no_offsets);
|
||||
assert_eq!(make_offsets(0, 1), no_offsets);
|
||||
|
||||
assert_eq!(
|
||||
make_offsets(0, 3),
|
||||
vec![1, 2]);
|
||||
assert_eq!(make_offsets(0, 3), vec![1, 2]);
|
||||
|
||||
assert_eq!(
|
||||
make_offsets(1, 3),
|
||||
vec![-1, 1]);
|
||||
assert_eq!(make_offsets(1, 3), vec![-1, 1]);
|
||||
|
||||
assert_eq!(
|
||||
make_offsets(2, 3),
|
||||
vec![-2, -1]);
|
||||
assert_eq!(make_offsets(2, 3), vec![-2, -1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2,8 +2,8 @@ use dimensioned::si;
|
||||
use geom::Line;
|
||||
use intersection::Intersection;
|
||||
use road::{Road, RoadID};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub(crate) fn trim_lines(roads: &mut Vec<Road>, i: &Intersection) {
|
||||
let mut shortest_first_line: HashMap<RoadID, (Line, si::Meter<f64>)> = HashMap::new();
|
||||
|
@ -9,7 +9,7 @@ use intersection::{Intersection, IntersectionID};
|
||||
use make;
|
||||
use parcel::{Parcel, ParcelID};
|
||||
use raw_data;
|
||||
use road::{Road, RoadID, LaneType};
|
||||
use road::{LaneType, Road, RoadID};
|
||||
use std::collections::HashMap;
|
||||
use std::io::Error;
|
||||
use turn::{Turn, TurnID};
|
||||
@ -66,8 +66,10 @@ impl Map {
|
||||
counter += 1;
|
||||
let other_side = lane.offset_for_other_id
|
||||
.map(|offset| RoadID(((id.0 as isize) + offset) as usize));
|
||||
let siblings = lane.offsets_for_siblings.iter()
|
||||
.map(|offset| RoadID(((id.0 as isize) + offset) as usize)).collect();
|
||||
let siblings = lane.offsets_for_siblings
|
||||
.iter()
|
||||
.map(|offset| RoadID(((id.0 as isize) + offset) as usize))
|
||||
.collect();
|
||||
|
||||
let mut unshifted_pts = PolyLine::new(
|
||||
r.points
|
||||
@ -234,12 +236,18 @@ impl Map {
|
||||
let r = self.get_r(parking);
|
||||
assert_eq!(r.lane_type, LaneType::Parking);
|
||||
// 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> {
|
||||
let r = self.get_r(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)
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use IntersectionID;
|
||||
use dimensioned::si;
|
||||
use geom::{Angle, Line, PolyLine, Pt2D};
|
||||
use std;
|
||||
use std::collections::HashMap;
|
||||
use std::f64;
|
||||
use std::fmt;
|
||||
use IntersectionID;
|
||||
|
||||
const PARKING_SPOT_LENGTH: si::Meter<f64> = si::Meter {
|
||||
// TODO look up a real value
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use IntersectionID;
|
||||
use RoadID;
|
||||
use dimensioned::si;
|
||||
use geom::{Angle, Line, Pt2D};
|
||||
use std::f64;
|
||||
use std::fmt;
|
||||
use IntersectionID;
|
||||
use RoadID;
|
||||
|
||||
// TODO reconsider pub usize. maybe outside world shouldnt know.
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
|
@ -1,12 +1,12 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use CarID;
|
||||
use driving::{Car, On};
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Angle, Pt2D};
|
||||
use graphics;
|
||||
use graphics::math::Vec2d;
|
||||
use map_model::{geometry, Map};
|
||||
use CarID;
|
||||
|
||||
const CAR_WIDTH: f64 = 2.0;
|
||||
const CAR_LENGTH: f64 = 4.5;
|
||||
|
@ -6,9 +6,9 @@ use draw_car::DrawCar;
|
||||
use geom::{Angle, Pt2D};
|
||||
use intersections::{IntersectionPolicy, StopSign, TrafficSignal};
|
||||
use map_model;
|
||||
use rand::Rng;
|
||||
use map_model::{Map, RoadID, TurnID, LaneType};
|
||||
use map_model::{LaneType, Map, RoadID, TurnID};
|
||||
use multimap::MultiMap;
|
||||
use rand::Rng;
|
||||
use std;
|
||||
use std::collections::{BTreeMap, HashSet, VecDeque};
|
||||
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
|
||||
// road (from a building), so just ignore this problem for now.
|
||||
// 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) {
|
||||
// TODO car should enter Unparking state and wait for room
|
||||
println!("No room for {} to start driving on {}", car, start);
|
||||
|
@ -1,7 +1,7 @@
|
||||
// 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::ControlMap;
|
||||
use dimensioned::si;
|
||||
use map_model::{IntersectionID, Map, TurnID};
|
||||
use std::collections::HashMap;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use CarID;
|
||||
use map_model::{LaneType, Map, Road, RoadID};
|
||||
use rand::Rng;
|
||||
use std::iter;
|
||||
use CarID;
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub(crate) struct ParkingSimState {
|
||||
@ -20,7 +20,12 @@ impl ParkingSimState {
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
let mut total_capacity = 0;
|
||||
@ -75,11 +80,17 @@ impl ParkingLane {
|
||||
}
|
||||
|
||||
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) {
|
||||
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));
|
||||
self.spots[idx] = None;
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ use dimensioned::si;
|
||||
use draw_car::DrawCar;
|
||||
use driving::DrivingSimState;
|
||||
use map_model::{LaneType, Map, RoadID, TurnID};
|
||||
use rand::{FromEntropy, Rng, SeedableRng, XorShiftRng};
|
||||
use parking::ParkingSimState;
|
||||
use rand::{FromEntropy, Rng, SeedableRng, XorShiftRng};
|
||||
use std::f64;
|
||||
use std::time::{Duration, Instant};
|
||||
use {CarID, Tick};
|
||||
@ -48,11 +48,13 @@ impl Sim {
|
||||
}
|
||||
|
||||
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) {
|
||||
let mut driving_lanes: Vec<RoadID> = map.all_roads().iter()
|
||||
let mut driving_lanes: Vec<RoadID> = map.all_roads()
|
||||
.iter()
|
||||
.filter_map(|r| {
|
||||
if r.lane_type == LaneType::Driving && self.driving_state.roads[r.id.0].is_empty() {
|
||||
Some(r.id)
|
||||
@ -101,7 +103,13 @@ impl Sim {
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
true
|
||||
|
Loading…
Reference in New Issue
Block a user