use crate::misc::FloatingPoint;
mod continuous;
mod curve;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DiscontinuityType {
C1,
C2,
G2,
}
pub trait Discontinuity<T> {
fn get_next_discontinuity(&self, ty: DiscontinuityType, start: T, end: T) -> Option<T>;
fn discontinuity_iter(
&self,
ty: DiscontinuityType,
start: T,
end: T,
) -> DiscontinuityIterator<'_, Self, T>
where
Self: Sized,
{
DiscontinuityIterator {
geometry: self,
ty,
next: start,
end,
}
}
}
pub struct DiscontinuityIterator<'a, G, T>
where
G: Discontinuity<T>,
{
geometry: &'a G,
ty: DiscontinuityType,
next: T,
end: T,
}
impl<G, T> Iterator for DiscontinuityIterator<'_, G, T>
where
G: Discontinuity<T>,
T: FloatingPoint,
{
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
let item = self
.geometry
.get_next_discontinuity(self.ty, self.next, self.end);
if let Some(t) = item {
let h = (self.end - self.next) * T::from_f64(1e-12).unwrap();
self.next = t + h;
Some(t)
} else {
None
}
}
}