1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::math::{Point, Real};
use crate::shape::Ball;
use na::{self, ComplexField};

/// Distance between balls.
#[inline]
pub fn distance_ball_ball(b1: &Ball, center2: &Point<Real>, b2: &Ball) -> Real {
    let r1 = b1.radius;
    let r2 = b2.radius;
    let distance_squared = center2.coords.norm_squared();
    let sum_radius = r1 + r2;

    if distance_squared <= sum_radius * sum_radius {
        0.0
    } else {
        ComplexField::sqrt(distance_squared) - sum_radius
    }
}