Skip to content

Commit

Permalink
Fix the biking mode for #393
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Nov 22, 2020
1 parent 594b376 commit d83133f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 3 additions & 4 deletions game/src/devtools/fifteen_min/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ impl State<App> 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(
Expand Down Expand Up @@ -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));

Expand Down
10 changes: 7 additions & 3 deletions map_model/src/connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,15 +91,19 @@ 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 =
petgraph::algo::dijkstra(&graph, *start_lane, None, |(_, _, turn)| {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion map_model/src/pathfind/driving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit d83133f

Please sign in to comment.