Skip to main content

draco_core/
geometry_indices.rs

1/// Index of a unique attribute value.
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
3pub struct AttributeValueIndex(pub u32);
4
5/// Index of a point in point-cloud or mesh geometry.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub struct PointIndex(pub u32);
8
9/// Index of a corner-table vertex.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
11pub struct VertexIndex(pub u32);
12
13/// Index of a corner in triangle corner-table topology.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct CornerIndex(pub u32);
16
17impl std::ops::Add<u32> for CornerIndex {
18    type Output = CornerIndex;
19    fn add(self, rhs: u32) -> CornerIndex {
20        CornerIndex(self.0 + rhs)
21    }
22}
23
24impl std::ops::Sub<u32> for CornerIndex {
25    type Output = CornerIndex;
26    fn sub(self, rhs: u32) -> CornerIndex {
27        CornerIndex(self.0 - rhs)
28    }
29}
30
31impl From<CornerIndex> for u32 {
32    fn from(ci: CornerIndex) -> u32 {
33        ci.0
34    }
35}
36
37/// Index of a triangle face.
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
39pub struct FaceIndex(pub u32);
40
41/// Sentinel attribute value index used for missing mappings.
42pub const INVALID_ATTRIBUTE_VALUE_INDEX: AttributeValueIndex = AttributeValueIndex(u32::MAX);
43/// Sentinel point index.
44pub const INVALID_POINT_INDEX: PointIndex = PointIndex(u32::MAX);
45/// Sentinel corner-table vertex index.
46pub const INVALID_VERTEX_INDEX: VertexIndex = VertexIndex(u32::MAX);
47/// Sentinel corner index.
48pub const INVALID_CORNER_INDEX: CornerIndex = CornerIndex(u32::MAX);
49/// Sentinel face index.
50pub const INVALID_FACE_INDEX: FaceIndex = FaceIndex(u32::MAX);
51
52impl From<u32> for AttributeValueIndex {
53    fn from(v: u32) -> Self {
54        Self(v)
55    }
56}
57
58impl From<AttributeValueIndex> for u32 {
59    fn from(v: AttributeValueIndex) -> Self {
60        v.0
61    }
62}
63
64impl From<u32> for PointIndex {
65    fn from(v: u32) -> Self {
66        Self(v)
67    }
68}
69
70impl From<PointIndex> for u32 {
71    fn from(v: PointIndex) -> Self {
72        v.0
73    }
74}
75
76impl From<usize> for PointIndex {
77    fn from(v: usize) -> Self {
78        Self(v as u32)
79    }
80}
81
82impl From<PointIndex> for usize {
83    fn from(v: PointIndex) -> Self {
84        v.0 as usize
85    }
86}