1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
mod point_cloud;
pub use point_cloud::*;
mod tri_mesh;
pub use tri_mesh::*;
pub use crate::prelude::*;
#[derive(Clone, Debug)]
pub enum Indices {
None,
U8(Vec<u8>),
U16(Vec<u16>),
U32(Vec<u32>),
}
impl Indices {
pub fn into_u32(self) -> Option<Vec<u32>> {
match self {
Self::None => None,
Self::U8(mut values) => Some(values.drain(..).map(|i| i as u32).collect::<Vec<_>>()),
Self::U16(mut values) => Some(values.drain(..).map(|i| i as u32).collect::<Vec<_>>()),
Self::U32(values) => Some(values),
}
}
pub fn to_u32(&self) -> Option<Vec<u32>> {
match self {
Self::None => None,
Self::U8(values) => Some(values.iter().map(|i| *i as u32).collect::<Vec<_>>()),
Self::U16(values) => Some(values.iter().map(|i| *i as u32).collect::<Vec<_>>()),
Self::U32(values) => Some(values.clone()),
}
}
pub fn len(&self) -> Option<usize> {
match self {
Self::None => None,
Self::U8(values) => Some(values.len()),
Self::U16(values) => Some(values.len()),
Self::U32(values) => Some(values.len()),
}
}
}
impl std::default::Default for Indices {
fn default() -> Self {
Self::None
}
}
#[derive(Clone)]
pub enum Positions {
F32(Vec<Vec3>),
F64(Vec<Vector3<f64>>),
}
impl Positions {
pub fn into_f32(self) -> Vec<Vec3> {
match self {
Self::F32(values) => values,
Self::F64(mut values) => values
.drain(..)
.map(|v| Vec3::new(v.x as f32, v.y as f32, v.z as f32))
.collect::<Vec<_>>(),
}
}
pub fn to_f32(&self) -> Vec<Vec3> {
match self {
Self::F32(values) => values.clone(),
Self::F64(values) => values
.iter()
.map(|v| Vec3::new(v.x as f32, v.y as f32, v.z as f32))
.collect::<Vec<_>>(),
}
}
pub fn into_f64(self) -> Vec<Vector3<f64>> {
match self {
Self::F32(mut values) => values
.drain(..)
.map(|v| Vector3::new(v.x as f64, v.y as f64, v.z as f64))
.collect::<Vec<_>>(),
Self::F64(values) => values,
}
}
pub fn to_f64(&self) -> Vec<Vector3<f64>> {
match self {
Self::F32(values) => values
.iter()
.map(|v| Vector3::new(v.x as f64, v.y as f64, v.z as f64))
.collect::<Vec<_>>(),
Self::F64(values) => values.clone(),
}
}
pub fn len(&self) -> usize {
match self {
Self::F32(values) => values.len(),
Self::F64(values) => values.len(),
}
}
}
impl std::default::Default for Positions {
fn default() -> Self {
Self::F32(Vec::new())
}
}
impl std::fmt::Debug for Positions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut d = f.debug_struct("Positions");
match self {
Self::F32(ind) => d.field("f32", &ind.len()),
Self::F64(ind) => d.field("f64", &ind.len()),
};
d.finish()
}
}