Skip to main content

signed_distances_multi

Function signed_distances_multi 

Source
pub fn signed_distances_multi(
    targets: &[Target<'_>],
    points: &[[f32; 3]],
    max_distance: f64,
    out: &mut [f32],
    nearest: &mut [u32],
) -> Result<()>
Expand description

Signed distances from points to the nearest of several targets, with the target each value came from: out[i] and nearest[i] get the value and the target index for points[i].

A target’s value at a point is what signed_distances gives for that point moved into the target’s local space by Target::to_local (Rigid::apply in f64, then rounded to f32), with max_distance rounded up to f32, and made +∞ when its magnitude is above max_distance (compared in f64). The point’s value is the minimum over the targets, so the nearest surface outside every target, or the deepest penetration: the same bits as taking the minimum of separate single-target calls, with ties going to the lowest target index. nearest[i] is that index, or u32::MAX when the value is +∞ (no target within max_distance, or no targets).

The best value so far bounds the next target’s search where that is exact (see pruned_value): always when it is negative (a penetration), and in winding mode when it is not. A positive best cannot bound a pseudonormal target’s search: the point may be inside that target however far its surface is, and only the closest point decides that side.

With the parallel feature, large batches run in chunks on rayon’s pool; the values and indices are the same, bit for bit.

§Errors

Everything is checked before anything is written, so on error out and nearest are unchanged:

  • FieldsError::InvalidInput when the slices differ in length, a point is not finite (in the points’ space or moved into a target’s), max_distance is negative or NaN, or a target’s sign data is not current, or there are u32::MAX targets or more;
  • FieldsError::Query with MeshMismatch or StaleBvh when a target’s BVH does not match its current mesh.