fbxcel_dom/v7400/data/mesh/
triangle_vertex_index.rs1use mint::Point3;
4
5use crate::v7400::data::mesh::{
6 ControlPointIndex, PolygonIndex, PolygonVertex, PolygonVertexIndex, PolygonVertices,
7};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub struct TriangleVertexIndex(usize);
12
13impl TriangleVertexIndex {
14 pub(crate) fn new(i: usize) -> Self {
16 Self(i)
17 }
18
19 pub fn to_usize(self) -> usize {
21 self.0
22 }
23
24 #[deprecated(since = "0.0.3", note = "Renamed to `to_usize`")]
26 pub fn get(self) -> usize {
27 self.to_usize()
28 }
29
30 pub fn triangle_index(self) -> TriangleIndex {
32 TriangleIndex::new(self.0 / 3)
33 }
34}
35
36#[derive(Debug, Clone)]
40pub struct TriangleVertices<'a> {
41 polygon_vertices: PolygonVertices<'a>,
43 tri_pv_indices: Vec<PolygonVertexIndex>,
45 tri_poly_indices: Vec<PolygonIndex>,
47}
48
49impl<'a> TriangleVertices<'a> {
50 pub(crate) fn new(
52 polygon_vertices: PolygonVertices<'a>,
53 tri_pv_indices: Vec<PolygonVertexIndex>,
54 tri_poly_indices: Vec<PolygonIndex>,
55 ) -> Self {
56 Self {
57 polygon_vertices,
58 tri_pv_indices,
59 tri_poly_indices,
60 }
61 }
62
63 pub fn polygon_vertices(&self) -> PolygonVertices<'a> {
65 self.polygon_vertices
66 }
67
68 pub fn polygon_vertex_index(&self, tri_vi: TriangleVertexIndex) -> Option<PolygonVertexIndex> {
70 self.tri_pv_indices.get(tri_vi.to_usize()).cloned()
71 }
72
73 pub fn polygon_vertex(&self, i: impl Into<IntoPvWithTriVerts>) -> Option<PolygonVertex> {
75 i.into().polygon_vertex(self)
76 }
77
78 pub fn control_point_index(
80 &self,
81 i: impl Into<IntoCpiWithTriVerts>,
82 ) -> Option<ControlPointIndex> {
83 i.into().control_point_index(self)
84 }
85
86 pub fn control_point(&self, i: impl Into<IntoCpiWithTriVerts>) -> Option<Point3<f64>> {
88 self.control_point_index(i.into())
89 .and_then(|cpi| self.polygon_vertices.control_point(cpi))
90 }
91
92 pub fn len(&self) -> usize {
94 self.tri_pv_indices.len()
95 }
96
97 pub fn is_empty(&self) -> bool {
99 self.tri_pv_indices.is_empty()
100 }
101
102 pub fn iter_control_point_indices(
104 &self,
105 ) -> impl Iterator<Item = Option<ControlPointIndex>> + '_ {
106 (0..self.len())
107 .map(TriangleVertexIndex::new)
108 .map(move |tri_vi| self.control_point_index(tri_vi))
109 }
110
111 pub fn polygon_index(&self, tri_i: TriangleIndex) -> Option<PolygonIndex> {
113 self.tri_poly_indices.get(tri_i.to_usize()).cloned()
114 }
115
116 pub fn triangle_vertex_indices(&self) -> impl Iterator<Item = TriangleVertexIndex> {
118 (0..self.len()).map(TriangleVertexIndex::new)
119 }
120}
121
122#[derive(Debug, Clone, Copy)]
124pub struct TriangleIndex(usize);
125
126impl TriangleIndex {
127 fn new(v: usize) -> Self {
129 Self(v)
130 }
131
132 pub fn to_usize(self) -> usize {
134 self.0
135 }
136
137 #[deprecated(since = "0.0.3", note = "Renamed to `to_usize`")]
139 pub fn get(self) -> usize {
140 self.to_usize()
141 }
142}
143
144#[derive(Debug, Clone, Copy)]
152#[non_exhaustive]
153pub enum IntoPvWithTriVerts {
154 PolygonVertex(PolygonVertex),
156 PolygonVertexIndex(PolygonVertexIndex),
158 TriangleVertexIndex(TriangleVertexIndex),
160}
161
162impl IntoPvWithTriVerts {
163 fn polygon_vertex(&self, triangle_vertices: &TriangleVertices<'_>) -> Option<PolygonVertex> {
165 match *self {
166 IntoPvWithTriVerts::PolygonVertex(pv) => Some(pv),
167 IntoPvWithTriVerts::PolygonVertexIndex(pvi) => {
168 triangle_vertices.polygon_vertices.polygon_vertex(pvi)
169 }
170 IntoPvWithTriVerts::TriangleVertexIndex(tri_vi) => triangle_vertices
171 .polygon_vertex_index(tri_vi)
172 .and_then(|pvi| triangle_vertices.polygon_vertices.polygon_vertex(pvi)),
173 }
174 }
175}
176
177impl From<PolygonVertex> for IntoPvWithTriVerts {
178 fn from(i: PolygonVertex) -> Self {
179 IntoPvWithTriVerts::PolygonVertex(i)
180 }
181}
182
183impl From<&PolygonVertex> for IntoPvWithTriVerts {
184 fn from(i: &PolygonVertex) -> Self {
185 IntoPvWithTriVerts::PolygonVertex(*i)
186 }
187}
188
189impl From<PolygonVertexIndex> for IntoPvWithTriVerts {
190 fn from(i: PolygonVertexIndex) -> Self {
191 IntoPvWithTriVerts::PolygonVertexIndex(i)
192 }
193}
194
195impl From<&PolygonVertexIndex> for IntoPvWithTriVerts {
196 fn from(i: &PolygonVertexIndex) -> Self {
197 IntoPvWithTriVerts::PolygonVertexIndex(*i)
198 }
199}
200
201impl From<TriangleVertexIndex> for IntoPvWithTriVerts {
202 fn from(i: TriangleVertexIndex) -> Self {
203 IntoPvWithTriVerts::TriangleVertexIndex(i)
204 }
205}
206
207impl From<&TriangleVertexIndex> for IntoPvWithTriVerts {
208 fn from(i: &TriangleVertexIndex) -> Self {
209 IntoPvWithTriVerts::TriangleVertexIndex(*i)
210 }
211}
212
213#[derive(Debug, Clone, Copy)]
224#[non_exhaustive]
225pub enum IntoCpiWithTriVerts {
226 ControlPointIndex(ControlPointIndex),
228 IntoPolygonVertex(IntoPvWithTriVerts),
230}
231
232impl IntoCpiWithTriVerts {
233 fn control_point_index(
235 &self,
236 triangle_vertices: &TriangleVertices<'_>,
237 ) -> Option<ControlPointIndex> {
238 match *self {
239 IntoCpiWithTriVerts::ControlPointIndex(cpi) => Some(cpi),
240 IntoCpiWithTriVerts::IntoPolygonVertex(into_pv) => {
241 into_pv.polygon_vertex(triangle_vertices).map(Into::into)
242 }
243 }
244 }
245}
246
247impl<T: Into<IntoPvWithTriVerts>> From<T> for IntoCpiWithTriVerts {
248 fn from(i: T) -> Self {
249 IntoCpiWithTriVerts::IntoPolygonVertex(i.into())
250 }
251}
252
253impl From<ControlPointIndex> for IntoCpiWithTriVerts {
254 fn from(i: ControlPointIndex) -> Self {
255 IntoCpiWithTriVerts::ControlPointIndex(i)
256 }
257}
258
259impl From<&ControlPointIndex> for IntoCpiWithTriVerts {
260 fn from(i: &ControlPointIndex) -> Self {
261 IntoCpiWithTriVerts::ControlPointIndex(*i)
262 }
263}