revamping MapFixes. very straightforward full override of synthetic/normal stuff, including geometry. no more semantically weird hints like merging roads. some bugs left.

This commit is contained in:
Dustin Carlino 2019-10-27 17:15:27 -07:00
parent 75e155fec6
commit ecc86b6d6a
8 changed files with 191 additions and 2769 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,469 +0,0 @@
{
"gps_bounds": {
"min_lon": -122.31036966897096,
"min_lat": 47.597290174872846,
"max_lon": -122.291527254181,
"max_lat": 47.65513966206871
},
"override_metadata": [
[
{
"osm_way_id": 6343960,
"node1": 246758543,
"node2": 53068959
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "6343960",
"highway": "residential",
"lanes": "2",
"maxspeed": "25 mph",
"name": "East Olive Street",
"oneway": "yes",
"surface": "asphalt"
},
[]
]
],
[
{
"osm_way_id": 92170540,
"node1": 53211694,
"node2": 53211693
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "92170540",
"highway": "secondary",
"lanes": "4",
"maxspeed": "30 mph",
"name": "23rd Avenue East",
"surface": "concrete"
},
[]
]
],
[
{
"osm_way_id": 243334881,
"node1": 53211693,
"node2": 53100545
},
[
{
"abst:endpt_back": "true",
"abst:osm_way_id": "243334881",
"abst:parking_lane_back": "true",
"abst:parking_lane_fwd": "true",
"highway": "residential",
"lanes": "2",
"maxspeed": "25 mph",
"name": "East Denny Way"
},
[]
]
],
[
{
"osm_way_id": 337739267,
"node1": 3448781094,
"node2": 3447973924
},
[
{
"abst:endpt_fwd": "true",
"abst:osm_way_id": "337739267",
"highway": "residential",
"lanes": "2",
"maxspeed": "25 mph",
"name": "20th Avenue",
"oneway": "yes",
"surface": "asphalt"
},
[]
]
],
[
{
"osm_way_id": 337739271,
"node1": 3447973929,
"node2": 246758543
},
[
{
"abst:endpt_fwd": "true",
"abst:osm_way_id": "337739271",
"highway": "residential",
"lanes": "2",
"maxspeed": "25 mph",
"name": "East Olive Street",
"oneway": "yes"
},
[]
]
],
[
{
"osm_way_id": 338701493,
"node1": 3458337321,
"node2": 53211693
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "338701493",
"highway": "residential",
"lanes": "2",
"maxspeed": "25 mph",
"name": "East Denny Way",
"oneway": "yes"
},
[]
]
],
[
{
"osm_way_id": 385214478,
"node1": 31429758,
"node2": 29464758
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "385214478",
"highway": "primary",
"lanes": "5",
"lanes:backward": "3",
"lanes:forward": "2",
"maxspeed": "30 mph",
"name": "Montlake Boulevard Northeast",
"old_ref": "SSH 1J",
"ref": "WA 513",
"shoulder": "no",
"sidewalk": "both",
"surface": "asphalt",
"turn:lanes:backward": "left|through|through"
},
[
[
"BanTurns",
{
"osm_way_id": 385214478,
"node1": 31429758,
"node2": 29464758
}
],
[
"BanTurns",
{
"osm_way_id": 499392305,
"node1": 32103268,
"node2": 31429758
}
],
[
"BanTurns",
{
"osm_way_id": 4910588,
"node1": 29464758,
"node2": 32103268
}
]
]
]
],
[
{
"osm_way_id": 537678339,
"node1": 3458337321,
"node2": 53211694
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "537678339",
"abst:parking_inferred": "true",
"highway": "secondary",
"lanes": "5",
"lanes:backward": "2",
"lanes:forward": "3",
"maxspeed": "30 mph",
"name": "East Madison Street",
"old_ref": "WA 513 (Old SSH 1J)",
"parking:lane:right": "no_parking",
"sidewalk": "both",
"turn:lanes:forward": "left||"
},
[]
]
]
],
"delete_roads": [
{
"osm_way_id": 92170540,
"node1": 53211694,
"node2": 53211693
},
{
"osm_way_id": 428235514,
"node1": 4273706425,
"node2": 3458337321
},
{
"osm_way_id": 243334881,
"node1": 53211693,
"node2": 53100545
},
{
"osm_way_id": 396055523,
"node1": 53211693,
"node2": 53068963
},
{
"osm_way_id": 337739271,
"node1": 3447973929,
"node2": 246758543
},
{
"osm_way_id": 6343960,
"node1": 246758543,
"node2": 53068959
},
{
"osm_way_id": 337818462,
"node1": 3448781094,
"node2": 3447973929
},
{
"osm_way_id": 337739267,
"node1": 3448781094,
"node2": 3447973924
},
{
"osm_way_id": 337739271,
"node1": 3447973924,
"node2": 3447973929
},
{
"osm_way_id": 337739269,
"node1": 246758543,
"node2": 53068961
},
{
"osm_way_id": 481291488,
"node1": 53168891,
"node2": 3447973924
},
{
"osm_way_id": 337739267,
"node1": 53068959,
"node2": 3448781094
},
{
"osm_way_id": 338701493,
"node1": 3458337321,
"node2": 53211693
}
],
"delete_intersections": [
{
"osm_node_id": 3447973929
},
{
"osm_node_id": 246758543
},
{
"osm_node_id": 3447973924
},
{
"osm_node_id": 3448781094
}
],
"add_intersections": [],
"add_roads": [
{
"i1": 431,
"i2": 356,
"center_points": [
{
"inner_x": 546.3455,
"inner_y": 4038.4176
},
{
"inner_x": 586.6938,
"inner_y": 3998.0761
}
],
"orig_id": {
"osm_way_id": -1569862944,
"node1": 4273706425,
"node2": 53211694
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569862944",
"abst:synthetic": "true",
"abst:synthetic_lanes": "ddps/ddps",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 356,
"i2": 473,
"center_points": [
{
"inner_x": 586.6938,
"inner_y": 3998.0761
},
{
"inner_x": 688.0182,
"inner_y": 4026.5086
}
],
"orig_id": {
"osm_way_id": -1569862946,
"node1": 53211694,
"node2": 53100545
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569862946",
"abst:synthetic": "true",
"abst:synthetic_lanes": "dps/dps",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 356,
"i2": 751,
"center_points": [
{
"inner_x": 586.6938,
"inner_y": 3998.0761
},
{
"inner_x": 584.4518,
"inner_y": 4228.3497
}
],
"orig_id": {
"osm_way_id": -1569862953,
"node1": 53211694,
"node2": 53068963
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569862953",
"abst:synthetic": "true",
"abst:synthetic_lanes": "dds/dds",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 70,
"i2": 31,
"center_points": [
{
"inner_x": 315.8406,
"inner_y": 4211.3591
},
{
"inner_x": 312.084,
"inner_y": 4431.1359
}
],
"orig_id": {
"osm_way_id": -1569863408,
"node1": 53068959,
"node2": 53168891
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569863408",
"abst:synthetic": "true",
"abst:synthetic_lanes": "dps/dps",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 70,
"i2": 68,
"center_points": [
{
"inner_x": 315.8406,
"inner_y": 4211.3591
},
{
"inner_x": 411.6012,
"inner_y": 4227.0376
}
],
"orig_id": {
"osm_way_id": -1569863411,
"node1": 53068959,
"node2": 53068961
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569863411",
"abst:synthetic": "true",
"abst:synthetic_lanes": "dps/dps",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
}
],
"merge_short_roads": [
{
"osm_way_id": 6460085,
"node1": 53211697,
"node2": 53211698
},
{
"osm_way_id": 486875123,
"node1": 246753651,
"node2": 53062805
},
{
"osm_way_id": 394736758,
"node1": 1726088135,
"node2": 53103988
},
{
"osm_way_id": 256996977,
"node1": 53139022,
"node2": 53224620
},
{
"osm_way_id": 6380913,
"node1": 53125309,
"node2": 53125310
},
{
"osm_way_id": 6507818,
"node1": 53144329,
"node2": 53144350
}
]
}

View File

@ -1,51 +0,0 @@
{
"gps_bounds": {
"min_lon": -122.33521557443338,
"min_lat": 47.605453088643266,
"max_lon": -122.28604060126838,
"max_lat": 47.65727694392701
},
"override_metadata": [],
"delete_roads": [
{
"osm_way_id": 160553203,
"node1": 60407342,
"node2": 1726088128
}
],
"delete_intersections": [],
"add_intersections": [],
"add_roads": [],
"merge_short_roads": [
{
"osm_way_id": 6521205,
"node1": 1758004075,
"node2": 53118266
},
{
"osm_way_id": 8071894,
"node1": 53110518,
"node2": 60407342
},
{
"osm_way_id": 462701470,
"node1": 53110518,
"node2": 1726088128
},
{
"osm_way_id": 6470834,
"node1": 4272388261,
"node2": 53110518
},
{
"osm_way_id": 428098986,
"node1": 4274312036,
"node2": 4272388261
},
{
"osm_way_id": 6457203,
"node1": 53209418,
"node2": 60799506
}
]
}

View File

@ -1,24 +0,0 @@
{
"gps_bounds": {
"min_lon": -122.3218,
"min_lat": 47.6315,
"max_lon": -122.2985,
"max_lat": 47.6475
},
"override_metadata": [],
"delete_roads": [
{
"osm_way_id": 6413596,
"node1": 1726081485,
"node2": 53149395
}
],
"delete_intersections": [
{
"osm_node_id": 1726081485
}
],
"add_intersections": [],
"add_roads": [],
"merge_short_roads": []
}

View File

@ -1,487 +0,0 @@
{
"gps_bounds": {
"min_lon": -122.3218,
"min_lat": 47.6315,
"max_lon": -122.2985,
"max_lat": 47.6475
},
"override_metadata": [
[
{
"osm_way_id": 394991043,
"node1": 3978753110,
"node2": 3978753097
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "394991043",
"bicycle": "designated",
"cycleway": "shared_lane",
"highway": "tertiary",
"lanes": "1",
"maxspeed": "30 mph",
"name": "Boyer Avenue East",
"oneway": "yes"
},
[]
]
],
[
{
"osm_way_id": 394991044,
"node1": 3978753107,
"node2": 3978753110
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "394991044",
"bicycle": "designated",
"cycleway": "shared_lane",
"highway": "tertiary",
"lanes": "1",
"maxspeed": "30 mph",
"name": "Boyer Avenue East",
"oneway": "yes"
},
[]
]
],
[
{
"osm_way_id": 394991045,
"node1": 3978753087,
"node2": 2499822233
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "394991045",
"abst:parking_lane_fwd": "true",
"bicycle": "designated",
"cycleway": "shared_lane",
"highway": "tertiary",
"lanes": "1",
"maxspeed": "30 mph",
"name": "Boyer Avenue East",
"oneway": "yes"
},
[]
]
],
[
{
"osm_way_id": 394991048,
"node1": 3978753110,
"node2": 3978753099
},
[
{
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "394991048",
"destination": "East Lynn Street",
"highway": "tertiary_link",
"lanes": "1",
"oneway": "yes"
},
[]
]
]
],
"delete_roads": [
{
"osm_way_id": 394991046,
"node1": 3978753099,
"node2": 3978753097
},
{
"osm_way_id": 394991045,
"node1": 3978753087,
"node2": 2499822233
},
{
"osm_way_id": 394991042,
"node1": 2499822233,
"node2": 3978753092
},
{
"osm_way_id": 394991047,
"node1": 3978753097,
"node2": 3978753087
},
{
"osm_way_id": 394991047,
"node1": 3978753087,
"node2": 3978753092
},
{
"osm_way_id": 394991043,
"node1": 3978753110,
"node2": 3978753097
},
{
"osm_way_id": 394991047,
"node1": 3978753107,
"node2": 3978753097
},
{
"osm_way_id": 394991047,
"node1": 3978753096,
"node2": 3978753105
},
{
"osm_way_id": 394991044,
"node1": 3978753107,
"node2": 3978753110
},
{
"osm_way_id": 394991048,
"node1": 3978753110,
"node2": 3978753099
},
{
"osm_way_id": 394991047,
"node1": 3978753095,
"node2": 3978753096
},
{
"osm_way_id": 394991047,
"node1": 3978753092,
"node2": 3978753095
},
{
"osm_way_id": 394991047,
"node1": 3978753105,
"node2": 3978753107
},
{
"osm_way_id": 158782115,
"node1": 1709142313,
"node2": 1709142595
},
{
"osm_way_id": 6495804,
"node1": 1709142595,
"node2": 53230466
},
{
"osm_way_id": 6495792,
"node1": 53214349,
"node2": 1709141381
},
{
"osm_way_id": 158782115,
"node1": 1709142353,
"node2": 1709141381
},
{
"osm_way_id": 158780999,
"node1": 1709142353,
"node2": 53096943
},
{
"osm_way_id": 158782115,
"node1": 1709142595,
"node2": 1709142353
},
{
"osm_way_id": 158782115,
"node1": 1709141381,
"node2": 1709141982
},
{
"osm_way_id": 158782115,
"node1": 1709141982,
"node2": 1709142313
}
],
"delete_intersections": [
{
"osm_node_id": 3978753087
},
{
"osm_node_id": 3978753097
},
{
"osm_node_id": 3978753096
},
{
"osm_node_id": 3978753092
},
{
"osm_node_id": 3978753107
},
{
"osm_node_id": 1709142353
},
{
"osm_node_id": 1709142595
},
{
"osm_node_id": 1709141381
},
{
"osm_node_id": 1709142313
}
],
"add_intersections": [
{
"point": {
"inner_x": 813.9379,
"inner_y": 886.5756
},
"intersection_type": "StopSign",
"label": null,
"orig_id": {
"osm_node_id": -1569791120
},
"synthetic": true
}
],
"add_roads": [
{
"i1": 389,
"i2": 64,
"center_points": [
{
"inner_x": 813.9379,
"inner_y": 886.5756
},
{
"inner_x": 798.6749,
"inner_y": 861.2825
}
],
"orig_id": {
"osm_way_id": -1569791128,
"node1": -1569791120,
"node2": 3978753110
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569791128",
"abst:synthetic": "true",
"abst:synthetic_lanes": "ds/ds",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 389,
"i2": 84,
"center_points": [
{
"inner_x": 813.9379,
"inner_y": 886.5756
},
{
"inner_x": 786.3408,
"inner_y": 879.8966
}
],
"orig_id": {
"osm_way_id": -1569791130,
"node1": -1569791120,
"node2": 3978753099
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569791130",
"abst:synthetic": "true",
"abst:synthetic_lanes": "ds/ds",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 389,
"i2": 205,
"center_points": [
{
"inner_x": 813.9379,
"inner_y": 886.5756
},
{
"inner_x": 829.4053,
"inner_y": 872.1018
}
],
"orig_id": {
"osm_way_id": -1569791132,
"node1": -1569791120,
"node2": 3978753105
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569791132",
"abst:synthetic": "true",
"abst:synthetic_lanes": "ds/ds",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 389,
"i2": 103,
"center_points": [
{
"inner_x": 813.9379,
"inner_y": 886.5756
},
{
"inner_x": 844.6918,
"inner_y": 882.2317
}
],
"orig_id": {
"osm_way_id": -1569791134,
"node1": -1569791120,
"node2": 3978753095
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569791134",
"abst:synthetic": "true",
"abst:synthetic_lanes": "ds/ds",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 389,
"i2": 111,
"center_points": [
{
"inner_x": 813.9379,
"inner_y": 886.5756
},
{
"inner_x": 859.806,
"inner_y": 904.4373
}
],
"orig_id": {
"osm_way_id": -1569791135,
"node1": -1569791120,
"node2": 2499822233
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569791135",
"abst:synthetic": "true",
"abst:synthetic_lanes": "ds/ds",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 155,
"i2": 31,
"center_points": [
{
"inner_x": 1670.7776,
"inner_y": 1507.9477
},
{
"inner_x": 1674.2845,
"inner_y": 1066.6373
}
],
"orig_id": {
"osm_way_id": -1569791601,
"node1": 1709141982,
"node2": 53230466
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569791601",
"abst:synthetic": "true",
"abst:synthetic_lanes": "dps/dps",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 337,
"i2": 155,
"center_points": [
{
"inner_x": 1642.3402,
"inner_y": 1646.9859
},
{
"inner_x": 1670.7776,
"inner_y": 1507.9477
}
],
"orig_id": {
"osm_way_id": -1569791614,
"node1": 53214349,
"node2": 1709141982
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569791614",
"abst:synthetic": "true",
"abst:synthetic_lanes": "dps/dps",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
},
{
"i1": 112,
"i2": 155,
"center_points": [
{
"inner_x": 1583.0525,
"inner_y": 1389.7475
},
{
"inner_x": 1670.7776,
"inner_y": 1507.9477
}
],
"orig_id": {
"osm_way_id": -1569791620,
"node1": 53096943,
"node2": 1709141982
},
"osm_tags": {
"abst:endpt_back": "true",
"abst:endpt_fwd": "true",
"abst:osm_way_id": "-1569791620",
"abst:synthetic": "true",
"abst:synthetic_lanes": "dps/dps",
"maxspeed": "25 mph",
"name": "Streety McStreetFace"
},
"turn_restrictions": []
}
],
"merge_short_roads": [
{
"osm_way_id": 256990067,
"node1": 542743474,
"node2": 53207165
}
]
}

View File

@ -473,7 +473,7 @@ impl GUI for UI {
.key_pressed(Key::Backspace, "delete everything in area")
{
if let Some(rect) = Polygon::rectangle_two_corners(pt1, *pt2) {
self.model.delete_everything_inside(rect, ctx.prerender);
self.model.delete_everything_inside(rect);
self.model.world.handle_mouseover(ctx);
}
self.state = State::viewing();

View File

@ -7,7 +7,7 @@ use map_model::raw::{
RestrictionType, StableBuildingID, StableIntersectionID, StableRoadID,
};
use map_model::{osm, IntersectionType, LaneType, RoadSpec, LANE_THICKNESS};
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeMap;
use std::mem;
const INTERSECTION_RADIUS: Distance = Distance::const_meters(5.0);
@ -22,7 +22,6 @@ pub struct Model {
pub world: World<ID>,
include_bldgs: bool,
fixes: MapFixes,
edit_fixes: Option<String>,
pub intersection_geom: bool,
}
@ -35,7 +34,6 @@ impl Model {
showing_pts: None,
include_bldgs: false,
fixes: MapFixes::new(),
edit_fixes: None,
world: World::new(&Bounds::new()),
intersection_geom: false,
@ -55,16 +53,14 @@ impl Model {
model.include_bldgs = include_bldgs;
model.edit_fixes = edit_fixes;
model.map = read_binary(path, &mut timer).unwrap();
model.fixes.gps_bounds = model.map.gps_bounds.clone();
model.intersection_geom = intersection_geom;
if !no_fixes {
let mut all_fixes = MapFixes::load(&mut timer);
let all_fixes = MapFixes::load(&mut timer);
model.map.apply_fixes(&all_fixes, &mut timer);
if let Some(ref name) = model.edit_fixes {
if let Some(fixes) = all_fixes.remove(name) {
model.fixes = fixes;
if !model.fixes.gps_bounds.approx_eq(&model.map.gps_bounds) {
if let Some(fixes) = all_fixes.get(name) {
if !fixes.gps_bounds.approx_eq(&model.map.gps_bounds) {
panic!("Can't edit {} with this map; use the original map", name);
}
}
@ -116,38 +112,14 @@ impl Model {
return;
};
// It's easiest to just go back and detect all of the added roads and intersections. But we
// have to avoid picking up changes from other fixes.
// TODO Ideally fixes would have a Polygon of where they influence, and all of the polygons
// would be disjoint. Nothing prevents fixes from being saved in the wrong group, or a
// created road from one set to be deleted in another -- we're just sure that a fix isn't
// repeated.
let mut ignore_roads: BTreeSet<OriginalRoad> = BTreeSet::new();
let mut ignore_intersections: BTreeSet<OriginalIntersection> = BTreeSet::new();
for (n, f) in MapFixes::load(&mut Timer::throwaway()) {
if n != name {
let (r, i) = f.all_touched_ids();
ignore_roads.extend(r);
ignore_intersections.extend(i);
}
}
self.fixes.add_intersections.clear();
self.fixes.add_roads.clear();
for i in self.map.intersections.values() {
if i.synthetic && !ignore_intersections.contains(&i.orig_id) {
self.fixes.add_intersections.push(i.clone());
}
}
for r in self.map.roads.values() {
if r.synthetic() && !ignore_roads.contains(&r.orig_id) {
self.fixes.add_roads.push(r.clone());
}
}
let path = abstutil::path_fixes(&name);
abstutil::write_json(&path, &self.fixes).unwrap();
abstutil::write_json(
&path,
&self
.map
.generate_fixes(&name, &mut Timer::new("calculate MapFixes")),
)
.unwrap();
println!("Wrote {}", path);
}
@ -169,7 +141,7 @@ impl Model {
bounds
}
pub fn delete_everything_inside(&mut self, area: Polygon, prerender: &Prerender) {
pub fn delete_everything_inside(&mut self, area: Polygon) {
if self.include_bldgs {
for id in self.map.buildings.keys().cloned().collect::<Vec<_>>() {
if area.contains_pt(self.map.buildings[&id].polygon.center()) {
@ -178,23 +150,15 @@ impl Model {
}
}
let mut delete_roads = Vec::new();
for id in self.map.roads.keys().cloned().collect::<Vec<_>>() {
if self.map.roads[&id]
.center_points
.iter()
.any(|pt| area.contains_pt(*pt))
{
for (rt, to) in self.map.roads[&id].turn_restrictions.clone() {
self.delete_tr(id, rt, to, prerender);
}
delete_roads.push(id);
self.delete_r(id);
}
}
for id in delete_roads {
self.delete_r(id);
}
for id in self.map.intersections.keys().cloned().collect::<Vec<_>>() {
if area.contains_pt(self.map.intersections[&id].point) {
@ -294,7 +258,7 @@ impl Model {
pub fn create_i(&mut self, point: Pt2D, prerender: &Prerender) {
let id = self
.map
.create_intersection(RawIntersection {
.override_intersection(RawIntersection {
point,
intersection_type: IntersectionType::StopSign,
label: None,
@ -352,7 +316,7 @@ impl Model {
println!("Can't delete intersection used by roads");
return;
}
self.map.delete_intersection(id, &mut self.fixes);
self.map.delete_intersection(id);
self.world.delete(ID::Intersection(id));
}
}
@ -408,7 +372,7 @@ impl Model {
let id = self
.map
.create_road(RawRoad {
.override_road(RawRoad {
i1,
i2,
orig_id: OriginalRoad {
@ -431,14 +395,12 @@ impl Model {
self.road_deleted(id);
if let Some(s) = RoadSpec::parse(spec.clone()) {
let mut osm_tags = self.map.roads[&id].osm_tags.clone();
osm_tags.insert(osm::SYNTHETIC_LANES.to_string(), s.to_string());
self.map.override_metadata(
id,
osm_tags,
self.map.roads[&id].turn_restrictions.clone(),
&mut self.fixes,
);
self.map
.roads
.get_mut(&id)
.unwrap()
.osm_tags
.insert(osm::SYNTHETIC_LANES.to_string(), s.to_string());
} else {
println!("Bad RoadSpec: {}", spec);
}
@ -449,9 +411,9 @@ impl Model {
pub fn swap_lanes(&mut self, id: StableRoadID, prerender: &Prerender) {
self.road_deleted(id);
let (mut lanes, mut osm_tags) = {
let r = &self.map.roads[&id];
(r.get_spec(), r.osm_tags.clone())
let (mut lanes, osm_tags) = {
let r = self.map.roads.get_mut(&id).unwrap();
(r.get_spec(), &mut r.osm_tags)
};
mem::swap(&mut lanes.fwd, &mut lanes.back);
osm_tags.insert(osm::SYNTHETIC_LANES.to_string(), lanes.to_string());
@ -465,28 +427,20 @@ impl Model {
osm_tags.insert(osm::FWD_LABEL.to_string(), l);
}
self.map.override_metadata(
id,
osm_tags,
self.map.roads[&id].turn_restrictions.clone(),
&mut self.fixes,
);
self.road_added(id, prerender);
}
pub fn set_r_label(&mut self, r: StableRoadID, label: String, prerender: &Prerender) {
self.road_deleted(r);
let mut osm_tags = self.map.roads[&r].osm_tags.clone();
// Always insert the forward label. Can fiddle with swap_lanes to change it.
osm_tags.insert(osm::FWD_LABEL.to_string(), label.to_string());
self.map
.roads
.get_mut(&r)
.unwrap()
.osm_tags
.insert(osm::FWD_LABEL.to_string(), label.to_string());
self.map.override_metadata(
r,
osm_tags,
self.map.roads[&r].turn_restrictions.clone(),
&mut self.fixes,
);
self.road_added(r, prerender);
}
@ -500,17 +454,11 @@ impl Model {
) {
self.road_deleted(id);
let mut osm_tags = self.map.roads[&id].osm_tags.clone();
let osm_tags = &mut self.map.roads.get_mut(&id).unwrap().osm_tags;
osm_tags.insert(osm::NAME.to_string(), name);
osm_tags.insert(osm::MAXSPEED.to_string(), speed);
osm_tags.insert(osm::HIGHWAY.to_string(), highway);
self.map.override_metadata(
id,
osm_tags,
self.map.roads[&id].turn_restrictions.clone(),
&mut self.fixes,
);
self.road_added(id, prerender);
}
@ -560,7 +508,7 @@ impl Model {
for id in matching_roads {
self.road_deleted(id);
let mut osm_tags = self.map.roads[&id].osm_tags.clone();
let osm_tags = &mut self.map.roads.get_mut(&id).unwrap().osm_tags;
osm_tags.remove(osm::INFERRED_PARKING);
let yes = "parallel".to_string();
let no = "no_parking".to_string();
@ -579,12 +527,6 @@ impl Model {
osm_tags.insert(osm::PARKING_BOTH.to_string(), yes);
}
self.map.override_metadata(
id,
osm_tags,
self.map.roads[&id].turn_restrictions.clone(),
&mut self.fixes,
);
self.road_added(id, prerender);
}
}
@ -624,7 +566,7 @@ impl Model {
for id in matching_roads {
self.road_deleted(id);
let mut osm_tags = self.map.roads[&id].osm_tags.clone();
let osm_tags = &mut self.map.roads.get_mut(&id).unwrap().osm_tags;
osm_tags.remove(osm::INFERRED_SIDEWALKS);
if value == Some("both".to_string()) {
osm_tags.insert(osm::SIDEWALK.to_string(), "right".to_string());
@ -636,26 +578,14 @@ impl Model {
osm_tags.insert(osm::SIDEWALK.to_string(), "both".to_string());
}
self.map.override_metadata(
id,
osm_tags,
self.map.roads[&id].turn_restrictions.clone(),
&mut self.fixes,
);
self.road_added(id, prerender);
}
}
pub fn delete_r(&mut self, id: StableRoadID) {
self.stop_showing_pts(id);
match self.map.can_delete_road(id) {
Ok(()) => {
self.road_deleted(id);
self.map.delete_road(id, &mut self.fixes);
}
Err(e) => println!("Can't delete this road: {}", e),
}
self.road_deleted(id);
self.map.delete_road(id);
}
fn road_objects(&self, id: StableRoadID) -> Vec<Object<ID>> {
@ -797,9 +727,8 @@ impl Model {
self.world.delete(ID::Intersection(self.map.roads[&id].i1));
self.world.delete(ID::Intersection(self.map.roads[&id].i2));
let mut pts = self.map.roads[&id].center_points.clone();
let pts = &mut self.map.roads.get_mut(&id).unwrap().center_points;
pts[idx] = point;
self.map.override_road_points(id, pts);
self.road_added(id, prerender);
self.intersection_added(self.map.roads[&id].i1, prerender);
@ -815,9 +744,8 @@ impl Model {
self.world.delete(ID::Intersection(self.map.roads[&id].i1));
self.world.delete(ID::Intersection(self.map.roads[&id].i2));
let mut pts = self.map.roads[&id].center_points.clone();
let pts = &mut self.map.roads.get_mut(&id).unwrap().center_points;
pts.remove(idx);
self.map.override_road_points(id, pts);
self.road_added(id, prerender);
self.intersection_added(self.map.roads[&id].i1, prerender);
@ -833,8 +761,8 @@ impl Model {
self.world.delete(ID::Intersection(self.map.roads[&id].i1));
self.world.delete(ID::Intersection(self.map.roads[&id].i2));
let mut pts = self.map.roads[&id].center_points.clone();
let mut closest = FindClosest::new(&self.compute_bounds());
let pts = &mut self.map.roads.get_mut(&id).unwrap().center_points;
for (idx, pair) in pts.windows(2).enumerate() {
closest.add(idx + 1, &vec![pair[0], pair[1]]);
}
@ -845,7 +773,6 @@ impl Model {
println!("Couldn't figure out where to insert new point");
None
};
self.map.override_road_points(id, pts);
self.road_added(id, prerender);
self.intersection_added(self.map.roads[&id].i1, prerender);
@ -868,8 +795,7 @@ impl Model {
// of lanes and can generate all the IDs.
self.road_deleted(id);
let (retained_i, deleted_i, changed_roads) =
self.map.merge_short_road(id, &mut self.fixes).unwrap();
let (retained_i, deleted_i, changed_roads) = self.map.merge_short_road(id).unwrap();
self.world.delete(ID::Intersection(retained_i));
self.intersection_added(retained_i, prerender);
@ -896,8 +822,14 @@ impl Model {
) {
self.road_deleted(from);
assert!(self.map.can_add_turn_restriction(from, to));
// TODO Worry about dupes
self.map
.add_turn_restriction(from, restriction, to, &mut self.fixes);
.roads
.get_mut(&from)
.unwrap()
.turn_restrictions
.push((restriction, to));
self.road_added(from, prerender);
}
@ -912,7 +844,11 @@ impl Model {
self.road_deleted(from);
self.map
.delete_turn_restriction(from, restriction, to, &mut self.fixes);
.roads
.get_mut(&from)
.unwrap()
.turn_restrictions
.retain(|(this_r, this_to)| *this_r != restriction || *this_to != to);
self.road_added(from, prerender);
}

View File

@ -1,6 +1,6 @@
use crate::make::get_lane_types;
use crate::{osm, AreaType, IntersectionType, OffstreetParking, RoadSpec};
use abstutil::{deserialize_btreemap, serialize_btreemap, Error, Timer};
use abstutil::{Error, Timer};
use geom::{Distance, GPSBounds, Polygon, Pt2D};
use gtfs::Route;
use serde_derive::{Deserialize, Serialize};
@ -64,8 +64,7 @@ impl RawMap {
}
}
// TODO pub(crate) for these
pub fn find_r(&self, orig: OriginalRoad) -> Option<StableRoadID> {
fn find_r(&self, orig: OriginalRoad) -> Option<StableRoadID> {
for (id, r) in &self.roads {
if r.orig_id == orig {
return Some(*id);
@ -74,7 +73,7 @@ impl RawMap {
None
}
pub fn find_i(&self, orig: OriginalIntersection) -> Option<StableIntersectionID> {
fn find_i(&self, orig: OriginalIntersection) -> Option<StableIntersectionID> {
for (id, i) in &self.intersections {
if i.orig_id == orig {
return Some(*id);
@ -84,33 +83,14 @@ impl RawMap {
}
pub fn apply_fixes(&mut self, all_fixes: &BTreeMap<String, MapFixes>, timer: &mut Timer) {
let mut dummy_fixes = MapFixes::new();
timer.start("applying all fixes");
for (name, fixes) in all_fixes {
let mut applied = 0;
let mut skipped = 0;
// Do these first, because we're not allowed to delete roads if they have turn
// restrictions.
for (orig, (osm_tags, raw_restrictions)) in &fixes.override_metadata {
if let Some(r) = self.find_r(*orig) {
// If this road is in the map, it better not have any turn restrictions linking
// it to a road outside the map!
let restrictions = raw_restrictions
.iter()
.map(|(rt, to)| (*rt, self.find_r(*to).unwrap()))
.collect();
self.override_metadata(r, osm_tags.clone(), restrictions, &mut dummy_fixes);
applied += 1;
} else {
skipped += 1;
}
}
for orig in &fixes.delete_roads {
if let Some(r) = self.find_r(*orig) {
self.delete_road(r, &mut dummy_fixes);
self.delete_road(r);
applied += 1;
} else {
skipped += 1;
@ -119,7 +99,7 @@ impl RawMap {
for orig in &fixes.delete_intersections {
if let Some(i) = self.find_i(*orig) {
self.delete_intersection(i, &mut dummy_fixes);
self.delete_intersection(i);
applied += 1;
} else {
skipped += 1;
@ -128,7 +108,7 @@ impl RawMap {
let remap_pts = !self.gps_bounds.approx_eq(&fixes.gps_bounds);
for mut i in fixes.add_intersections.clone() {
for mut i in fixes.override_intersections.clone() {
if remap_pts {
i.point = Pt2D::forcibly_from_gps(
i.point.to_gps(&fixes.gps_bounds).unwrap(),
@ -136,30 +116,21 @@ impl RawMap {
);
}
if self.create_intersection(i).is_some() {
if self.override_intersection(i).is_some() {
applied += 1;
} else {
skipped += 1;
}
}
for mut r in fixes.add_roads.clone() {
for mut r in fixes.override_roads.clone() {
if remap_pts {
r.center_points = self
.gps_bounds
.forcibly_convert(&fixes.gps_bounds.must_convert_back(&r.center_points));
}
if self.create_road(r).is_some() {
applied += 1;
} else {
skipped += 1;
}
}
for orig in &fixes.merge_short_roads {
if let Some(r) = self.find_r(*orig) {
self.merge_short_road(r, &mut dummy_fixes);
if self.override_road(r).is_some() {
applied += 1;
} else {
skipped += 1;
@ -177,7 +148,6 @@ impl RawMap {
}
// TODO Might be better to maintain this instead of doing a search everytime.
// TODO make private
pub fn roads_per_intersection(&self, i: StableIntersectionID) -> Vec<StableRoadID> {
let mut results = Vec::new();
for (id, r) in &self.roads {
@ -265,69 +235,82 @@ impl RawMap {
}
}
// Mutations
// Mutations and supporting queries
impl RawMap {
pub fn can_delete_road(&self, r: StableRoadID) -> Result<(), Error> {
pub fn delete_road(&mut self, r: StableRoadID) {
// First delete and warn about turn restrictions
if !self.roads[&r].turn_restrictions.is_empty() {
return Err(Error::new(format!("{} has turn restrictions from it", r)));
println!("Deleting {}, but note it has turn restrictions from it", r);
}
// Brute force search the other direction
let mut cleanup_other_roads = Vec::new();
for (src, road) in &self.roads {
for (_, to) in &road.turn_restrictions {
if r == *to {
return Err(Error::new(format!(
"There's a turn restriction from {} to {}",
src, r
)));
println!(
"Deleting turn restriction from other road {} to {}",
src, to
);
cleanup_other_roads.push(*src);
}
}
}
Ok(())
}
for src in cleanup_other_roads {
self.roads
.get_mut(&src)
.unwrap()
.turn_restrictions
.retain(|(_, to)| *to != r);
}
pub fn delete_road(&mut self, r: StableRoadID, fixes: &mut MapFixes) {
if let Err(e) = self.can_delete_road(r) {
panic!("Can't delete_road {:?}: {}", self.roads[&r].orig_id, e);
}
let road = self.roads.remove(&r).unwrap();
if !road.synthetic() {
fixes.delete_roads.push(road.orig_id);
}
self.roads.remove(&r).unwrap();
}
pub fn can_delete_intersection(&self, i: StableIntersectionID) -> bool {
self.roads_per_intersection(i).is_empty()
}
pub fn delete_intersection(&mut self, id: StableIntersectionID, fixes: &mut MapFixes) {
pub fn delete_intersection(&mut self, id: StableIntersectionID) {
if !self.can_delete_intersection(id) {
panic!(
"Can't delete_intersection {:?}, must have roads connected",
self.intersections[&id].orig_id
);
}
let i = self.intersections.remove(&id).unwrap();
if !i.synthetic {
fixes.delete_intersections.push(i.orig_id);
}
self.intersections.remove(&id).unwrap();
}
pub fn create_intersection(&mut self, i: RawIntersection) -> Option<StableIntersectionID> {
assert!(i.synthetic);
// These two are kind of just for apply_fixes, except they're also useful to create new stuff,
// since they allocate a new ID.
pub fn override_intersection(&mut self, i: RawIntersection) -> Option<StableIntersectionID> {
// Existing?
if let Some(id) = self.find_i(i.orig_id) {
self.intersections.insert(id, i);
return Some(id);
}
// New
if self
.gps_bounds
.contains(i.point.forcibly_to_gps(&self.gps_bounds))
{
let id = StableIntersectionID(self.intersections.keys().max().unwrap().0 + 1);
self.intersections.insert(id, i.clone());
self.intersections.insert(id, i);
Some(id)
} else {
None
}
}
pub fn create_road(&mut self, mut r: RawRoad) -> Option<StableRoadID> {
assert!(r.synthetic());
pub fn override_road(&mut self, mut r: RawRoad) -> Option<StableRoadID> {
// Existing?
if let Some(id) = self.find_r(r.orig_id) {
// TODO Do we need to rewrite i1 and i2?
self.roads.insert(id, r);
return Some(id);
}
// New
match (
self.find_i(OriginalIntersection {
osm_node_id: r.orig_id.node1,
@ -348,8 +331,6 @@ impl RawMap {
}
pub fn can_merge_short_road(&self, id: StableRoadID) -> Result<(), Error> {
self.can_delete_road(id)?;
let road = &self.roads[&id];
let i1 = &self.intersections[&road.i1];
let i2 = &self.intersections[&road.i2];
@ -359,23 +340,6 @@ impl RawMap {
return Err(Error::new(format!("{} touches a border", id)));
}
for r in self.roads_per_intersection(road.i2) {
if self.roads[&r].synthetic() {
return Err(Error::new(format!(
"Surviving {} touches a synthetic road",
r
)));
}
}
if i1.synthetic || i2.synthetic {
return Err(Error::new(format!(
"{} touches a synthetic intersection",
id
)));
}
// It's fine if we're overriding the metadata for this road already; we'll just delete it
// if so. We might be forced to do that to delete turn restrictions. ;)
Ok(())
}
@ -384,7 +348,6 @@ impl RawMap {
pub fn merge_short_road(
&mut self,
id: StableRoadID,
fixes: &mut MapFixes,
) -> Option<(
StableIntersectionID,
StableIntersectionID,
@ -392,9 +355,7 @@ impl RawMap {
)> {
assert!(self.can_merge_short_road(id).is_ok());
let (i1, i2) = {
let r = self.roads.remove(&id).unwrap();
fixes.merge_short_roads.push(r.orig_id);
fixes.override_metadata.remove(&r.orig_id);
let r = &self.roads[&id];
(r.i1, r.i2)
};
let (i1_pt, i1_orig_id) = {
@ -402,9 +363,12 @@ impl RawMap {
(i.point, i.orig_id)
};
self.delete_road(id);
// Arbitrarily keep i1 and destroy i2. If the intersection types differ, upgrade the
// surviving interesting.
{
// Don't use delete_intersection; we're manually fixing up connected roads
let i = self.intersections.remove(&i2).unwrap();
if i.intersection_type == IntersectionType::TrafficSignal {
self.intersections.get_mut(&i1).unwrap().intersection_type =
@ -442,50 +406,6 @@ impl RawMap {
Some((i1, i2, fixed))
}
pub fn override_metadata(
&mut self,
r: StableRoadID,
osm_tags: BTreeMap<String, String>,
restrictions: Vec<(RestrictionType, StableRoadID)>,
fixes: &mut MapFixes,
) {
{
let road = self.roads.get_mut(&r).unwrap();
road.osm_tags = osm_tags;
road.turn_restrictions = restrictions;
}
let road = &self.roads[&r];
if !road.synthetic() {
fixes.override_metadata.insert(
road.orig_id,
(
road.osm_tags.clone(),
road.turn_restrictions
.iter()
.map(|(rt, to)| (*rt, self.roads[to].orig_id))
.collect(),
),
);
}
}
pub fn delete_turn_restriction(
&mut self,
from: StableRoadID,
restriction: RestrictionType,
to: StableRoadID,
fixes: &mut MapFixes,
) {
let (osm_tags, mut restrictions) = {
let r = &self.roads[&from];
(r.osm_tags.clone(), r.turn_restrictions.clone())
};
restrictions.retain(|(this_r, this_to)| *this_r != restriction || *this_to != to);
self.override_metadata(from, osm_tags, restrictions, fixes);
}
pub fn can_add_turn_restriction(&self, from: StableRoadID, to: StableRoadID) -> bool {
let (i1, i2) = {
let r = &self.roads[&from];
@ -498,33 +418,11 @@ impl RawMap {
i1 == i3 || i1 == i4 || i2 == i3 || i2 == i4
}
// TODO Worry about duplicates?
pub fn add_turn_restriction(
&mut self,
from: StableRoadID,
restriction: RestrictionType,
to: StableRoadID,
fixes: &mut MapFixes,
) {
assert!(self.can_add_turn_restriction(from, to));
let (osm_tags, mut restrictions) = {
let r = &self.roads[&from];
(r.osm_tags.clone(), r.turn_restrictions.clone())
};
restrictions.push((restriction, to));
self.override_metadata(from, osm_tags, restrictions, fixes);
}
}
// Mutations not recorded in MapFixes yet
// TODO Fix that!
impl RawMap {
pub fn move_intersection(
&mut self,
id: StableIntersectionID,
point: Pt2D,
) -> Option<Vec<StableRoadID>> {
// TODO Only for synthetic intersections, right?
self.intersections.get_mut(&id).unwrap().point = point;
// Update all the roads.
@ -537,12 +435,15 @@ impl RawMap {
} else {
assert_eq!(road.i2, id);
*road.center_points.last_mut().unwrap() = point;
// TODO Don't update orig_id, right?
}
}
Some(fixed)
}
// TODO Some of these are pretty silly
pub fn modify_intersection(
&mut self,
id: StableIntersectionID,
@ -554,11 +455,6 @@ impl RawMap {
i.label = label;
}
// This shouldn't modify the endpoints, so don't have to mess around with intersections.
pub fn override_road_points(&mut self, id: StableRoadID, pts: Vec<Pt2D>) {
self.roads.get_mut(&id).unwrap().center_points = pts;
}
pub fn create_building(&mut self, bldg: RawBuilding) -> Option<StableBuildingID> {
if bldg.polygon.center().to_gps(&self.gps_bounds).is_some() {
let id = StableBuildingID(self.buildings.keys().max().unwrap().0 + 1);
@ -583,9 +479,82 @@ impl RawMap {
pub fn delete_building(&mut self, id: StableBuildingID) {
self.buildings.remove(&id);
}
pub fn generate_fixes(&self, fixes_name: &str, timer: &mut Timer) -> MapFixes {
let orig: RawMap =
abstutil::read_binary(&abstutil::path_raw_map(&self.name), timer).unwrap();
let mut fixes = MapFixes {
gps_bounds: self.gps_bounds.clone(),
delete_roads: Vec::new(),
delete_intersections: Vec::new(),
override_intersections: Vec::new(),
override_roads: Vec::new(),
};
// What'd we delete?
for r in orig.roads.values() {
if self.find_r(r.orig_id).is_none() {
fixes.delete_roads.push(r.orig_id);
}
}
for i in orig.intersections.values() {
if self.find_i(i.orig_id).is_none() {
fixes.delete_intersections.push(i.orig_id);
}
}
// What'd we create or modify?
for i in self.intersections.values() {
if orig
.find_i(i.orig_id)
.map(|id| orig.intersections[&id] != *i)
.unwrap_or(true)
{
fixes.override_intersections.push(i.clone());
}
}
for r in self.roads.values() {
if orig
.find_r(r.orig_id)
.map(|id| orig.roads[&id] != *r)
.unwrap_or(true)
{
fixes.override_roads.push(r.clone());
}
}
// Filter out things from other fixes.
// TODO If we accidentally modify something from another set of fixes, then we silently
// discard that change. Oops!
let mut seen_roads = BTreeSet::new();
let mut seen_intersections = BTreeSet::new();
for name in abstutil::list_all_objects("fixes", "") {
if name == fixes_name {
continue;
}
let f: MapFixes = abstutil::read_json(&abstutil::path_fixes(&name), timer).unwrap();
let (new_roads, new_intersections) = f.all_touched_ids();
seen_roads.extend(new_roads);
seen_intersections.extend(new_intersections);
}
fixes.delete_roads.retain(|r| !seen_roads.contains(r));
fixes
.delete_intersections
.retain(|i| !seen_intersections.contains(i));
fixes
.override_intersections
.retain(|i| !seen_intersections.contains(&i.orig_id));
fixes
.override_roads
.retain(|r| !seen_roads.contains(&r.orig_id));
fixes
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct RawRoad {
// The first and last point may not match up with i1 and i2.
pub i1: StableIntersectionID,
@ -611,7 +580,7 @@ impl RawRoad {
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct RawIntersection {
// Represents the original place where OSM center-lines meet. This is meaningless beyond
// RawMap; roads and intersections get merged and deleted.
@ -690,38 +659,15 @@ pub struct OriginalIntersection {
pub struct MapFixes {
// Any Pt2Ds in the rest of the fixes are relative to these GPSBounds.
pub gps_bounds: GPSBounds,
// For non-synthetic (original OSM) roads. (OSM tags, turn restrictions).
#[serde(
serialize_with = "serialize_btreemap",
deserialize_with = "deserialize_btreemap"
)]
pub override_metadata: BTreeMap<
OriginalRoad,
(
BTreeMap<String, String>,
Vec<(RestrictionType, OriginalRoad)>,
),
>,
pub delete_roads: Vec<OriginalRoad>,
pub delete_intersections: Vec<OriginalIntersection>,
pub add_intersections: Vec<RawIntersection>,
pub add_roads: Vec<RawRoad>,
pub merge_short_roads: Vec<OriginalRoad>,
// Create or modify
pub override_intersections: Vec<RawIntersection>,
pub override_roads: Vec<RawRoad>,
}
impl MapFixes {
pub fn new() -> MapFixes {
MapFixes {
gps_bounds: GPSBounds::new(),
delete_roads: Vec::new(),
delete_intersections: Vec::new(),
add_intersections: Vec::new(),
add_roads: Vec::new(),
merge_short_roads: Vec::new(),
override_metadata: BTreeMap::new(),
}
}
// The groups of fixes should be applicable in any order, theoretically...
pub fn load(timer: &mut Timer) -> BTreeMap<String, MapFixes> {
// Make sure different groups of fixes don't conflict.
@ -754,17 +700,15 @@ impl MapFixes {
results
}
pub fn all_touched_ids(&self) -> (BTreeSet<OriginalRoad>, BTreeSet<OriginalIntersection>) {
fn all_touched_ids(&self) -> (BTreeSet<OriginalRoad>, BTreeSet<OriginalIntersection>) {
let mut roads: BTreeSet<OriginalRoad> = self.delete_roads.iter().cloned().collect();
for r in &self.add_roads {
for r in &self.override_roads {
roads.insert(r.orig_id);
}
roads.extend(self.merge_short_roads.clone());
roads.extend(self.override_metadata.keys().cloned());
let mut intersections: BTreeSet<OriginalIntersection> =
self.delete_intersections.iter().cloned().collect();
for i in &self.add_intersections {
for i in &self.override_intersections {
intersections.insert(i.orig_id);
}