Point2.H

Go to the documentation of this file.
00001 
00009 #ifndef _MESHLIB_POINT2_H_
00010 #define _MESHLIB_POINT2_H_
00011 
00012 
00013 namespace MeshLib{
00014 
00020 class CPoint2
00021 {
00022         public:
00026     CPoint2(){ m_c[0] = 0; m_c[1] = 0; };
00030     CPoint2( const CPoint2 & uv ) {     m_c[0] = uv.m_c[0]; m_c[1] = uv.m_c[1];};
00034     ~CPoint2(){};
00035         
00039          CPoint2( double  x, double y ) { m_c[0] = x; m_c[1] = y; };
00040         
00044     double & operator[]( int i ) {      assert( i < 2 && i >= 0 ); return m_c[i]; };
00045 
00046                 bool operator==( const CPoint2 & uv ) 
00047                 {
00048                         return ( m_c[0] == uv.m_c[0] && m_c[1] == uv.m_c[1] );
00049                 }
00050 
00054     double  operator[]( int i ) const {         assert( i < 2 && i >= 0 ); return m_c[i]; };
00055 
00059     void operator/=( double s )
00060     {
00061       m_c[0]/=s;
00062       m_c[1]/=s;
00063     }
00064 
00068         double norm() { return sqrt( m_c[0] * m_c[0] + m_c[1] * m_c[1] ); };
00069 
00073         double norm2() { return  m_c[0] * m_c[0] + m_c[1] * m_c[1]; };
00074 
00075         private:
00079                 double m_c[2];
00080 
00081 };
00082 
00089 inline CPoint2 operator+(  CPoint2 & uv0,  CPoint2 & uv1 )
00090 {
00091         CPoint2 uv( uv0[0]+uv1[0], uv0[1] + uv1[1] );
00092         return uv;
00093 };
00094 
00101 inline CPoint2 operator-(  CPoint2 & uv0,  CPoint2 & uv1 )
00102 {
00103         CPoint2 uv( uv0[0]-uv1[0], uv0[1] - uv1[1] );
00104         return uv;
00105 };
00106 
00113 inline CPoint2 operator*(  CPoint2 & uv0, const double s )
00114 {
00115         CPoint2 uv( uv0[0] * s, uv0[1] * s );
00116         return uv;
00117 };
00118 
00126 inline CPoint2 operator/(  CPoint2 & uv0, const double s )
00127 {
00128         CPoint2 uv( uv0[0] / s, uv0[1] / s );
00129         return uv;
00130 };
00131 
00138 inline CPoint2 operator+(  const CPoint2 & uv0,  const CPoint2 & uv1 )
00139 {
00140         CPoint2 uv( uv0[0]+uv1[0], uv0[1] + uv1[1] );
00141         return uv;
00142 };
00143 
00150 inline CPoint2 operator-(  const CPoint2 & uv0,  const CPoint2 & uv1 )
00151 {
00152         CPoint2 uv( uv0[0]-uv1[0], uv0[1] - uv1[1] );
00153         return uv;
00154 };
00155 
00162 inline CPoint2 operator*(  const CPoint2 & uv0, const double s )
00163 {
00164         CPoint2 uv( uv0[0] * s, uv0[1] * s );
00165         return uv;
00166 };
00167 
00174 inline CPoint2 operator/(  const CPoint2 & uv0, const double s )
00175 {
00176         CPoint2 uv( uv0[0] / s, uv0[1] / s );
00177         return uv;
00178 };
00179 
00185 inline double mag2(  CPoint2 & uv )
00186 {
00187         return uv[0] * uv[0] + uv[1] * uv[1];
00188 };
00189 
00195 inline double mag(  CPoint2 & uv )
00196 {
00197         return sqrt(uv[0] * uv[0] + uv[1] * uv[1]);
00198 };
00199 
00215 inline double cross(  CPoint2 uv1,  CPoint2 uv2 )
00216 {
00217         return (uv1[0] * uv2[1] - uv1[1] * uv2[0]);
00218 };
00219 
00220 
00227 inline double operator*( CPoint2 a, CPoint2 b )
00228 {
00229     return a[0] * b[0] + a[1] * b[1];
00230 }
00231 
00239 inline double operator^(  CPoint2 uv1,  CPoint2 uv2 )
00240 {
00241         return (uv1[0] * uv2[1] - uv1[1] * uv2[0]);
00242 };
00243 
00251 inline void operator>>(const std::string & str, CPoint2& c )
00252 {
00253         std::string t = str;
00254         t.erase(0, t.find_first_not_of("()") );
00255         t.erase(t.find_last_not_of("()") + 1);
00256         std::istringstream iss( t );
00257 
00258         iss >> c[0] >> c[1];
00259 }
00260 
00261 }; //namespace
00262 
00263 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines