diff --git a/src/lib.rs b/src/lib.rs index 7986c78..d9900ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,8 +72,10 @@ pub fn plan(start: Position, goal: Position, obstacle: Option) -> Plan if path_is_clear(&path_xy, obstacle) { PlanResult::Plan(path_xy) - } else { + } else if path_is_clear(&path_yx, obstacle) { PlanResult::Plan(path_yx) + } else { + PlanResult::NoPlan } } @@ -122,7 +124,7 @@ fn walk(from: u8, dest: u8) -> Vec { (from..dest).map(|coordinate| coordinate + 1).collect() } else { // Descending: [from - 1, ..., dest]. - (dest..from).collect() + (dest..from).rev().collect() } } @@ -172,12 +174,7 @@ impl Planner { /// Replaces the inputs and forgets any previously computed result. pub fn reset(&mut self, start: Position, goal: Position, obstacle: Option) { - self.start = start; - self.goal = goal; - if obstacle.is_some() { - self.obstacle = obstacle; - } - self.result = PlanResult::Pending; + *self = Self::new(start, goal, obstacle); } /// Computes the plan for the current inputs.