mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
Fix the biking mode for #393
This commit is contained in:
parent
594b376734
commit
d83133fa09
@ -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(
|
||||
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user