use polyzonotope::SparsePolyZonotope;
use sampling_planning::{Euclidean, Path, StateSpace};
#[derive(Debug, Clone)]
pub struct Node<C, const N: usize> {
pub nominal: [f64; N],
pub set: SparsePolyZonotope,
pub parent: Option<usize>,
pub control: Option<C>,
}
pub(crate) fn branch<C, const N: usize>(nodes: &[Node<C, N>], node: usize) -> Vec<usize> {
let mut ids = vec![node];
let mut cursor = node;
while let Some(parent) = nodes[cursor].parent {
ids.push(parent);
cursor = parent;
}
ids.reverse();
ids
}
pub(crate) fn nominal_path<C, const N: usize>(nodes: &[Node<C, N>], node: usize) -> Path<[f64; N]> {
let states: Vec<[f64; N]> = branch(nodes, node)
.into_iter()
.map(|id| nodes[id].nominal)
.collect();
let cost = states
.windows(2)
.map(|pair| Euclidean::<N>.distance(&pair[0], &pair[1]))
.sum();
Path { states, cost }
}