parry3d/utils/
point_cloud_support_point.rs

1use crate::math::{Point, Real, 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<Real>, points: &[Point<Real>]) -> usize {
6    let mut best_pt = 0;
7    let mut best_dot = points[0].coords.dot(dir);
8
9    for (i, p) in points.iter().enumerate().skip(1) {
10        let dot = p.coords.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<Real>, points: &[Point<Real>]) -> Point<Real> {
24    points[point_cloud_support_point_id(dir, points)]
25}