use nalgebra::{
allocator::Allocator, DefaultAllocator, DimName, DimNameAdd, DimNameSum, OPoint, U1,
};
use crate::{curve::NurbsCurve, misc::FloatingPoint, region::CompoundCurve};
pub trait ElevateDimension {
type Output;
fn elevate_dimension(&self) -> Self::Output;
}
impl<T: FloatingPoint, D: DimName> ElevateDimension for NurbsCurve<T, D>
where
D: DimNameAdd<U1>,
DefaultAllocator: Allocator<D>,
DefaultAllocator: Allocator<DimNameSum<D, U1>>,
{
type Output = NurbsCurve<T, DimNameSum<D, U1>>;
fn elevate_dimension(&self) -> NurbsCurve<T, DimNameSum<D, U1>>
where
D: DimNameAdd<U1>,
DefaultAllocator: Allocator<DimNameSum<D, U1>>,
{
let mut control_points = vec![];
for p in self.control_points().iter() {
let mut coords = vec![];
for i in 0..(D::dim() - 1) {
coords.push(p[i]);
}
coords.push(T::zero()); coords.push(p[D::dim() - 1]);
control_points.push(OPoint::from_slice(&coords));
}
NurbsCurve::new_unchecked(self.degree(), control_points, self.knots().clone())
}
}
impl<T: FloatingPoint, D: DimName> ElevateDimension for CompoundCurve<T, D>
where
D: DimNameAdd<U1>,
DefaultAllocator: Allocator<D>,
DefaultAllocator: Allocator<DimNameSum<D, U1>>,
{
type Output = CompoundCurve<T, DimNameSum<D, U1>>;
fn elevate_dimension(&self) -> Self::Output {
let spans = self.spans().iter().map(|s| s.elevate_dimension()).collect();
CompoundCurve::new_unchecked(spans)
}
}