00001 #ifndef __VECMATH_POINT3_HPP 00002 #define __VECMATH_POINT3_HPP 00003 00004 #ifndef __VECMATH_TUPLE3_HPP 00005 #include <vecmath/_Tuple3.h> 00006 #endif 00007 00008 #ifndef __VECMATH_POINT4_HPP 00009 #include <vecmath/_Point4.h> 00010 #endif 00011 00012 //#define DEBUGPOINT3(d) d 00013 #define DEBUGPOINT3(d) 00014 00015 template <class Type> 00016 class VECMATH_EXPORT _Point3 : public _Tuple3<Type> { 00017 public: 00018 00019 _Point3<Type>() : _Tuple3<Type>() {} 00020 00021 explicit _Point3<Type>(Type x, Type y = 0, Type z = 0) : _Tuple3<Type>(x, y, z) { 00022 DEBUGPOINT3(cout << "_Point3 explicit constructor x,y,z " << *this << endl); 00023 } 00024 00025 _Point3<Type> (const _Tuple3<double>& v) : _Tuple3<Type>(v) { 00026 DEBUGPOINT3(cout << "_Point3 constructor &double " << *this << endl); 00027 } 00028 00029 _Point3<Type> (const _Tuple3<float>& v) : _Tuple3<Type>(v) { 00030 DEBUGPOINT3(cout << "_Point3 constructor &float " << *this << endl); 00031 } 00032 00033 _Point3<Type>(const Type t[3]) : _Tuple3<Type>(t) { 00034 DEBUGPOINT3(cout << "_Point3 constructor t[3] " << *this << endl); 00035 } 00036 00037 Type distanceSquared(const _Point3<Type>& p) const { 00038 return (Math::sqr(this.x - p.x) + 00039 Math::sqr(this.y - p.y) + 00040 Math::sqr(this.z - p.z)); 00041 } 00042 00043 Type distance(const _Point3<Type>& p) const { 00044 return sqrt(distanceSquared(p)); 00045 } 00046 00047 Type distanceL1(const _Point3<Type>& p) const { 00048 return fabs(this.x - p.x) + fabs(this.y - p.y) + fabs(this.z - p.z); 00049 } 00050 00051 Type distanceLinf(const _Point3<Type>& p) const { 00052 Type a = (Type) Math::max(fabs(this.x - p.x), fabs(this.y - p.y)); 00053 return Math::max(a, (Type) fabs(this.z - p.z)); 00054 } 00055 00056 void project(const _Point4<Type>& p) { 00057 this.x /= p.w; 00058 this.y /= p.w; 00059 this.z /= p.w; 00060 } 00061 }; 00062 00063 #endif