Skip to content

Commit 238f263

Browse files
author
mlund
committed
Add comments to weight calculation
1 parent 67ffc26 commit 238f263

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/icosphere.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,27 @@ pub fn make_weights(icosphere: &IcoSphere) -> Vec<f64> {
118118
let mut adjency = AdjacencyBuilder::new(vertices.len());
119119
adjency.add_indices(&indices);
120120

121-
for (i, nb) in adjency.finish().iter().enumerate() {
122-
let mut areas = Vec::with_capacity(nb.len());
121+
// Loop over each neighboring face to i'th vertex
122+
for (i, neighbors) in adjency.finish().iter().enumerate() {
123+
let mut areas = Vec::with_capacity(neighbors.len());
124+
// Handle the face made of i with the first and last neighboring vertices
123125
areas.push(spherical_face_area(
124126
i,
125-
*nb.first().unwrap(),
126-
*nb.last().unwrap(),
127+
*neighbors.first().unwrap(),
128+
*neighbors.last().unwrap(),
127129
));
128-
for j in 0..nb.len() - 1 {
129-
let area = spherical_face_area(i, nb[j], nb[j + 1]);
130+
// Handle the faces made of i with each remaining pair of neighboring vertices
131+
for j in 0..neighbors.len() - 1 {
132+
let area = spherical_face_area(i, neighbors[j], neighbors[j + 1]);
130133
areas.push(area);
131134
}
132135
let avg_area = areas.iter().sum::<f64>() / areas.len() as f64;
133136
weights.push(avg_area);
134137
}
135138
assert_eq!(weights.len(), vertices.len());
136139

140+
// Normalize the weights to that they fluctuate around 1.0
141+
// (this has no effect on final results)
137142
let scale = vertices.len() as f64 / weights.iter().sum::<f64>();
138143
weights.iter_mut().for_each(|w| *w *= scale);
139144
weights

0 commit comments

Comments
 (0)