-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(occara): add test for Shape::mesh()
- Loading branch information
1 parent
8d5e1d2
commit cf3d1f5
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use occara::{ | ||
geom::{Direction, Point}, | ||
shape::Shape, | ||
}; | ||
|
||
#[test] | ||
fn test_mesh_cylinder() { | ||
let plane = Point::new(0.0, 0.0, 0.0).plane_axis_with(&Direction::z()); | ||
let mesh = Shape::cylinder(&plane, 1.0, 1.0).mesh(); | ||
let vertices = mesh.vertices(); | ||
let indices = mesh.indices(); | ||
|
||
// Check mesh is not empty | ||
assert!(vertices.len() > 50, "Too few vertices"); | ||
assert!(indices.len() > 50, "Too few indices"); | ||
|
||
// Check indices are valid | ||
assert!(indices.iter().all(|&i| i < vertices.len()), "Invalid index"); | ||
|
||
// Check vertices form a cylinder | ||
let (min_z, max_z) = vertices | ||
.iter() | ||
.map(|v| v.z()) | ||
.fold((f64::INFINITY, f64::NEG_INFINITY), |(min, max), z| { | ||
(min.min(z), max.max(z)) | ||
}); | ||
|
||
assert!((max_z - min_z - 1.0).abs() < 1e-6, "Incorrect height"); | ||
|
||
let max_radius = vertices | ||
.iter() | ||
.map(|v| (v.x().powi(2) + v.y().powi(2)).sqrt()) | ||
.fold(0.0, f64::max); | ||
|
||
assert!((max_radius - 1.0).abs() < 1e-6, "Incorrect radius"); | ||
} |