use super::{Point2d, Vector2d};
use crate::util::Interval;
pub use algorithms::*;
pub use bezier::*;
mod algorithms;
mod bezier;
pub trait ParametricCurve2d {
fn sample(&self, t: f64) -> Point2d;
fn bounds(&self) -> Interval<f64>;
fn sample_dt(&self, t: f64) -> Vector2d {
let delta = self.bounds().length() * 0.0001;
let p1 = self.sample(t);
let p2 = self.sample(t + delta);
(p2 - p1) / delta
}
fn sample_dt2(&self, t: f64) -> Vector2d {
let delta = self.bounds().length() * 0.0001;
let p1 = self.sample_dt(t);
let p2 = self.sample_dt(t + delta);
(p2 - p1) / delta
}
}
impl<T: ParametricCurve2d + ?Sized> ParametricCurve2d for &T {
fn sample(&self, t: f64) -> Point2d {
(&**self).sample(t)
}
fn bounds(&self) -> Interval<f64> {
(&**self).bounds()
}
fn sample_dt(&self, t: f64) -> Vector2d {
(&**self).sample_dt(t)
}
fn sample_dt2(&self, t: f64) -> Vector2d {
(&**self).sample_dt2(t)
}
}