Skip to content

Commit

Permalink
Create a more careful API for handling one-way roads everywhere, in
Browse files Browse the repository at this point in the history
preparation for modifying them in the LTN tool.

Regenerated everything. This had some effects on overlapping road
shrinking, mostly positive. Screenshot diffs all changed, since I
switched laptops again.
  • Loading branch information
dabreegster committed May 27, 2022
1 parent a0ff011 commit d98f18b
Show file tree
Hide file tree
Showing 18 changed files with 495 additions and 455 deletions.
4 changes: 3 additions & 1 deletion apps/ltn/src/components/freehand_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ impl FreehandFilters {
continue;
}
let road = app.map.get_r(*r);
if !PathConstraints::Car.can_use_road(road, &app.map) || road.is_oneway() {
if !PathConstraints::Car.can_use_road(road, &app.map)
|| road.oneway_for_driving().is_some()
{
continue;
}
if let Some((pt, _)) = road.center_pts.intersection(&path) {
Expand Down
24 changes: 15 additions & 9 deletions apps/ltn/src/connectivity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use geom::{ArrowCap, Distance, PolyLine};
use map_gui::tools::ColorNetwork;
use raw_map::Direction;
use widgetry::mapspace::ToggleZoomed;
use widgetry::tools::PopupMsg;
use widgetry::{
Expand Down Expand Up @@ -256,14 +257,14 @@ fn setup_editing(

// The arrow direction depends on if the road is one-way
let thickness = Distance::meters(6.0);
let arrow = if road.is_oneway() {
if road.src_i == *i {
let arrow = if let Some(dir) = road.oneway_for_driving() {
let pl = if road.src_i == *i {
PolyLine::must_new(vec![pt_farther, pt_closer])
.make_arrow(thickness, ArrowCap::Triangle)
} else {
PolyLine::must_new(vec![pt_closer, pt_farther])
.make_arrow(thickness, ArrowCap::Triangle)
}
};
pl.maybe_reverse(dir == Direction::Back)
.make_arrow(thickness, ArrowCap::Triangle)
} else {
// Order doesn't matter
PolyLine::must_new(vec![pt_closer, pt_farther])
Expand All @@ -282,19 +283,24 @@ fn setup_editing(
.chain(neighborhood.orig_perimeter.roads.iter().map(|id| &id.road))
{
let road = map.get_r(*r);
if road.osm_tags.is("oneway", "yes") {
if let Some(dir) = road.oneway_for_driving() {
let arrow_len = Distance::meters(10.0);
let thickness = Distance::meters(1.0);
for (pt, angle) in road
.center_pts
.step_along(Distance::meters(30.0), Distance::meters(5.0))
{
if let Ok(poly) = PolyLine::must_new(vec![
// If the user has made the one-way point opposite to how the road is originally
// oriented, reverse the arrows
let pl = PolyLine::must_new(vec![
pt.project_away(arrow_len / 2.0, angle.opposite()),
pt.project_away(arrow_len / 2.0, angle),
])
.make_arrow(thickness * 2.0, ArrowCap::Triangle)
.to_outline(thickness / 2.0)
.maybe_reverse(dir == Direction::Back);

if let Ok(poly) = pl
.make_arrow(thickness * 2.0, ArrowCap::Triangle)
.to_outline(thickness / 2.0)
{
draw_top_layer.unzoomed.push(colors::OUTLINE, poly);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/ltn/src/edit/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ pub fn handle_world_outcome(ctx: &mut EventCtx, app: &mut App, outcome: WorldOut
let road = map.get_r(r);
// Filtering a road that's already marked bike-only doesn't make sense. Likewise for
// one-ways.
if !PathConstraints::Car.can_use_road(road, map) || road.is_oneway() {
if !PathConstraints::Car.can_use_road(road, map) || road.oneway_for_driving().is_some()
{
return true;
}

Expand Down
10 changes: 2 additions & 8 deletions apps/ltn/src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,8 @@ impl DiagonalFilter {
let r2 = map.get_r(self.r2);

// Orient the road to face the intersection
let mut pl1 = r1.center_pts.clone();
if r1.src_i == self.i {
pl1 = pl1.reversed();
}
let mut pl2 = r2.center_pts.clone();
if r2.src_i == self.i {
pl2 = pl2.reversed();
}
let pl1 = r1.center_pts.maybe_reverse(r1.src_i == self.i);
let pl2 = r2.center_pts.maybe_reverse(r2.src_i == self.i);

// The other combinations of left/right here would produce points or a line across just one
// road
Expand Down
2 changes: 1 addition & 1 deletion apps/ltn/src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use abstio::MapName;
use abstutil::Timer;
use map_model::osm::RoadRank;
use map_model::{Block, Map, PathConstraints, Perimeter, RoadID, RoadSideID};
use map_model::{Block, Map, Perimeter, RoadID, RoadSideID};
use widgetry::Color;

use crate::{colors, App};
Expand Down
2 changes: 1 addition & 1 deletion apps/parking_mapper/src/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ fn find_divided_highways(app: &App) -> HashSet<RoadID> {
// road, but didn't mark one side oneway!
let mut oneways = Vec::new();
for r in map.all_roads() {
if r.osm_tags.contains_key("oneway") {
if r.oneway_for_driving().is_some() {
closest.add(r.id, r.center_pts.points());
oneways.push(r.id);
}
Expand Down
2 changes: 1 addition & 1 deletion convert_osm/src/parking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn apply_parking(map: &mut RawMap, opts: &Options, timer: &mut Timer) {
&& id.osm_way_id.0 % 100 <= pct
&& r.length() >= Distance::meters(20.0)
{
if r.osm_tags.is("oneway", "yes") {
if r.oneway_for_driving().is_some() {
r.osm_tags.remove(osm::PARKING_BOTH);
r.osm_tags.insert(osm::PARKING_RIGHT, "parallel");
} else {
Expand Down
Loading

0 comments on commit d98f18b

Please sign in to comment.