#ifndef _AABB_H
  #define _AABB_H

#include "../arithmetic/arithmetics.h"


class AABB {
public:
  Vec3 center;   // x,y,z center
  Vec3 extents;  // x,y,z extents

  AABB():center(Vec3(0,0,0)), extents(Vec3(0,0,0)) {};
  AABB( const Vec3& c, const Vec3& e ): center(c), extents(e) {};

  // Returns true if A overlaps B
  const bool overlaps( const AABB& box ) const
  {
    const Vec3 tmp = box.center - center; //vector from A to B
    return fabs(tmp[0]) <= (extents[0] + box.extents[0])
                       &&
           fabs(tmp[1]) <= (extents[1] + box.extents[1])
                       &&
           fabs(tmp[2]) <= (extents[2] + box.extents[2]);
  };

  const Scalar emin( long i ) const {
    return center[i] - extents[i];
  };

  const Scalar emax( long i ) const {
    return center[i] + extents[i];
  };
};

#endif
