use deke_types::SRobotPath;
use crate::error::{MultipathError, MultipathResult};
pub enum ReqPath<const N: usize> {
OneWay(SRobotPath<N, f64>),
Reversible(SRobotPath<N, f64>),
BothWays(SRobotPath<N, f64>, SRobotPath<N, f64>),
ManyWays(Vec<SRobotPath<N, f64>>),
}
pub(crate) struct DirectedOption<const N: usize> {
pub path: SRobotPath<N, f64>,
pub cluster: usize,
}
pub(crate) fn expand<const N: usize>(
req_paths: &[ReqPath<N>],
) -> MultipathResult<(Vec<DirectedOption<N>>, usize)> {
let mut options = Vec::new();
for (cluster, req) in req_paths.iter().enumerate() {
let before = options.len();
match req {
ReqPath::OneWay(p) => options.push(DirectedOption {
path: p.clone(),
cluster,
}),
ReqPath::Reversible(p) => {
options.push(DirectedOption {
path: p.clone(),
cluster,
});
options.push(DirectedOption {
path: p.reversed(),
cluster,
});
}
ReqPath::BothWays(a, b) => {
options.push(DirectedOption {
path: a.clone(),
cluster,
});
options.push(DirectedOption {
path: b.clone(),
cluster,
});
}
ReqPath::ManyWays(ps) => {
for p in ps {
options.push(DirectedOption {
path: p.clone(),
cluster,
});
}
}
}
if options.len() == before {
return Err(MultipathError::EmptyOptions(cluster));
}
}
Ok((options, req_paths.len()))
}