Skip to main content

triangles_near

Function triangles_near 

Source
pub fn triangles_near(
    mesh_a: &Mesh,
    bvh_a: &Bvh,
    mesh_b: &Mesh,
    bvh_b: &Bvh,
    xf: &Rigid,
    margin: f32,
    out_a: &mut Vec<TriangleId>,
    out_b: &mut Vec<TriangleId>,
) -> Result<()>
Expand description

Appends to out_a every alive triangle of A within margin of B, and to out_b every alive triangle of B within margin of A, with B placed in A’s space by xf. Elements already in the vectors are kept and stay in front; each appended part is in ascending order without duplicates.

A pair of triangles is near when it intersects or touches (decided exactly), or when its f64 distance is at most margin, compared as f64 distance <= f64::from(margin). So a margin of 0 finds the triangles that touch, intersect, or are closer than f64 rounding resolves, as for a distance of 0 in mesh_distance: a pair with a positive gap whose computed distance rounds to 0 counts as near, so a margin of 0 can find pairs for which intersects (exact) would be false.

Both sides come from the same pair tests, so they agree pair for pair; a second call with the meshes swapped and Rigid::inverse could differ at the rounding level.

Before deduplication, each vector temporarily holds a triangle once per near pair it belongs to (a triangle near k triangles of the other mesh is held k times), and keeps that capacity afterwards.

Passing the same mesh twice means two coincident copies, as for intersects.

§Errors

QueryError::InvalidInput for an invalid xf (see Rigid) or a margin that is negative or NaN; then QueryError::MeshMismatch or QueryError::StaleBvh as for intersects; and QueryError::OutOfMemory when either vector cannot grow. On any error both vectors keep their original lengths.