1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::math::{Point, Real};
use na;

/// Computes the center of a set of point.
#[inline]
pub fn center(pts: &[Point<Real>]) -> Point<Real> {
    assert!(
        !pts.is_empty(),
        "Cannot compute the center of less than 1 point."
    );

    let denom: Real = na::convert::<f64, Real>(1.0 / (pts.len() as f64));

    let mut piter = pts.iter();
    let mut res = *piter.next().unwrap() * denom;

    for pt in piter {
        res += pt.coords * denom;
    }

    res
}