Using TriMesh::cast_local_ray_and_get_normal FeatureId out of bounds if the face is a backface
- Dominant language
- Rust
- Stars
- 867
- Forks
- 157
- Avg merge
- 7d 13h
- Merged PRs (30d)
- 2
Description
`TriMesh::cast_local_ray_and_get_normal` requires reading source code to use correctly. The issue is that if the ray intersects with a backface, the function sets `feature` to `FeatureId::Face(best + self.indices().len() as u32)`. When I unwrap the index and attempt to read the triangle (using `TriMesh::triangle`), I get an index out of bounds error.
This behavior isn't documented clearly enough. Later I learned that I can use `TriMesh::is_backface` to check whether it's a backface, but even then I can't know how to get the "real index", except by reading the source code and relying on an implementation detail.
Here's a pseudocode to demonstrate the problem
```
let mesh = TriMesh::new( ... );
let ray = ..;
if let Some(intersection) = mesh.cast_local_ray_and_get_normal(&ray, 1000.0, false) {
let tri_index = intersection.feature.unwrap_face();
// if the face is a backface, the following line panics
let tri = mesh.triangle(tri_index);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.