use crate::{Heading, Path, Point, Tangent};
pub struct Offset<P, S> {
inner: P,
distance: S,
}
impl<P, S> Offset<P, S> {
pub fn new(inner: P, distance: S) -> Self {
Self { inner, distance }
}
}
impl<P: Path + Tangent + Heading> Path for Offset<P, P::Scalar> {
type Scalar = P::Scalar;
type Point = P::Point;
type Error = P::Error;
fn length(&self) -> Self::Scalar {
self.inner.length()
}
fn sample_at(&self, s: Self::Scalar) -> Result<Self::Point, Self::Error> {
let pos = self.inner.sample_at(s)?;
let tan = self.inner.tangent_at(s)?;
let offset_vec = tan * self.distance;
Ok(pos.translate(offset_vec))
}
}