PointTmplDec.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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         /*Constructors*/
00036                 PointTmpl() : mX(0), mY(0)
00037                 {};
00038 
00039                 PointTmpl(TX xValue,TY yValue)
00040                 {
00041                         mX=xValue;
00042                         mY=yValue;
00043                 }
00044 
00045         /*Getting Values*/
00046                 const TX& GetX() const{return mX;}
00047                 const TY& GetY() const{return mY;}
00048 
00049         /*Setting Values*/
00050                 void SetX(TX xValue){mX=xValue;}
00051                 void SetY(TY yValue){mY=yValue;}
00052 
00053         /*Member operators*/
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         /*member funtion, euclidian distance*/
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         /*non-member operators*/
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         /*member variables, x and y values*/
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 } // namespace CLAM
00111 
00112 #endif // _PointTmplDec_
00113 
Generated by  doxygen 1.6.3