Quantum GIS API Documentation  1.8
src/core/qgspoint.h
Go to the documentation of this file.
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 
00018 #ifndef QGSPOINT_H
00019 #define QGSPOINT_H
00020 
00021 #include <qgis.h>
00022 
00023 #include <iostream>
00024 #include <QString>
00025 #include <QPoint>
00026 
00032 class CORE_EXPORT QgsVector
00033 {
00034     double m_x, m_y;
00035 
00036   public:
00037     QgsVector();
00038     QgsVector( double x, double y );
00039 
00040     QgsVector operator-( void ) const;
00041     QgsVector operator*( double scalar ) const;
00042     QgsVector operator/( double scalar ) const;
00043     double operator*( QgsVector v ) const;
00044     double length() const;
00045 
00046     double x() const;
00047     double y() const;
00048 
00049     // perpendicular vector (rotated 90 counter-clockwise)
00050     QgsVector perpVector() const;
00051 
00052     double angle( void ) const;
00053     double angle( QgsVector v ) const;
00054     QgsVector rotateBy( double rot ) const;
00055     QgsVector normal() const;
00056 
00057 };
00058 
00063 class CORE_EXPORT QgsPoint
00064 {
00065   public:
00067     QgsPoint() : m_x( 0.0 ), m_y( 0.0 )
00068     {}
00069 
00071     QgsPoint( const QgsPoint& p );
00072 
00077     QgsPoint( double x, double y )
00078         : m_x( x ), m_y( y )
00079     {}
00080 
00081     ~QgsPoint()
00082     {}
00083 
00087     void setX( double x )
00088     {
00089       m_x = x;
00090     }
00091 
00095     void setY( double y )
00096     {
00097       m_y = y;
00098     }
00099 
00101     void set( double x, double y )
00102     {
00103       m_x = x;
00104       m_y = y;
00105     }
00106 
00110     double x() const
00111     {
00112       return m_x;
00113     }
00114 
00118     double y() const
00119     {
00120       return m_y;
00121     }
00122 
00124     QString toString() const;
00125 
00127     QString toString( int thePrecision ) const;
00128 
00134     QString toDegreesMinutesSeconds( int thePrecision ) const;
00135 
00136 
00141     QString wellKnownText() const;
00142 
00144     double sqrDist( double x, double y ) const;
00145 
00147     double sqrDist( const QgsPoint& other ) const;
00148 
00151     double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
00152 
00155     double azimuth( const QgsPoint& other );
00156 
00158     bool operator==( const QgsPoint &other );
00159 
00161     bool operator!=( const QgsPoint &other ) const;
00162 
00164     QgsPoint & operator=( const QgsPoint &other );
00165 
00167     void multiply( const double& scalar );
00168 
00173     int onSegment( const QgsPoint& a, const QgsPoint& b ) const;
00174 
00175     QgsVector operator-( QgsPoint p ) const { return QgsVector( m_x - p.m_x, m_y - p.m_y ); }
00176     QgsPoint &operator+=( const QgsVector &v ) { *this = *this + v; return *this; }
00177     QgsPoint &operator-=( const QgsVector &v ) { *this = *this - v; return *this; }
00178     QgsPoint operator+( const QgsVector &v ) const { return QgsPoint( m_x + v.x(), m_y + v.y() ); }
00179     QgsPoint operator-( const QgsVector &v ) const { return QgsPoint( m_x - v.x(), m_y - v.y() ); }
00180 
00181   private:
00182 
00184     double m_x;
00185 
00187     double m_y;
00188 
00189 
00190 }; // class QgsPoint
00191 
00192 
00193 inline bool operator==( const QgsPoint &p1, const QgsPoint &p2 )
00194 {
00195   if (( p1.x() == p2.x() ) && ( p1.y() == p2.y() ) )
00196     { return true; }
00197   else
00198     { return false; }
00199 }
00200 
00201 inline std::ostream& operator << ( std::ostream& os, const QgsPoint &p )
00202 {
00203   // Use Local8Bit for printouts
00204   os << p.toString().toLocal8Bit().data();
00205   return os;
00206 }
00207 
00208 #endif //QGSPOINT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines