00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QGSPOINT_H
00020 #define QGSPOINT_H
00021
00022 #include <iostream>
00023 #include <QString>
00024
00030 class CORE_EXPORT QgsVector
00031 {
00032 double m_x, m_y;
00033
00034 public:
00035 QgsVector();
00036 QgsVector( double x, double y );
00037
00038 QgsVector operator-( void ) const;
00039 QgsVector operator*( double scalar ) const;
00040 QgsVector operator/( double scalar ) const;
00041 double operator*( QgsVector v ) const;
00042 double length() const;
00043
00044 double x() const;
00045 double y() const;
00046
00047
00048 QgsVector perpVector() const;
00049
00050 double angle( void ) const;
00051 double angle( QgsVector v ) const;
00052 QgsVector rotateBy( double rot ) const;
00053 QgsVector normal() const;
00054
00055 };
00056
00061 class CORE_EXPORT QgsPoint
00062 {
00063 public:
00065 QgsPoint()
00066 {}
00067
00069 QgsPoint( const QgsPoint& p );
00070
00075 QgsPoint( double x, double y )
00076 : m_x( x ), m_y( y )
00077 {}
00078
00079 ~QgsPoint()
00080 {}
00081
00085 void setX( double x )
00086 {
00087 m_x = x;
00088 }
00089
00093 void setY( double y )
00094 {
00095 m_y = y;
00096 }
00097
00099 void set( double x, double y )
00100 {
00101 m_x = x;
00102 m_y = y;
00103 }
00104
00108 double x() const
00109 {
00110 return m_x;
00111 }
00112
00116 double y() const
00117 {
00118 return m_y;
00119 }
00120
00122 QString toString() const;
00123
00125 QString toString( int thePrecision ) const;
00126
00132 QString toDegreesMinutesSeconds( int thePrecision ) const;
00133
00134
00139 QString wellKnownText() const;
00140
00142 double sqrDist( double x, double y ) const;
00143
00145 double sqrDist( const QgsPoint& other ) const;
00146
00149 double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint ) const;
00150
00152 bool operator==( const QgsPoint &other );
00153
00155 bool operator!=( const QgsPoint &other ) const;
00156
00158 QgsPoint & operator=( const QgsPoint &other );
00159
00161 void multiply( const double& scalar );
00162
00167 int onSegment( const QgsPoint& a, const QgsPoint& b ) const;
00168
00169 QgsVector operator-( QgsPoint p ) const { return QgsVector( m_x - p.m_x, m_y - p.m_y ); }
00170 QgsPoint &operator+=( const QgsVector &v ) { *this = *this + v; return *this; }
00171 QgsPoint &operator-=( const QgsVector &v ) { *this = *this - v; return *this; }
00172 QgsPoint operator+( const QgsVector &v ) const { return QgsPoint( m_x + v.x(), m_y + v.y() ); }
00173 QgsPoint operator-( const QgsVector &v ) const { return QgsPoint( m_x - v.x(), m_y - v.y() ); }
00174
00175 private:
00176
00178 double m_x;
00179
00181 double m_y;
00182
00183
00184 };
00185
00186
00187 inline bool operator==( const QgsPoint &p1, const QgsPoint &p2 )
00188 {
00189 if (( p1.x() == p2.x() ) && ( p1.y() == p2.y() ) )
00190 { return true; }
00191 else
00192 { return false; }
00193 }
00194
00195 inline std::ostream& operator << ( std::ostream& os, const QgsPoint &p )
00196 {
00197
00198 os << p.toString().toLocal8Bit().data();
00199 return os;
00200 }
00201
00202 #endif //QGSPOINT_H