fbxcel_dom/v7400/data/mesh/
control_point.rs

1//! Control point.
2
3use mint::Point3;
4
5/// Control point index (in other words, polygon vertex).
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct ControlPointIndex(u32);
8
9impl ControlPointIndex {
10    /// Creates a new `ControlPointIndex`.
11    pub(crate) fn new(v: u32) -> Self {
12        Self(v)
13    }
14
15    /// Returns the raw index.
16    pub fn to_u32(self) -> u32 {
17        self.0
18    }
19
20    /// Returns the raw index.
21    #[deprecated(since = "0.0.3", note = "Renamed to `to_u32`")]
22    pub fn get_u32(self) -> u32 {
23        self.to_u32()
24    }
25}
26
27/// Control points.
28#[derive(Debug, Clone, Copy)]
29pub(crate) struct ControlPoints<'a> {
30    /// Control points.
31    data: &'a [f64],
32}
33
34impl<'a> ControlPoints<'a> {
35    /// Creates a new `ControlPoints`.
36    pub(crate) fn new(data: &'a [f64]) -> Self {
37        Self { data }
38    }
39
40    /// Returns a control point at the given index.
41    pub(crate) fn get(&self, index: ControlPointIndex) -> Option<Point3<f64>> {
42        let i3 = index.to_u32() as usize * 3;
43        if self.data.len() < i3 + 2 {
44            return None;
45        }
46        Some(Point3::from_slice(&self.data[i3..]))
47    }
48
49    /// Returns an iterator through the control points
50    pub(crate) fn iter(&self) -> anyhow::Result<impl Iterator<Item = Point3<f64>> + 'a> {
51        if self.data.len() % 3 != 0 {
52            return Err(anyhow::format_err!(
53                "Mesh did not have valid vertex array size."
54            ));
55        }
56
57        Ok(self.data.chunks(3).map(Point3::from_slice))
58    }
59}