use mint::Point3;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ControlPointIndex(u32);
impl ControlPointIndex {
pub(crate) fn new(v: u32) -> Self {
Self(v)
}
pub fn to_u32(self) -> u32 {
self.0
}
#[deprecated(since = "0.0.3", note = "Renamed to `to_u32`")]
pub fn get_u32(self) -> u32 {
self.to_u32()
}
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct ControlPoints<'a> {
data: &'a [f64],
}
impl<'a> ControlPoints<'a> {
pub(crate) fn new(data: &'a [f64]) -> Self {
Self { data }
}
pub(crate) fn get(&self, index: ControlPointIndex) -> Option<Point3<f64>> {
let i3 = index.to_u32() as usize * 3;
if self.data.len() < i3 + 2 {
return None;
}
Some(Point3::from_slice(&self.data[i3..]))
}
pub(crate) fn iter(&self) -> anyhow::Result<impl Iterator<Item = Point3<f64>> + 'a> {
if self.data.len() % 3 != 0 {
return Err(anyhow::format_err!(
"Mesh did not have valid vertex array size."
));
}
Ok(self.data.chunks(3).map(Point3::from_slice))
}
}