parry3d/utils/
point_cloud_support_point.rs

1use crate::math::Vector;
2
3/// Computes the index of the support point of a cloud of points.
4#[inline]
5pub fn point_cloud_support_point_id(dir: Vector, points: &[Vector]) -> usize {
6    let mut best_pt = 0;
7    let mut best_dot = points[0].dot(dir);
8
9    for (i, p) in points.iter().enumerate().skip(1) {
10        let dot = p.dot(dir);
11
12        if dot > best_dot {
13            best_dot = dot;
14            best_pt = i;
15        }
16    }
17
18    best_pt
19}
20
21/// Computes the support point of a cloud of points.
22#[inline]
23pub fn point_cloud_support_point(dir: Vector, points: &[Vector]) -> Vector {
24    points[point_cloud_support_point_id(dir, points)]
25}