00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef QGSPOINT_H
00019 #define QGSPOINT_H
00020
00021 #include <iostream>
00022 #include <QString>
00023 #include <QPoint>
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() : m_x( 0.0 ), m_y( 0.0 )
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
00153 double azimuth( const QgsPoint& other );
00154
00156 bool operator==( const QgsPoint &other );
00157
00159 bool operator!=( const QgsPoint &other ) const;
00160
00162 QgsPoint & operator=( const QgsPoint &other );
00163
00165 void multiply( const double& scalar );
00166
00171 int onSegment( const QgsPoint& a, const QgsPoint& b ) const;
00172
00173 QgsVector operator-( QgsPoint p ) const { return QgsVector( m_x - p.m_x, m_y - p.m_y ); }
00174 QgsPoint &operator+=( const QgsVector &v ) { *this = *this + v; return *this; }
00175 QgsPoint &operator-=( const QgsVector &v ) { *this = *this - v; return *this; }
00176 QgsPoint operator+( const QgsVector &v ) const { return QgsPoint( m_x + v.x(), m_y + v.y() ); }
00177 QgsPoint operator-( const QgsVector &v ) const { return QgsPoint( m_x - v.x(), m_y - v.y() ); }
00178
00179 private:
00180
00182 double m_x;
00183
00185 double m_y;
00186
00187
00188 };
00189
00190
00191 inline bool operator==( const QgsPoint &p1, const QgsPoint &p2 )
00192 {
00193 if (( p1.x() == p2.x() ) && ( p1.y() == p2.y() ) )
00194 { return true; }
00195 else
00196 { return false; }
00197 }
00198
00199 inline std::ostream& operator << ( std::ostream& os, const QgsPoint &p )
00200 {
00201
00202 os << p.toString().toLocal8Bit().data();
00203 return os;
00204 }
00205
00206 #endif //QGSPOINT_H