Skip to content

Commit

Permalink
Update osm2streets after some API changes in
Browse files Browse the repository at this point in the history
a-b-street/osm2streets#47. No behavioral effect
from this. For the moment, I'm pretending uncontrolled junctions are the
same as stop signs.

Also whittle down creators of strange polygons for #951. Some buildings
or areas may be affected, but no major problems seen yet.

Regenerating everything...
  • Loading branch information
dabreegster committed Aug 16, 2022
1 parent c88baeb commit e9e28a7
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion apps/game/src/info/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ fn header(
let i = app.primary.map.get_i(id);

let label = match i.intersection_type {
IntersectionType::StopSign => format!("{} (Stop signs)", id),
IntersectionType::StopSign | IntersectionType::Uncontrolled => {
format!("{} (Stop signs)", id)
}
IntersectionType::TrafficSignal => format!("{} (Traffic signals)", id),
IntersectionType::Border => format!("Border #{}", id.0),
IntersectionType::Construction => format!("{} (under construction)", id),
Expand Down
35 changes: 20 additions & 15 deletions apps/map_editor/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use abstio::{CityName, MapName};
use abstutil::{Tags, Timer};
use geom::{Bounds, Circle, Distance, FindClosest, GPSBounds, HashablePt2D, LonLat, Polygon, Pt2D};
use raw_map::{RawBuilding, RawMap};
use street_network::{osm, IntersectionType, OriginalRoad, RawIntersection, RawRoad};
use street_network::{osm, ControlType, Intersection, IntersectionComplexity, OriginalRoad, Road};
use widgetry::mapspace::{ObjectID, World};
use widgetry::{Color, Drawable, EventCtx, GeomBatch, Key, Line, Text};

Expand Down Expand Up @@ -162,11 +162,11 @@ impl Model {
impl Model {
fn intersection_added(&mut self, ctx: &EventCtx, id: osm::NodeID) {
let i = &self.map.streets.intersections[&id];
let color = match i.intersection_type {
IntersectionType::TrafficSignal => Color::GREEN,
IntersectionType::StopSign => Color::RED,
IntersectionType::Border => Color::BLUE,
IntersectionType::Construction => Color::ORANGE,
let color = match i.control {
ControlType::TrafficSignal => Color::GREEN,
ControlType::StopSign | ControlType::Uncontrolled => Color::RED,
ControlType::Border => Color::BLUE,
ControlType::Construction => Color::ORANGE,
};

let poly =
Expand Down Expand Up @@ -199,10 +199,15 @@ impl Model {

pub fn create_i(&mut self, ctx: &EventCtx, point: Pt2D) {
let id = self.map.streets.new_osm_node_id(time_to_id());
self.map
.streets
.intersections
.insert(id, RawIntersection::new(point, IntersectionType::StopSign));
// The complexity will change as we connect things to this intersection
self.map.streets.intersections.insert(
id,
Intersection::new(
point,
IntersectionComplexity::Crossing,
ControlType::StopSign,
),
);
self.intersection_added(ctx, id);
}

Expand All @@ -228,10 +233,10 @@ impl Model {
self.world.delete_before_replacement(ID::Intersection(id));

let i = self.map.streets.intersections.get_mut(&id).unwrap();
if i.intersection_type == IntersectionType::TrafficSignal {
i.intersection_type = IntersectionType::StopSign;
} else if i.intersection_type == IntersectionType::StopSign {
i.intersection_type = IntersectionType::TrafficSignal;
if i.control == ControlType::TrafficSignal {
i.control = ControlType::StopSign;
} else if i.control == ControlType::StopSign {
i.control = ControlType::TrafficSignal;
}

self.intersection_added(ctx, id);
Expand Down Expand Up @@ -353,7 +358,7 @@ impl Model {
osm_tags.insert(osm::NAME, "Streety McStreetFace");
osm_tags.insert(osm::MAXSPEED, "25 mph");

let road = match RawRoad::new(
let road = match Road::new(
vec![
self.map.streets.intersections[&i1].point,
self.map.streets.intersections[&i2].point,
Expand Down
24 changes: 13 additions & 11 deletions convert_osm/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,19 @@ pub fn extract_osm(
}
} else if is_bldg(&rel.tags) {
match multipoly_geometry(id, rel, &doc) {
Ok(polygon) => {
map.buildings.insert(
OsmID::Relation(id),
RawBuilding {
polygon,
public_garage_name: None,
num_parking_spots: 0,
amenities: get_bldg_amenities(&rel.tags),
osm_tags: rel.tags.clone(),
},
);
Ok(polygons) => {
for polygon in polygons {
map.buildings.insert(
OsmID::Relation(id),
RawBuilding {
polygon,
public_garage_name: None,
num_parking_spots: 0,
amenities: get_bldg_amenities(&rel.tags),
osm_tags: rel.tags.clone(),
},
);
}
}
Err(err) => println!("Skipping building {}: {}", id, err),
}
Expand Down
6 changes: 3 additions & 3 deletions convert_osm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use abstio::MapName;
use abstutil::{Tags, Timer};
use geom::{Distance, FindClosest, GPSBounds, LonLat, Polygon, Pt2D, Ring};
use raw_map::{Amenity, RawMap};
use street_network::{osm, OriginalRoad, RawRoad};
use street_network::{osm, OriginalRoad, Road};

pub use import_streets::{
OnstreetParking, Options, PrivateOffstreetParking, PublicOffstreetParking,
Expand All @@ -29,7 +29,7 @@ pub fn convert(
timer: &mut Timer,
) -> RawMap {
let mut map = RawMap::blank(name);
// Do this early. Calculating RawRoads uses DrivingSide, for example!
// Do this early. Calculating Roads uses DrivingSide, for example!
map.streets.config = opts.map_config.clone();

if let Some(ref path) = clip_path {
Expand Down Expand Up @@ -154,7 +154,7 @@ fn bristol_hack(map: &mut RawMap) {

map.streets.roads.insert(
id,
RawRoad::new(
Road::new(
vec![
map.streets.intersections[&i1].point,
map.streets.intersections[&i2].point,
Expand Down
1 change: 1 addition & 0 deletions geom/src/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ pub struct Triangle {
pub pt3: Pt2D,
}

// Note that this could crash on invalid rings
impl From<geo::Polygon> for Polygon {
fn from(poly: geo::Polygon) -> Self {
let (exterior, interiors) = poly.into_inner();
Expand Down
1 change: 1 addition & 0 deletions geom/src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ impl From<Ring> for geo::LineString {
}
}

// TODO This could crash. Should be TryFrom?
impl From<geo::LineString> for Ring {
fn from(line_string: geo::LineString) -> Self {
// Dedupe adjacent points. Only needed for results from concave hull.
Expand Down
2 changes: 1 addition & 1 deletion map_gui/src/render/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl DrawIntersection {
calculate_border_arrows(i, r, map),
);
}
IntersectionType::StopSign => {
IntersectionType::StopSign | IntersectionType::Uncontrolled => {
for ss in map.get_stop_sign(i.id).roads.values() {
if !app.opts().show_stop_signs {
break;
Expand Down
6 changes: 4 additions & 2 deletions map_model/src/edits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ fn recalculate_turns(id: IntersectionID, map: &mut Map, effects: &mut EditEffect
i.movements = movements;

match i.intersection_type {
IntersectionType::StopSign => {
IntersectionType::StopSign | IntersectionType::Uncontrolled => {
// Stop sign policy usually doesn't depend on incoming lane types, except when changing
// to/from construction. To be safe, always regenerate. Edits to stop signs are rare
// anyway. And when we're smarter about preserving traffic signal changes in the face
Expand Down Expand Up @@ -782,7 +782,9 @@ impl Map {
/// Panics on borders
pub fn get_i_edit(&self, i: IntersectionID) -> EditIntersection {
match self.get_i(i).intersection_type {
IntersectionType::StopSign => EditIntersection::StopSign(self.get_stop_sign(i).clone()),
IntersectionType::StopSign | IntersectionType::Uncontrolled => {
EditIntersection::StopSign(self.get_stop_sign(i).clone())
}
IntersectionType::TrafficSignal => {
EditIntersection::TrafficSignal(self.get_traffic_signal(i).export(self))
}
Expand Down
5 changes: 3 additions & 2 deletions map_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ use abstutil::{deserialize_btreemap, serialize_btreemap, MultiMap};
use geom::{Bounds, GPSBounds, Polygon};
// Re-export a bunch of things for convenience
pub use raw_map::{Amenity, AmenityType, AreaType};
pub use street_network::ControlType as IntersectionType;
pub use street_network::{
osm, BufferType, Direction, DrivingSide, IntersectionType, LaneSpec, LaneType, MapConfig,
NamePerLanguage, OriginalRoad, RestrictionType, NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS,
osm, BufferType, Direction, DrivingSide, LaneSpec, LaneType, MapConfig, NamePerLanguage,
OriginalRoad, RestrictionType, NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS,
};

pub use crate::city::City;
Expand Down
8 changes: 6 additions & 2 deletions map_model/src/make/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ impl Map {
movements: BTreeMap::new(),
elevation: i.elevation,
// Might change later
intersection_type: i.intersection_type,
intersection_type: match i.control {
// Nothing in A/B Street handles uncontrolled intersections yet
IntersectionType::Uncontrolled => IntersectionType::StopSign,
x => x,
},
orig_id: i.id,
incoming_lanes: Vec::new(),
outgoing_lanes: Vec::new(),
Expand Down Expand Up @@ -260,7 +264,7 @@ impl Map {
let mut traffic_signals: BTreeMap<IntersectionID, ControlTrafficSignal> = BTreeMap::new();
for i in &map.intersections {
match i.intersection_type {
IntersectionType::StopSign => {
IntersectionType::StopSign | IntersectionType::Uncontrolled => {
stop_signs.insert(i.id, ControlStopSign::new(&map, i.id));
}
IntersectionType::TrafficSignal => {
Expand Down

0 comments on commit e9e28a7

Please sign in to comment.