From d83133fa094897be9d1497007020d10cffedf45a Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 22 Nov 2020 10:48:41 -0800 Subject: [PATCH] Fix the biking mode for #393 --- game/src/devtools/fifteen_min/mod.rs | 7 +++---- map_model/src/connectivity.rs | 10 +++++++--- map_model/src/pathfind/driving.rs | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/game/src/devtools/fifteen_min/mod.rs b/game/src/devtools/fifteen_min/mod.rs index 3b52dfb271..9d2fb9a4ac 100644 --- a/game/src/devtools/fifteen_min/mod.rs +++ b/game/src/devtools/fifteen_min/mod.rs @@ -150,9 +150,9 @@ impl State for Viewer { }, Outcome::Changed => { let constraints = if self.panel.is_checked("walking / biking") { - PathConstraints::Bike - } else { PathConstraints::Pedestrian + } else { + PathConstraints::Bike }; self.isochrone = Isochrone::new(ctx, app, self.isochrone.start, constraints); self.panel = build_panel( @@ -220,14 +220,13 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc // Start of toolbar rows.push(Widget::horiz_separator(ctx, 0.3).margin_above(10)); - // TODO Why does this look backwards? rows.push(Checkbox::toggle( ctx, "walking / biking", "walking", "biking", None, - isochrone.constraints == PathConstraints::Bike, + isochrone.constraints == PathConstraints::Pedestrian, )); rows.push(Btn::plaintext("About").build_def(ctx, None)); diff --git a/map_model/src/connectivity.rs b/map_model/src/connectivity.rs index be9a35142d..22309a0f2a 100644 --- a/map_model/src/connectivity.rs +++ b/map_model/src/connectivity.rs @@ -4,7 +4,7 @@ use std::collections::{HashMap, HashSet}; use petgraph::graphmap::DiGraphMap; -use geom::Duration; +use geom::{Distance, Duration, Speed}; pub use crate::pathfind::{ build_graph_for_pedestrians, build_graph_for_vehicles, driving_cost, WalkingNode, @@ -91,6 +91,9 @@ pub fn all_costs_from( } } + // TODO Copied from simulation code :( + let max_bike_speed = Speed::miles_per_hour(10.0); + if let Some(start_lane) = bldg_to_lane.get(&start) { let graph = build_graph_for_vehicles(map, constraints); let cost_per_lane = @@ -98,8 +101,9 @@ pub fn all_costs_from( driving_cost(map.get_l(turn.src), map.get_t(*turn), constraints, map) }); for (b, lane) in bldg_to_lane { - if let Some(seconds) = cost_per_lane.get(&lane) { - let duration = Duration::seconds(*seconds as f64); + if let Some(meters) = cost_per_lane.get(&lane) { + let distance = Distance::meters(*meters as f64); + let duration = distance / max_bike_speed; if duration <= time_limit { results.insert(b, duration); } diff --git a/map_model/src/pathfind/driving.rs b/map_model/src/pathfind/driving.rs index 649133a5e0..411a64a902 100644 --- a/map_model/src/pathfind/driving.rs +++ b/map_model/src/pathfind/driving.rs @@ -218,7 +218,7 @@ fn make_input_graph( input_graph } -/// Roughly equivalent to seconds +/// Different unit based on constraints. pub fn driving_cost(lane: &Lane, turn: &Turn, constraints: PathConstraints, map: &Map) -> f64 { // TODO Could cost turns differently.