Draw corners where shoulders and sidewalks meet more carefully.

This commit is contained in:
Dustin Carlino 2021-02-23 14:20:59 -08:00
parent 0344e51170
commit 9eea3c9247
2 changed files with 58 additions and 45 deletions

View File

@ -536,9 +536,9 @@
"compressed_size_bytes": 3242506
},
"data/input/gb/great_kneighton/screenshots/center.zip": {
"checksum": "cce62738db1dd92440bc74e3dd9a136b",
"uncompressed_size_bytes": 39127370,
"compressed_size_bytes": 39111583
"checksum": "a08d6da6f4d628b1936e0e33e3e859b7",
"uncompressed_size_bytes": 39131751,
"compressed_size_bytes": 39116018
},
"data/input/gb/hampton/osm/cambridgeshire-latest.osm.pbf": {
"checksum": "c4ec8f81dc604526443750f695886ebf",
@ -996,9 +996,9 @@
"compressed_size_bytes": 3865424
},
"data/input/pl/krakow/screenshots/center.zip": {
"checksum": "ead5a241b2afa3336d8f11ee0b2e59af",
"uncompressed_size_bytes": 28338189,
"compressed_size_bytes": 28333173
"checksum": "cda45914d3783c17769d57060b65d344",
"uncompressed_size_bytes": 28541114,
"compressed_size_bytes": 28536036
},
"data/input/pl/warsaw/osm/center.osm": {
"checksum": "b41830dd375674ffc9f7ec15d6cf9c0c",
@ -1396,24 +1396,24 @@
"compressed_size_bytes": 6234114
},
"data/input/us/seattle/screenshots/downtown.zip": {
"checksum": "3b4f6486f5b842183492fcc7c4353c46",
"uncompressed_size_bytes": 22571887,
"compressed_size_bytes": 22563432
"checksum": "981a0b2d1af0f3bc3ac1acc0f5646120",
"uncompressed_size_bytes": 22566418,
"compressed_size_bytes": 22558043
},
"data/input/us/seattle/screenshots/lakeslice.zip": {
"checksum": "764afab8073128dadae08ac60d766769",
"uncompressed_size_bytes": 21970128,
"compressed_size_bytes": 21963553
"checksum": "7b5fabeb176ab7e6223c1549e36fa3b2",
"uncompressed_size_bytes": 22210060,
"compressed_size_bytes": 22203619
},
"data/input/us/seattle/screenshots/montlake.zip": {
"checksum": "4900bdfdda7b477e181a723e4763891f",
"uncompressed_size_bytes": 4326100,
"compressed_size_bytes": 4325840
"checksum": "b2c7cc9ae9e982ab0881397813e2a7b3",
"uncompressed_size_bytes": 4324585,
"compressed_size_bytes": 4324336
},
"data/input/us/seattle/screenshots/udistrict.zip": {
"checksum": "182944dbdf70f24edc8b0f62847e7c40",
"uncompressed_size_bytes": 10597038,
"compressed_size_bytes": 10593822
"checksum": "5d2a932a8b44588c079e8ce33bffa894",
"uncompressed_size_bytes": 10592157,
"compressed_size_bytes": 10588951
},
"data/input/us/seattle/trips_2014.csv": {
"checksum": "d4a8e733045b28c0385fb81359d6df03",

View File

@ -229,37 +229,50 @@ pub fn calculate_corners(i: &Intersection, map: &Map) -> Vec<Polygon> {
if map.get_l(turn.id.src).dst_i != i.id {
continue;
}
let width = map
.get_l(turn.id.src)
.width
.min(map.get_l(turn.id.dst).width);
// Special case for dead-ends: just thicken the geometry.
if i.roads.len() == 1 {
corners.push(turn.geom.make_polygons(width));
continue;
}
let l1 = map.get_l(turn.id.src);
let l2 = map.get_l(turn.id.dst);
if let Some(poly) = (|| {
let mut pts = turn.geom.shift_left(width / 2.0).ok()?.into_points();
pts.push(l2.first_line().shift_left(width / 2.0).pt1());
pts.push(l2.first_line().shift_right(width / 2.0).pt1());
pts.extend(
turn.geom
.shift_right(width / 2.0)
.ok()?
.reversed()
.into_points(),
);
pts.push(l1.last_line().shift_right(width / 2.0).pt2());
pts.push(l1.last_line().shift_left(width / 2.0).pt2());
// Special case for dead-ends: just thicken the geometry.
if i.roads.len() == 1 {
corners.push(turn.geom.make_polygons(l1.width.min(l2.width)));
continue;
}
if l1.width == l2.width {
// When two sidewalks or two shoulders meet, use the turn geometry to create some
// nice rounding.
let width = l1.width;
if let Some(poly) = (|| {
let mut pts = turn.geom.shift_left(width / 2.0).ok()?.into_points();
pts.push(l2.first_line().shift_left(width / 2.0).pt1());
pts.push(l2.first_line().shift_right(width / 2.0).pt1());
pts.extend(
turn.geom
.shift_right(width / 2.0)
.ok()?
.reversed()
.into_points(),
);
pts.push(l1.last_line().shift_right(width / 2.0).pt2());
pts.push(l1.last_line().shift_left(width / 2.0).pt2());
pts.push(pts[0]);
// Many resulting shapes aren't valid rings, but we can still triangulate them.
Some(Polygon::buggy_new(pts))
})() {
corners.push(poly);
}
} else {
// When a sidewalk and a shoulder meet, use a simpler shape to connect them.
let mut pts = vec![
l2.first_line().shift_left(l2.width / 2.0).pt1(),
l2.first_line().shift_right(l2.width / 2.0).pt1(),
l1.last_line().shift_right(l1.width / 2.0).pt2(),
l1.last_line().shift_left(l1.width / 2.0).pt2(),
];
pts.push(pts[0]);
Some(Polygon::buggy_new(pts))
})() {
corners.push(poly);
if let Ok(ring) = Ring::new(pts) {
corners.push(ring.to_polygon());
}
}
}
}