pub fn shortcut<Sp, C>(
space: &Sp,
checker: &C,
path: &Path<Sp::State>,
max_edge: f64,
) -> Path<Sp::State>where
Sp: StateSpace,
C: ValidityChecker<Sp>,Expand description
Greedy vertex shortcutting: from each kept state, jumps to the furthest later state that a
direct, valid motion of length at most max_edge reaches.
Deterministic, keeps the first and last state, and only drops states. Each step tries the
candidates from the end of the path backward, so a path of m states costs O(m^2)
motion checks in the worst case and O(m) when long shortcuts exist.
ยงExamples
use sampling_planning::{Euclidean, Path, Validity, ValidityChecker, shortcut};
/// Free space everywhere.
struct Free;
impl ValidityChecker<Euclidean<2>> for Free {
fn check_state(&self, _: &[f64; 2]) -> Validity {
Validity::Valid
}
fn check_motion(&self, _: &Euclidean<2>, _: &[f64; 2], _: &[f64; 2]) -> Validity {
Validity::Valid
}
}
let zigzag = Path {
states: vec![[0.0, 0.0], [1.0, 1.0], [2.0, 0.0]],
cost: 2.0 * 2.0_f64.sqrt(),
};
let straight = shortcut(&Euclidean::<2>, &Free, &zigzag, f64::INFINITY);
assert_eq!(straight.states, [[0.0, 0.0], [2.0, 0.0]]);
assert!((straight.cost - 2.0).abs() < 1e-12);