Restrict the LTN route planner to 2 waypoints. Too easy to accidentally click and add a third, and the route overlapping itself is a total mess.

This commit is contained in:
Dustin Carlino 2022-03-23 09:49:08 +00:00
parent e5ea25ec58
commit 696f010301
2 changed files with 15 additions and 1 deletions

View File

@ -46,7 +46,7 @@ impl RoutePlanner {
let mut rp = RoutePlanner {
top_panel: crate::common::app_top_panel(ctx, app),
left_panel: Panel::empty(ctx),
waypoints: InputWaypoints::new(app),
waypoints: InputWaypoints::new_max_2(app),
files: TripManagement::new(app),
world: World::unbounded(),
draw_routes: ToggleZoomed::empty(ctx),

View File

@ -13,6 +13,7 @@ use crate::AppLike;
pub struct InputWaypoints {
waypoints: Vec<Waypoint>,
snap_to_endpts: FindClosest<TripEndpoint>,
max_waypts: Option<usize>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@ -26,6 +27,7 @@ struct Waypoint {
}
impl InputWaypoints {
/// Allows any number of waypoints
pub fn new(app: &dyn AppLike) -> InputWaypoints {
let map = app.map();
let mut snap_to_endpts = FindClosest::new(map.get_bounds());
@ -41,9 +43,18 @@ impl InputWaypoints {
InputWaypoints {
waypoints: Vec::new(),
snap_to_endpts,
max_waypts: None,
}
}
/// Only allow drawing routes with 2 waypoints. If a route is loaded with more than that, it
/// can be modified.
pub fn new_max_2(app: &dyn AppLike) -> Self {
let mut i = Self::new(app);
i.max_waypts = Some(2);
i
}
/// The caller should call `rebuild_world` after this
pub fn overwrite(&mut self, app: &dyn AppLike, waypoints: Vec<TripEndpoint>) {
self.waypoints.clear();
@ -145,6 +156,9 @@ impl InputWaypoints {
) -> bool {
match world_outcome {
WorldOutcome::ClickedFreeSpace(pt) => {
if Some(self.waypoints.len()) == self.max_waypts {
return false;
}
if let Some((at, _)) = self.snap_to_endpts.closest_pt(pt, Distance::meters(30.0)) {
self.waypoints.push(Waypoint::new(app, at));
return true;