adding Areas to map and UI; not instantiating them yet

This commit is contained in:
Dustin Carlino 2018-09-16 09:07:36 -07:00
parent 99f73b7e3d
commit 966d7bb03d
5 changed files with 91 additions and 3 deletions

View File

@ -997,8 +997,11 @@ Alright, replan yet again.
= plugin trait, color(id) -> Option<Color>. parallel list of box plugins (or, a fxn that takes the idx)
= refactor to one color_blah method
= handle the two color things... just buildings?
= and see how much boilerplate a new type would need, by adding bus stops and water/parks
- load water/parks and stuff
- deal with overlapping keys that still kinda happen (sim ctrl, escape game)
- bug: do need to recalculate current_selection whenever anything potentially changes camera, like follow
= and see how much boilerplate a new type would need, by adding bus stops and water/parks
- consider merging control map into map
- see how hard it is to render textures onto cars or something
- refactor debug and tooltip lines for objects

42
map_model/src/area.rs Normal file
View File

@ -0,0 +1,42 @@
use abstutil;
use geom::{PolyLine, Pt2D};
use std::collections::BTreeMap;
use std::fmt;
// TODO reconsider pub usize. maybe outside world shouldnt know.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct AreaID(pub usize);
impl fmt::Display for AreaID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "AreaID({0})", self.0)
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub enum AreaType {
Park,
Water,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Area {
pub id: AreaID,
pub area_type: AreaType,
pub points: Vec<Pt2D>,
pub osm_tags: BTreeMap<String, String>,
pub osm_way_id: i64,
}
impl PartialEq for Area {
fn eq(&self, other: &Area) -> bool {
self.id == other.id
}
}
impl Area {
pub fn dump_debug(&self) {
println!("{}", abstutil::to_json(self));
println!("{}", PolyLine::new(self.points.clone()));
}
}

View File

@ -13,6 +13,7 @@ extern crate serde;
#[macro_use]
extern crate serde_derive;
mod area;
mod building;
mod bus_stop;
mod edits;
@ -27,6 +28,7 @@ pub mod raw_data;
mod road;
mod turn;
pub use area::{Area, AreaID, AreaType};
pub use building::{Building, BuildingID, FrontPath};
pub use bus_stop::{BusRoute, BusStop, BusStopID};
pub use edits::{EditReason, Edits};

View File

@ -11,8 +11,8 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::io::Error;
use std::path;
use {
Building, BuildingID, BusRoute, BusStop, BusStopID, Intersection, IntersectionID, Lane, LaneID,
LaneType, Parcel, ParcelID, Road, RoadID, Turn, TurnID,
Area, AreaID, Building, BuildingID, BusRoute, BusStop, BusStopID, Intersection, IntersectionID,
Lane, LaneID, LaneType, Parcel, ParcelID, Road, RoadID, Turn, TurnID,
};
#[derive(Serialize, Deserialize, Debug)]
@ -25,6 +25,7 @@ pub struct Map {
parcels: Vec<Parcel>,
bus_stops: BTreeMap<BusStopID, BusStop>,
bus_routes: Vec<BusRoute>,
areas: Vec<Area>,
// TODO maybe dont need to retain GPS stuff later
bounds: Bounds,
@ -65,6 +66,7 @@ impl Map {
parcels: Vec::new(),
bus_stops: BTreeMap::new(),
bus_routes: Vec::new(),
areas: Vec::new(),
};
let mut pt_to_intersection: HashMap<HashablePt2D, IntersectionID> = HashMap::new();
@ -195,6 +197,20 @@ impl Map {
});
}
for (idx, a) in data.areas.iter().enumerate() {
m.areas.push(Area {
id: AreaID(idx),
area_type: a.area_type,
points: a
.points
.iter()
.map(|coord| Pt2D::from_gps(coord, &bounds))
.collect(),
osm_tags: a.osm_tags.clone(),
osm_way_id: a.osm_way_id,
});
}
m
}
@ -243,6 +259,10 @@ impl Map {
&self.parcels
}
pub fn all_areas(&self) -> &Vec<Area> {
&self.areas
}
pub fn maybe_get_r(&self, id: RoadID) -> Option<&Road> {
self.roads.get(id.0)
}
@ -291,6 +311,10 @@ impl Map {
&self.parcels[id.0]
}
pub fn get_a(&self, id: AreaID) -> &Area {
&self.areas[id.0]
}
// All these helpers should take IDs and return objects.
pub fn get_source_intersection(&self, l: LaneID) -> &Intersection {

View File

@ -2,6 +2,7 @@ use dimensioned::si;
use geom::{Bounds, HashablePt2D, LonLat};
use gtfs::Route;
use std::collections::BTreeMap;
use AreaType;
#[derive(PartialEq, Debug, Serialize, Deserialize)]
pub struct Map {
@ -10,6 +11,7 @@ pub struct Map {
pub buildings: Vec<Building>,
pub parcels: Vec<Parcel>,
pub bus_routes: Vec<Route>,
pub areas: Vec<Area>,
pub coordinates_in_world_space: bool,
}
@ -22,6 +24,7 @@ impl Map {
buildings: Vec::new(),
parcels: Vec::new(),
bus_routes: Vec::new(),
areas: Vec::new(),
coordinates_in_world_space: false,
}
}
@ -42,6 +45,11 @@ impl Map {
bounds.update_coord(pt);
}
}
for a in &self.areas {
for pt in &a.points {
bounds.update_coord(pt);
}
}
for p in &self.parcels {
for pt in &p.points {
bounds.update_coord(pt);
@ -86,6 +94,15 @@ pub struct Building {
pub osm_way_id: i64,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct Area {
pub area_type: AreaType,
// last point is always the same as the first
pub points: Vec<LonLat>,
pub osm_tags: BTreeMap<String, String>,
pub osm_way_id: i64,
}
#[derive(PartialEq, Debug, Serialize, Deserialize)]
pub struct Parcel {
// last point never the first?