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