mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
filling in more validity checks for map_editor...
This commit is contained in:
parent
b11f33f7f6
commit
67fb1b39da
@ -33,12 +33,12 @@ impl UI {
|
||||
fn new(ctx: &EventCtx) -> UI {
|
||||
let mut args = CmdArgs::new();
|
||||
let load = args.optional_free();
|
||||
let exclude_bldgs = args.enabled("--nobldgs");
|
||||
let include_bldgs = args.enabled("--bldgs");
|
||||
let edit_fixes = args.optional("--fixes");
|
||||
args.done();
|
||||
|
||||
let model = if let Some(path) = load {
|
||||
Model::import(&path, exclude_bldgs, edit_fixes, ctx.prerender)
|
||||
Model::import(&path, include_bldgs, edit_fixes, ctx.prerender)
|
||||
} else {
|
||||
Model::blank()
|
||||
};
|
||||
|
@ -23,7 +23,7 @@ pub struct Model {
|
||||
// TODO Not sure this should be pub...
|
||||
pub showing_pts: Option<StableRoadID>,
|
||||
|
||||
exclude_bldgs: bool,
|
||||
include_bldgs: bool,
|
||||
fixes: MapFixes,
|
||||
edit_fixes: Option<String>,
|
||||
world: World<ID>,
|
||||
@ -36,7 +36,7 @@ impl Model {
|
||||
map: RawMap::blank(String::new()),
|
||||
showing_pts: None,
|
||||
|
||||
exclude_bldgs: false,
|
||||
include_bldgs: false,
|
||||
fixes: MapFixes::new(),
|
||||
edit_fixes: None,
|
||||
world: World::new(&Bounds::new()),
|
||||
@ -45,13 +45,13 @@ impl Model {
|
||||
|
||||
pub fn import(
|
||||
path: &str,
|
||||
exclude_bldgs: bool,
|
||||
include_bldgs: bool,
|
||||
edit_fixes: Option<String>,
|
||||
prerender: &Prerender,
|
||||
) -> Model {
|
||||
let mut timer = Timer::new("import map");
|
||||
let mut model = Model::blank();
|
||||
model.exclude_bldgs = exclude_bldgs;
|
||||
model.include_bldgs = include_bldgs;
|
||||
model.edit_fixes = edit_fixes;
|
||||
model.map = read_binary(path, &mut timer).unwrap();
|
||||
|
||||
@ -64,7 +64,7 @@ impl Model {
|
||||
}
|
||||
|
||||
model.world = World::new(&model.compute_bounds());
|
||||
if !model.exclude_bldgs {
|
||||
if model.include_bldgs {
|
||||
for id in model.map.buildings.keys().cloned().collect::<Vec<_>>() {
|
||||
model.bldg_added(id, prerender);
|
||||
}
|
||||
@ -140,9 +140,7 @@ impl Model {
|
||||
}
|
||||
}
|
||||
for r in self.map.roads.values() {
|
||||
if r.osm_tags.get(osm::SYNTHETIC) == Some(&"true".to_string())
|
||||
&& !ignore_roads.contains(&r.orig_id)
|
||||
{
|
||||
if r.synthetic() && !ignore_roads.contains(&r.orig_id) {
|
||||
self.fixes.add_roads.push(r.clone());
|
||||
}
|
||||
}
|
||||
@ -171,7 +169,7 @@ impl Model {
|
||||
}
|
||||
|
||||
pub fn delete_everything_inside(&mut self, area: Polygon) {
|
||||
if !self.exclude_bldgs {
|
||||
if self.include_bldgs {
|
||||
for id in self.map.buildings.keys().cloned().collect::<Vec<_>>() {
|
||||
if area.contains_pt(self.map.buildings[&id].polygon.center()) {
|
||||
self.delete_b(id);
|
||||
@ -482,7 +480,7 @@ impl Model {
|
||||
}
|
||||
|
||||
let mut result = Vec::new();
|
||||
let synthetic = r.osm_tags.get(osm::SYNTHETIC) == Some(&"true".to_string());
|
||||
let synthetic = r.synthetic();
|
||||
let spec = r.get_spec();
|
||||
let center_pts = PolyLine::new(r.center_points.clone());
|
||||
for (idx, lt) in spec.fwd.iter().enumerate() {
|
||||
@ -600,7 +598,7 @@ impl Model {
|
||||
pub fn merge_r(&mut self, id: StableRoadID, prerender: &Prerender) {
|
||||
assert!(self.showing_pts != Some(id));
|
||||
|
||||
if !self.map.can_merge_short_road(id) {
|
||||
if !self.map.can_merge_short_road(id, &self.fixes) {
|
||||
println!("Can't merge this road; intersection types must differ or there must be synthetic stuff");
|
||||
return;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ impl RawMap {
|
||||
impl RawMap {
|
||||
pub fn delete_road(&mut self, r: StableRoadID, fixes: &mut MapFixes) {
|
||||
let road = self.roads.remove(&r).unwrap();
|
||||
if road.osm_tags.get(osm::SYNTHETIC) != Some(&"true".to_string()) {
|
||||
if !road.synthetic() {
|
||||
fixes.delete_roads.push(road.orig_id);
|
||||
}
|
||||
}
|
||||
@ -225,6 +225,7 @@ impl RawMap {
|
||||
}
|
||||
|
||||
pub fn create_intersection(&mut self, i: RawIntersection) -> Option<StableIntersectionID> {
|
||||
assert!(i.synthetic);
|
||||
if self
|
||||
.gps_bounds
|
||||
.contains(i.point.forcibly_to_gps(&self.gps_bounds))
|
||||
@ -238,6 +239,7 @@ impl RawMap {
|
||||
}
|
||||
|
||||
pub fn create_road(&mut self, mut r: RawRoad) -> Option<StableRoadID> {
|
||||
assert!(r.synthetic());
|
||||
match (
|
||||
self.find_i(OriginalIntersection {
|
||||
osm_node_id: r.orig_id.node1,
|
||||
@ -257,20 +259,23 @@ impl RawMap {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_merge_short_road(&self, id: StableRoadID) -> bool {
|
||||
pub fn can_merge_short_road(&self, id: StableRoadID, fixes: &MapFixes) -> bool {
|
||||
let road = &self.roads[&id];
|
||||
let it1 = self.intersections[&road.i1].intersection_type;
|
||||
let it2 = self.intersections[&road.i2].intersection_type;
|
||||
if it1 != it2 {
|
||||
let i1 = &self.intersections[&road.i1];
|
||||
let i2 = &self.intersections[&road.i2];
|
||||
if i1.intersection_type != i2.intersection_type {
|
||||
return false;
|
||||
}
|
||||
|
||||
for r in self.roads_per_intersection(road.i2) {
|
||||
if self.roads[&r].osm_tags.get(osm::SYNTHETIC) == Some(&"true".to_string()) {
|
||||
if self.roads[&r].synthetic() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if self.intersections[&road.i1].synthetic || self.intersections[&road.i2].synthetic {
|
||||
if i1.synthetic || i2.synthetic {
|
||||
return false;
|
||||
}
|
||||
if fixes.override_tags.contains_key(&road.orig_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -283,7 +288,7 @@ impl RawMap {
|
||||
id: StableRoadID,
|
||||
fixes: &mut MapFixes,
|
||||
) -> Option<(StableIntersectionID, Vec<StableRoadID>)> {
|
||||
assert!(self.can_merge_short_road(id));
|
||||
assert!(self.can_merge_short_road(id, fixes));
|
||||
let (i1, i2) = {
|
||||
let r = self.roads.remove(&id).unwrap();
|
||||
fixes.merge_short_roads.push(r.orig_id);
|
||||
@ -295,7 +300,6 @@ impl RawMap {
|
||||
};
|
||||
|
||||
// Arbitrarily keep i1 and destroy i2.
|
||||
// TODO Make sure intersection types are the same. Make sure i2 isn't synthetic.
|
||||
self.intersections.remove(&i2).unwrap();
|
||||
|
||||
// Fix up all roads connected to i2.
|
||||
@ -328,7 +332,7 @@ impl RawMap {
|
||||
) {
|
||||
let road = self.roads.get_mut(&r).unwrap();
|
||||
road.osm_tags = osm_tags;
|
||||
if road.osm_tags.get(osm::SYNTHETIC) != Some(&"true".to_string()) {
|
||||
if !road.synthetic() {
|
||||
fixes
|
||||
.override_tags
|
||||
.insert(road.orig_id, road.osm_tags.clone());
|
||||
@ -424,6 +428,10 @@ impl RawRoad {
|
||||
let (fwd, back) = get_lane_types(&self.osm_tags);
|
||||
RoadSpec { fwd, back }
|
||||
}
|
||||
|
||||
pub fn synthetic(&self) -> bool {
|
||||
self.osm_tags.get(osm::SYNTHETIC) == Some(&"true".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user