Better snapping heuristic: if only a small section of a cyclepath is close to a parallel road, don't snap it at all. #330

This commit is contained in:
Dustin Carlino 2021-07-13 17:55:58 -07:00
parent 9237afb439
commit a1a97877a5

View File

@ -135,6 +135,7 @@ fn v1(
let cycleway_half_width = (cycleway.total_width / 2.0) + buffer_from_cycleway; let cycleway_half_width = (cycleway.total_width / 2.0) + buffer_from_cycleway;
// Walk along the cycleway's center line // Walk along the cycleway's center line
let mut dist = Distance::ZERO; let mut dist = Distance::ZERO;
let mut matches_here = Vec::new();
loop { loop {
let (pt, cycleway_angle) = cycleway.center.must_dist_along(dist); let (pt, cycleway_angle) = cycleway.center.must_dist_along(dist);
let perp_line = Line::must_new( let perp_line = Line::must_new(
@ -160,7 +161,7 @@ fn v1(
.opposite() .opposite()
.approx_eq(cycleway_angle, parallel_threshold) .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 // 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. // close to multiple road edges, but we want the closest hit.
break; break;
@ -174,6 +175,19 @@ fn v1(
dist += step_size; dist += step_size;
dist = dist.min(cycleway.center.length()); 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 { if DEBUG_OUTPUT {