Skip to content

Commit 0c70368

Browse files
committed
use usize for Face
1 parent b54ab60 commit 0c70368

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/icotable.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pub type IcoTableOfSpheres = IcoTable<IcoTable<f64>>;
3232
/// The final `f64` data is stored at vertices of the deepest icospheres.
3333
pub type Table6D = PaddedTable<PaddedTable<IcoTableOfSpheres>>;
3434

35-
/// Represents indices of a face
36-
pub type Face = [u16; 3];
35+
/// Represents vertex indices defining the three corners of a face
36+
pub type Face = [usize; 3];
3737

3838
/// Icosphere table
3939
///
@@ -98,10 +98,10 @@ impl<T: Clone + GetSize> IcoTable<T> {
9898
/// Generate table based on an existing vertices pointer and optionally set default data
9999
pub fn from_vertices(vertices: Arc<OnceLock<Vec<Vertex>>>, data: Option<T>) -> Self {
100100
let num_vertices = vertices.get().unwrap().len();
101-
let data = data.map(|d| OnceLock::from(d)).unwrap_or(OnceLock::new());
101+
let data = data.map(|d| OnceLock::from(d));
102102
Self {
103103
vertices,
104-
data: vec![data; num_vertices],
104+
data: vec![data.unwrap_or_default(); num_vertices],
105105
}
106106
}
107107

@@ -112,7 +112,7 @@ impl<T: Clone + GetSize> IcoTable<T> {
112112
}
113113
Self {
114114
vertices: Arc::new(OnceLock::from(make_vertices(icosphere))),
115-
data: vec![OnceLock::new(); icosphere.raw_points().len()],
115+
data: vec![OnceLock::default(); icosphere.raw_points().len()],
116116
}
117117
}
118118

@@ -159,7 +159,7 @@ impl<T: Clone + GetSize> IcoTable<T> {
159159
/// After this call, `set_vertex_data` can be called again.
160160
pub fn clear_vertex_data(&mut self) {
161161
for data in self.data.iter_mut() {
162-
*data = OnceLock::new();
162+
*data = OnceLock::default();
163163
}
164164
}
165165

@@ -262,9 +262,9 @@ impl<T: Clone + GetSize> IcoTable<T> {
262262
/// Get the three vertices of a face
263263
pub fn face_positions(&self, face: &Face) -> (&Vector3, &Vector3, &Vector3) {
264264
(
265-
self.get_pos(face[0] as usize),
266-
self.get_pos(face[1] as usize),
267-
self.get_pos(face[2] as usize),
265+
self.get_pos(face[0]),
266+
self.get_pos(face[1]),
267+
self.get_pos(face[2]),
268268
)
269269
}
270270

@@ -300,10 +300,10 @@ impl<T: Clone + GetSize> IcoTable<T> {
300300
.cloned()
301301
.map(|i| (i, (self.get_pos(i as usize) - point).norm_squared()))
302302
.sorted_by(|a, b| a.1.partial_cmp(&b.1).unwrap()) // sort ascending
303-
.map(|(i, _)| i) // keep only indices
303+
.map(|(i, _)| i as usize) // keep only indices
304304
.take(2) // take two next nearest distances
305305
.collect_tuple()
306-
.map(|(a, b)| [a, b, nearest as u16]) // append nearest
306+
.map(|(a, b)| [a, b, nearest]) // append nearest
307307
.expect("Face requires exactly three indices")
308308
.iter()
309309
.copied()
@@ -360,10 +360,10 @@ impl IcoTableOfSpheres {
360360
) -> f64 {
361361
let data_ab = Matrix3::<f64>::from_fn(|i, j| {
362362
*self
363-
.get_data(face_a[i] as usize)
363+
.get_data(face_a[i])
364364
.get()
365365
.unwrap()
366-
.get_data(face_b[j] as usize)
366+
.get_data(face_b[j])
367367
.get()
368368
.unwrap()
369369
});
@@ -429,7 +429,7 @@ fn _get_faces_from_icosphere(icosphere: IcoSphere) -> Vec<Face> {
429429
.get_all_indices()
430430
.chunks(3)
431431
.map(|c| {
432-
let v = vec![c[0] as u16, c[1] as u16, c[2] as u16];
432+
let v = vec![c[0] as usize, c[1] as usize, c[2] as usize];
433433
v.try_into().unwrap()
434434
})
435435
.collect_vec()
@@ -441,9 +441,9 @@ impl IcoTable<f64> {
441441
pub fn interpolate(&self, point: &Vector3) -> f64 {
442442
let face = self.nearest_face(point);
443443
let bary = self.barycentric(point, &face);
444-
bary[0] * self.data[face[0] as usize].get().unwrap()
445-
+ bary[1] * self.data[face[1] as usize].get().unwrap()
446-
+ bary[2] * self.data[face[2] as usize].get().unwrap()
444+
bary[0] * self.data[face[0]].get().unwrap()
445+
+ bary[1] * self.data[face[1]].get().unwrap()
446+
+ bary[2] * self.data[face[2]].get().unwrap()
447447
}
448448
/// Generate table based on a minimum number of vertices on the subdivided icosaedron
449449
///
@@ -547,9 +547,6 @@ mod tests {
547547
let icotable = IcoTable::<f64>::from_min_points(42).unwrap();
548548
let icotable_of_spheres = IcoTableOfSpheres::from_min_points(42, icotable).unwrap();
549549
assert_eq!(icotable_of_spheres.data.len(), 42);
550-
assert_eq!(
551-
icotable_of_spheres.data[0].data.get().unwrap().data.len(),
552-
42
553-
);
550+
assert_eq!(icotable_of_spheres.data[0].get().unwrap().data.len(), 42);
554551
}
555552
}

0 commit comments

Comments
 (0)