00001 #ifndef __AABOX__ 00002 #define __AABOX__ 00003 00004 #include <float.h> 00005 #undef min 00006 #undef max 00007 00008 namespace apig { 00009 00010 class AABox { 00011 public: 00012 AABox() : min(FLT_MAX, FLT_MAX, FLT_MAX), max(-FLT_MAX, -FLT_MAX, -FLT_MAX) {} 00013 00014 void add(const Vec3 &p) { 00015 if (p.x < min.x) min.x = p.x; 00016 if (p.y < min.y) min.y = p.y; 00017 if (p.z < min.z) min.z = p.z; 00018 if (p.x > max.x) max.x = p.x; 00019 if (p.y > max.y) max.y = p.y; 00020 if (p.z > max.z) max.z = p.z; 00021 } 00022 00023 Vec3 center() const { return (min + max) / 2; } 00024 float radius() const { return (max - min).norm() / 2; } 00025 00026 public: 00027 Vec3 min, max; 00028 }; 00029 00030 } 00031 00032 #endif 00033