Skip to content

Commit 0b91874

Browse files
author
mlund
committed
Add icosahedron face area test
1 parent c67f5ea commit 0b91874

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/icosphere.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,18 @@ mod tests {
225225
let c = Vec3A::new(0.0, 0.0, 1.0);
226226
let area = spherical_face_area(&a, &b, &c);
227227
assert_relative_eq!(area, 0.5 * PI, epsilon = 1e-6);
228+
229+
// Sum face area of a regular icosahedron - should be 4π
230+
let icosahedron = IcoSphere::new(0, |_| ());
231+
let indices = icosahedron.get_all_indices();
232+
let vertices = icosahedron.raw_points();
233+
let face_area = |triangle: &[u32]| {
234+
let a = &vertices[triangle[0] as usize];
235+
let b = &vertices[triangle[1] as usize];
236+
let c = &vertices[triangle[2] as usize];
237+
spherical_face_area(a, b, c)
238+
};
239+
let total_area = indices.chunks(3).map(face_area).sum::<f64>();
240+
assert_relative_eq!(total_area, 4.0 * PI, epsilon = 1e-5);
228241
}
229242
}

0 commit comments

Comments
 (0)