ncollide3d/utils/
point_cloud_support_point.rs

1use crate::math::{Point, Vector};
2use na::{self, RealField};
3
4/// Computes the index of the support point of a cloud of points.
5#[inline]
6pub fn point_cloud_support_point_id<N: RealField + Copy>(
7    dir: &Vector<N>,
8    points: &[Point<N>],
9) -> usize {
10    let mut best_pt = 0;
11    let mut best_dot = points[0].coords.dot(dir);
12
13    for i in 1..points.len() {
14        let p = &points[i];
15        let dot = p.coords.dot(dir);
16
17        if dot > best_dot {
18            best_dot = dot;
19            best_pt = i;
20        }
21    }
22
23    best_pt
24}
25
26/// Computes the support point of a cloud of points.
27#[inline]
28pub fn point_cloud_support_point<N: RealField + Copy>(
29    dir: &Vector<N>,
30    points: &[Point<N>],
31) -> Point<N> {
32    points[point_cloud_support_point_id(dir, points)]
33}