PointTmplDec.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _PointTmplDec_
00024 #define _PointTmplDec_
00025
00026 #include <iosfwd>
00027 #include "CLAM_Math.hxx"
00028
00029 namespace CLAM
00030 {
00031
00032 template <typename TX = TData, typename TY = TX> class PointTmpl
00033 {
00034 public:
00035
00036 PointTmpl() : mX(0), mY(0)
00037 {};
00038
00039 PointTmpl(TX xValue,TY yValue)
00040 {
00041 mX=xValue;
00042 mY=yValue;
00043 }
00044
00045
00046 const TX& GetX() const{return mX;}
00047 const TY& GetY() const{return mY;}
00048
00049
00050 void SetX(TX xValue){mX=xValue;}
00051 void SetY(TY yValue){mY=yValue;}
00052
00053
00054 const PointTmpl<TX,TY>& operator=(const PointTmpl<TX,TY>& newPoint)
00055 {
00056 mX=newPoint.mX;
00057 mY=newPoint.mY;
00058 return *this;
00059 }
00060 const PointTmpl<TX,TY>& operator+=(const PointTmpl<TX,TY>& newPoint)
00061 {
00062 mX+=newPoint.mX;
00063 mY+=newPoint.mY;
00064 return *this;
00065 }
00066 const PointTmpl<TX,TY>& operator-=(const PointTmpl<TX,TY>& newPoint)
00067 {
00068 mX-=newPoint.mX;
00069 mY-=newPoint.mY;
00070 return *this;
00071 }
00072 bool operator<(const PointTmpl<TX,TY>& newPoint)const{return mX<newPoint.GetX();}
00073 bool operator<=(const PointTmpl<TX,TY>& newPoint)const{return mX<=newPoint.GetX();}
00074 bool operator>(const PointTmpl<TX,TY>& newPoint)const{return mX>newPoint.GetX();}
00075 bool operator>=(const PointTmpl<TX,TY>& newPoint)const{return mX>=newPoint.GetX();}
00076 bool operator!=(const PointTmpl<TX,TY>& newPoint)const{return (mX!=newPoint.GetX());}
00077 bool operator==(const PointTmpl<TX,TY>& newPoint)const{return (mX==newPoint.GetX());}
00078
00079
00080 double Distance(const PointTmpl<TX,TY>& newPoint)const
00081 {
00082 return CLAM_pow((TData)CLAM_pow((TData)(mX-newPoint.mX),(TData)2)+CLAM_pow((TData)(mY-newPoint.mY),(TData)2),(TData)0.5);
00083 }
00084
00085
00086 PointTmpl<TX,TY> operator-(const PointTmpl<TX,TY>& otherPoint)
00087 {
00088 PointTmpl<TX,TY> result(mX-otherPoint.mX,mY-otherPoint.mY);
00089 return result;
00090 }
00091 PointTmpl<TX,TY> operator+(const PointTmpl<TX,TY>& otherPoint)
00092 {
00093 PointTmpl<TX,TY> result(mX+otherPoint.mX,mY+otherPoint.mY);
00094 return result;
00095 }
00096
00097 protected:
00098
00099
00100 TX mX;
00101 TY mY;
00102 };
00103
00104 template <class TX,class TY>
00105 std::istream& operator >> (std::istream & stream, PointTmpl<TX,TY> & a);
00106
00107 template <class TX,class TY>
00108 std::ostream& operator << (std::ostream & stream, const PointTmpl<TX,TY> & a);
00109
00110 }
00111
00112 #endif // _PointTmplDec_
00113