fbxcel_dom/v7400/data/mesh/
control_point.rs1use mint::Point3;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct ControlPointIndex(u32);
8
9impl ControlPointIndex {
10 pub(crate) fn new(v: u32) -> Self {
12 Self(v)
13 }
14
15 pub fn to_u32(self) -> u32 {
17 self.0
18 }
19
20 #[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#[derive(Debug, Clone, Copy)]
29pub(crate) struct ControlPoints<'a> {
30 data: &'a [f64],
32}
33
34impl<'a> ControlPoints<'a> {
35 pub(crate) fn new(data: &'a [f64]) -> Self {
37 Self { data }
38 }
39
40 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 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}