Skip to content

Commit

Permalink
Better snapping heuristic: if only a small section of a cyclepath is …
Browse files Browse the repository at this point in the history
…close to a parallel road, don't snap it at all. #330
  • Loading branch information
dabreegster committed Jul 14, 2021
1 parent 9237afb commit a1a9787
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion convert_osm/src/snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ fn v1(
let cycleway_half_width = (cycleway.total_width / 2.0) + buffer_from_cycleway;
// Walk along the cycleway's center line
let mut dist = Distance::ZERO;
let mut matches_here = Vec::new();
loop {
let (pt, cycleway_angle) = cycleway.center.must_dist_along(dist);
let perp_line = Line::must_new(
Expand All @@ -160,7 +161,7 @@ fn v1(
.opposite()
.approx_eq(cycleway_angle, parallel_threshold)
{
matches.insert(cycleway.id, road_pair);
matches_here.push(road_pair);
// Just stop at the first, closest hit. One point along a cycleway might be
// close to multiple road edges, but we want the closest hit.
break;
Expand All @@ -174,6 +175,19 @@ fn v1(
dist += step_size;
dist = dist.min(cycleway.center.length());
}

// If only part of this cyclepath snapped to a parallel road, just keep it separate.
let pct_snapped = (matches_here.len() as f64) / (cycleway.center.length() / step_size);
info!(
"Only {}% of {} snapped to a road",
(pct_snapped * 100.0).round(),
cycleway.id
);
if pct_snapped >= 0.8 {
for pair in matches_here {
matches.insert(cycleway.id, pair);
}
}
}

if DEBUG_OUTPUT {
Expand Down

0 comments on commit a1a9787

Please sign in to comment.