pub struct MeshRayIndex<'m> { /* private fields */ }Expand description
A broad-phase index a caller builds once and casts against many times.
This is the zero-bookkeeping form of the cache below. It borrows the mesh for its whole life, so the borrow checker – not a runtime digest – guarantees the geometry cannot move underneath it:
let mut mesh = TriMesh::new(
vec![Point3::new(0.0, 0.0, 0.0), Point3::new(1.0, 0.0, 0.0), Point3::new(0.0, 1.0, 0.0)],
vec![0, 1, 2],
);
let index = MeshRayIndex::build(&mesh, tol);
mesh.positions[0].x = 5.0; // E0502: index still borrows `mesh`
let _ = &index;Use this when casting many rays at one mesh. Prefer
Application::nearest_mesh_hit when casts are incidental: it keeps
its own cache and needs no lifetime plumbing, at the cost of a
content digest per call.
Implementations§
Source§impl<'m> MeshRayIndex<'m>
impl<'m> MeshRayIndex<'m>
Sourcepub fn build(mesh: &'m TriMesh, tolerance: Tolerance) -> Self
pub fn build(mesh: &'m TriMesh, tolerance: Tolerance) -> Self
Build the broad phase for queries at tolerance.
The tolerance is taken at BUILD time because the bounds are padded by it: the narrow phase accepts a hit within tolerance of a triangle, so bounds tight to the vertices can prune a triangle the full scan would accept. Casting with a larger tolerance than the index was built for is rejected rather than silently answered from bounds that are too tight.
O(triangles); repays after ~22 casts.
Sourcepub fn nearest_hit(
&self,
ray: &Ray3,
tolerance: Tolerance,
) -> Result<Option<RayHit3>, RayMeshError>
pub fn nearest_hit( &self, ray: &Ray3, tolerance: Tolerance, ) -> Result<Option<RayHit3>, RayMeshError>
Nearest hit, identical in result to a full scan.
§Errors
Propagates whatever nearest_hit_among refuses.
Auto Trait Implementations§
impl<'m> Freeze for MeshRayIndex<'m>
impl<'m> RefUnwindSafe for MeshRayIndex<'m>
impl<'m> Send for MeshRayIndex<'m>
impl<'m> Sync for MeshRayIndex<'m>
impl<'m> Unpin for MeshRayIndex<'m>
impl<'m> UnwindSafe for MeshRayIndex<'m>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more