mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +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 => {
|
Outcome::Changed => {
|
||||||
let constraints = if self.panel.is_checked("walking / biking") {
|
let constraints = if self.panel.is_checked("walking / biking") {
|
||||||
PathConstraints::Bike
|
|
||||||
} else {
|
|
||||||
PathConstraints::Pedestrian
|
PathConstraints::Pedestrian
|
||||||
|
} else {
|
||||||
|
PathConstraints::Bike
|
||||||
};
|
};
|
||||||
self.isochrone = Isochrone::new(ctx, app, self.isochrone.start, constraints);
|
self.isochrone = Isochrone::new(ctx, app, self.isochrone.start, constraints);
|
||||||
self.panel = build_panel(
|
self.panel = build_panel(
|
||||||
@ -220,14 +220,13 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc
|
|||||||
// Start of toolbar
|
// Start of toolbar
|
||||||
rows.push(Widget::horiz_separator(ctx, 0.3).margin_above(10));
|
rows.push(Widget::horiz_separator(ctx, 0.3).margin_above(10));
|
||||||
|
|
||||||
// TODO Why does this look backwards?
|
|
||||||
rows.push(Checkbox::toggle(
|
rows.push(Checkbox::toggle(
|
||||||
ctx,
|
ctx,
|
||||||
"walking / biking",
|
"walking / biking",
|
||||||
"walking",
|
"walking",
|
||||||
"biking",
|
"biking",
|
||||||
None,
|
None,
|
||||||
isochrone.constraints == PathConstraints::Bike,
|
isochrone.constraints == PathConstraints::Pedestrian,
|
||||||
));
|
));
|
||||||
rows.push(Btn::plaintext("About").build_def(ctx, None));
|
rows.push(Btn::plaintext("About").build_def(ctx, None));
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use std::collections::{HashMap, HashSet};
|
|||||||
|
|
||||||
use petgraph::graphmap::DiGraphMap;
|
use petgraph::graphmap::DiGraphMap;
|
||||||
|
|
||||||
use geom::Duration;
|
use geom::{Distance, Duration, Speed};
|
||||||
|
|
||||||
pub use crate::pathfind::{
|
pub use crate::pathfind::{
|
||||||
build_graph_for_pedestrians, build_graph_for_vehicles, driving_cost, WalkingNode,
|
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) {
|
if let Some(start_lane) = bldg_to_lane.get(&start) {
|
||||||
let graph = build_graph_for_vehicles(map, constraints);
|
let graph = build_graph_for_vehicles(map, constraints);
|
||||||
let cost_per_lane =
|
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)
|
driving_cost(map.get_l(turn.src), map.get_t(*turn), constraints, map)
|
||||||
});
|
});
|
||||||
for (b, lane) in bldg_to_lane {
|
for (b, lane) in bldg_to_lane {
|
||||||
if let Some(seconds) = cost_per_lane.get(&lane) {
|
if let Some(meters) = cost_per_lane.get(&lane) {
|
||||||
let duration = Duration::seconds(*seconds as f64);
|
let distance = Distance::meters(*meters as f64);
|
||||||
|
let duration = distance / max_bike_speed;
|
||||||
if duration <= time_limit {
|
if duration <= time_limit {
|
||||||
results.insert(b, duration);
|
results.insert(b, duration);
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ fn make_input_graph(
|
|||||||
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 {
|
pub fn driving_cost(lane: &Lane, turn: &Turn, constraints: PathConstraints, map: &Map) -> f64 {
|
||||||
// TODO Could cost turns differently.
|
// TODO Could cost turns differently.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user