maps: cap walk/bike trip length, no far traffic prefetch on overlay routes
- Commit
6bfcb0599381f0a9bb5a9672755bc49afda8d1ea- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-25 04:34 UTC (1 month ago)
- Parents
7f11d68
Diff
maps/src/main/rust/src/graph_overlay.rs
diff --git a/maps/src/main/rust/src/graph_overlay.rs b/maps/src/main/rust/src/graph_overlay.rsindex 21c263ffe5..d9c919438c 100644--- a/maps/src/main/rust/src/graph_overlay.rs+++ b/maps/src/main/rust/src/graph_overlay.rs@@ -370,6 +370,10 @@ mod overlay_tests { /// A ~220 km motorway along the equator with a residential road 1.1 km north /// of it, joined by a residential connector at every node. Motorway ids /// `0..SPAN`, residential ids `SPAN..2*SPAN`.+ pub(super) fn corridor_graph() -> Graph {+ corridor()+ }+ fn corridor() -> Graph { let mut nodes = Vec::new(); for lat in [0, 100_000] {@@ -461,3 +465,30 @@ mod overlay_tests { assert!(g.overlay().is_none()); } }++#[cfg(test)]+mod trip_limit_tests {+ use crate::geometry::TrafficSpeeds;+ use crate::graph::{BICYCLE, DRIVING, WALK};+ use crate::routing::prepare_routing;+ use crate::state::{RadixHeap, RoutingScratchpad};++ /// A cross-country walk or ride is refused before any search, so it costs+ /// nothing; driving the same trip is still planned.+ #[test]+ fn walking_and_cycling_refuse_cross_country_trips() {+ let g = super::overlay_tests::corridor_graph();+ let speeds = TrafficSpeeds::default();+ let (mut scratch, mut heap) = (RoutingScratchpad::new(), RadixHeap::new());+ let mut ensure = |_: i32, _: i32| {};+ let mut plan = |mode, e_lon: f64| {+ prepare_routing(&g, &speeds, &mut ensure, 0.0101, 0.0001, 0.0101, e_lon, mode, &mut scratch, &mut heap)+ .is_some()+ };+ // ~220 km apart.+ assert!(plan(DRIVING, 1.9999));+ assert!(!plan(WALK, 1.9999), "past the walking limit");+ assert!(plan(BICYCLE, 1.9999), "inside the cycling limit");+ assert!(plan(WALK, 0.5), "a 55 km walk is still planned");+ }+}
maps/src/main/rust/src/routing/astar.rs
diff --git a/maps/src/main/rust/src/routing/astar.rs b/maps/src/main/rust/src/routing/astar.rsindex b3fddec160..44c30457b2 100644--- a/maps/src/main/rust/src/routing/astar.rs+++ b/maps/src/main/rust/src/routing/astar.rs@@ -127,7 +127,12 @@ fn search( // Keep expanding: this anchor may also be on the way to the other. } - if mode == DRIVING {+ // The search runs on the traffic snapshot taken when it started, so a+ // prefetch only helps the next route. Across a continent that was ~550+ // one-degree squares per route, each a request plus a native traffic merge+ // and a renderer re-push, which stalled the UI for seconds; keep it to the+ // roads near either end, which are the ones a reroute will need.+ if mode == DRIVING && (overlay.is_none() || is_local(g, lat_u, lon_u, ctx)) { ensure_traffic(lat_u, lon_u); }
maps/src/main/rust/src/routing/search.rs
diff --git a/maps/src/main/rust/src/routing/search.rs b/maps/src/main/rust/src/routing/search.rsindex 749b6f8588..e11cd07b90 100644--- a/maps/src/main/rust/src/routing/search.rs+++ b/maps/src/main/rust/src/routing/search.rs@@ -190,7 +190,22 @@ pub fn find_nearest_edge(g: &Graph, lat: f64, lon: f64, mode: i32) -> SnappedEdg best } -/// Snap endpoints, seed the open set. Returns `None` if snapping fails.+/// Straight-line limit for a walking or cycling route.+///+/// Neither mode uses the highway overlay, so a cross-country request is a full+/// search of every path on the continent: on device LA to NYC on foot ran into+/// the 25M-expansion cap after ~30 s and gigabytes of scratch, and the route+/// sheet plans every mode for every selection. Nobody needs those routes.+fn max_trip_mm(mode: i32) -> Option<u32> {+ match mode {+ WALK | PUBLIC_TRANSIT => Some(150_000_000),+ BICYCLE => Some(300_000_000),+ _ => None,+ }+}++/// Snap endpoints, seed the open set. Returns `None` if snapping fails or the+/// trip is too far to walk or cycle. #[allow(clippy::too_many_arguments)] pub fn prepare_routing( g: &Graph,@@ -207,6 +222,12 @@ pub fn prepare_routing( scratch.reset(); heap.clear(); + if let Some(max) = max_trip_mm(mode) {+ if accurate_dist_mm((s_lat * 1e7) as i32, (s_lon * 1e7) as i32, (e_lat * 1e7) as i32, (e_lon * 1e7) as i32) > max {+ return None;+ }+ }+ let start = find_nearest_edge(g, s_lat, s_lon, mode); let end = find_nearest_edge(g, e_lat, e_lon, mode); if start.node_a == 0xFFFF_FFFF || end.node_a == 0xFFFF_FFFF {