use super::{Interpolatable, Traj};
use crate::linalg::DefaultAllocator;
use crate::linalg::allocator::Allocator;
use crate::time::TimeSeries;
use log::{error, log_enabled};
pub struct TrajIterator<'a, S: Interpolatable>
where
DefaultAllocator: Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
pub time_series: TimeSeries,
pub traj: &'a Traj<S>,
}
impl<S: Interpolatable> Iterator for TrajIterator<'_, S>
where
DefaultAllocator: Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
type Item = S;
fn next(&mut self) -> Option<Self::Item> {
match self.time_series.next() {
Some(next_epoch) => match self.traj.at(next_epoch) {
Ok(item) => Some(item),
Err(e) => {
if next_epoch >= self.traj.first().epoch()
&& next_epoch <= self.traj.last().epoch()
{
let msg = format!(
"{e} out of bounds in {}! Please submit bug report with exported traj",
self.traj
);
if log_enabled!(log::Level::Error) {
error!("{msg}");
} else {
eprintln!("{msg}");
};
}
None
}
},
None => None,
}
}
}