#include "../inc/geometry/geometry.h"

/* Check to see if a sphere overlaps an AABB */
const bool SphereAABBIntersect( const class Sphere &S, const class AABB &B )
{ 
  float s, d = 0; 
  /* Find the square of the distance from the sphere to the box */
  for( long i=0 ; i<3 ; i++ ) 
  { 
    if( S.center[i] < B.emin(i) )
    {
      s = S.center[i] - B.emin(i);
      d += s*s; 
    }
    else if( S.center[i] > B.emax(i) )
    { 
      s = S.center[i] - B.emax(i);
      d += s*s; 
    }
  }
  return d <= S.radius*S.radius;
}

