Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgspoint.h - description 00003 ------------------- 00004 begin : Sat Jun 22 2002 00005 copyright : (C) 2002 by Gary E.Sherman 00006 email : sherman at mrcc.com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 /* $Id$ */ 00018 00019 #ifndef QGSPOINT_H 00020 #define QGSPOINT_H 00021 00022 #include <iostream> 00023 #include <QString> 00024 #include <QPoint> 00025 00031 class CORE_EXPORT QgsVector 00032 { 00033 double m_x, m_y; 00034 00035 public: 00036 QgsVector(); 00037 QgsVector( double x, double y ); 00038 00039 QgsVector operator-( void ) const; 00040 QgsVector operator*( double scalar ) const; 00041 QgsVector operator/( double scalar ) const; 00042 double operator*( QgsVector v ) const; 00043 double length() const; 00044 00045 double x() const; 00046 double y() const; 00047 00048 // perpendicular vector (rotated 90� counter-clockwise) 00049 QgsVector perpVector() const; 00050 00051 double angle( void ) const; 00052 double angle( QgsVector v ) const; 00053 QgsVector rotateBy( double rot ) const; 00054 QgsVector normal() const; 00055 00056 }; 00057 00062 class CORE_EXPORT QgsPoint 00063 { 00064 public: 00066 QgsPoint() 00067 {} 00068 00070 QgsPoint( const QgsPoint& p ); 00071 00076 QgsPoint( double x, double y ) 00077 : m_x( x ), m_y( y ) 00078 {} 00079 00080 ~QgsPoint() 00081 {} 00082 00086 void setX( double x ) 00087 { 00088 m_x = x; 00089 } 00090 00094 void setY( double y ) 00095 { 00096 m_y = y; 00097 } 00098 00100 void set( double x, double y ) 00101 { 00102 m_x = x; 00103 m_y = y; 00104 } 00105 00109 double x() const 00110 { 00111 return m_x; 00112 } 00113 00117 double y() const 00118 { 00119 return m_y; 00120 } 00121 00123 QString toString() const; 00124 00126 QString toString( int thePrecision ) const; 00127 00133 QString toDegreesMinutesSeconds( int thePrecision ) const; 00134 00135 00140 QString wellKnownText() const; 00141 00143 double sqrDist( double x, double y ) const; 00144 00146 double sqrDist( const QgsPoint& other ) const; 00147 00150 double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint ) const; 00151 00154 double azimuth( const QgsPoint& other ); 00155 00157 bool operator==( const QgsPoint &other ); 00158 00160 bool operator!=( const QgsPoint &other ) const; 00161 00163 QgsPoint & operator=( const QgsPoint &other ); 00164 00166 void multiply( const double& scalar ); 00167 00172 int onSegment( const QgsPoint& a, const QgsPoint& b ) const; 00173 00174 QgsVector operator-( QgsPoint p ) const { return QgsVector( m_x - p.m_x, m_y - p.m_y ); } 00175 QgsPoint &operator+=( const QgsVector &v ) { *this = *this + v; return *this; } 00176 QgsPoint &operator-=( const QgsVector &v ) { *this = *this - v; return *this; } 00177 QgsPoint operator+( const QgsVector &v ) const { return QgsPoint( m_x + v.x(), m_y + v.y() ); } 00178 QgsPoint operator-( const QgsVector &v ) const { return QgsPoint( m_x - v.x(), m_y - v.y() ); } 00179 00180 private: 00181 00183 double m_x; 00184 00186 double m_y; 00187 00188 00189 }; // class QgsPoint 00190 00191 00192 inline bool operator==( const QgsPoint &p1, const QgsPoint &p2 ) 00193 { 00194 if (( p1.x() == p2.x() ) && ( p1.y() == p2.y() ) ) 00195 { return true; } 00196 else 00197 { return false; } 00198 } 00199 00200 inline std::ostream& operator << ( std::ostream& os, const QgsPoint &p ) 00201 { 00202 // Use Local8Bit for printouts 00203 os << p.toString().toLocal8Bit().data(); 00204 return os; 00205 } 00206 00207 #endif //QGSPOINT_H