//! Iterable curves, which sample in the form of an iterator in order to support `Vec`-like1//! output whose length cannot be known statically.23use super::Interval;45#[cfg(feature = "alloc")]6use {super::ConstantCurve, alloc::vec::Vec};78/// A curve which provides samples in the form of [`Iterator`]s.9///10/// This is an abstraction that provides an interface for curves which look like `Curve<Vec<T>>`11/// but side-stepping issues with allocation on sampling. This happens when the size of an output12/// array cannot be known statically.13pub trait IterableCurve<T> {14/// The interval over which this curve is parametrized.15fn domain(&self) -> Interval;1617/// Sample a point on this curve at the parameter value `t`, producing an iterator over values.18/// This is the unchecked version of sampling, which should only be used if the sample time `t`19/// is already known to lie within the curve's domain.20///21/// Values sampled from outside of a curve's domain are generally considered invalid; data which22/// is nonsensical or otherwise useless may be returned in such a circumstance, and extrapolation23/// beyond a curve's domain should not be relied upon.24fn sample_iter_unchecked(&self, t: f32) -> impl Iterator<Item = T>;2526/// Sample this curve at a specified time `t`, producing an iterator over sampled values.27/// The parameter `t` is clamped to the domain of the curve.28fn sample_iter_clamped(&self, t: f32) -> impl Iterator<Item = T> {29let t_clamped = self.domain().clamp(t);30self.sample_iter_unchecked(t_clamped)31}3233/// Sample this curve at a specified time `t`, producing an iterator over sampled values.34/// If the parameter `t` does not lie in the curve's domain, `None` is returned.35fn sample_iter(&self, t: f32) -> Option<impl Iterator<Item = T>> {36if self.domain().contains(t) {37Some(self.sample_iter_unchecked(t))38} else {39None40}41}42}4344#[cfg(feature = "alloc")]45impl<T> IterableCurve<T> for ConstantCurve<Vec<T>>46where47T: Clone,48{49fn domain(&self) -> Interval {50self.domain51}5253fn sample_iter_unchecked(&self, _t: f32) -> impl Iterator<Item = T> {54self.value.iter().cloned()55}56}575859