Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgspoint.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspoint.h - description
3  -------------------
4  begin : Sat Jun 22 2002
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 /* $Id$ */
18 
19 #ifndef QGSPOINT_H
20 #define QGSPOINT_H
21 
22 #include <iostream>
23 #include <QString>
24 #include <QPoint>
25 
31 class CORE_EXPORT QgsVector
32 {
33  double m_x, m_y;
34 
35  public:
36  QgsVector();
37  QgsVector( double x, double y );
38 
39  QgsVector operator-( void ) const;
40  QgsVector operator*( double scalar ) const;
41  QgsVector operator/( double scalar ) const;
42  double operator*( QgsVector v ) const;
43  double length() const;
44 
45  double x() const;
46  double y() const;
47 
48  // perpendicular vector (rotated 90° counter-clockwise)
49  QgsVector perpVector() const;
50 
51  double angle( void ) const;
52  double angle( QgsVector v ) const;
53  QgsVector rotateBy( double rot ) const;
54  QgsVector normal() const;
55 
56 };
57 
62 class CORE_EXPORT QgsPoint
63 {
64  public:
67  {}
68 
70  QgsPoint( const QgsPoint& p );
71 
76  QgsPoint( double x, double y )
77  : m_x( x ), m_y( y )
78  {}
79 
81  {}
82 
86  void setX( double x )
87  {
88  m_x = x;
89  }
90 
94  void setY( double y )
95  {
96  m_y = y;
97  }
98 
100  void set( double x, double y )
101  {
102  m_x = x;
103  m_y = y;
104  }
105 
109  double x() const
110  {
111  return m_x;
112  }
113 
117  double y() const
118  {
119  return m_y;
120  }
121 
123  QString toString() const;
124 
126  QString toString( int thePrecision ) const;
127 
133  QString toDegreesMinutesSeconds( int thePrecision ) const;
134 
135 
140  QString wellKnownText() const;
141 
143  double sqrDist( double x, double y ) const;
144 
146  double sqrDist( const QgsPoint& other ) const;
147 
150  double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint ) const;
151 
154  double azimuth( const QgsPoint& other );
155 
157  bool operator==( const QgsPoint &other );
158 
160  bool operator!=( const QgsPoint &other ) const;
161 
163  QgsPoint & operator=( const QgsPoint &other );
164 
166  void multiply( const double& scalar );
167 
172  int onSegment( const QgsPoint& a, const QgsPoint& b ) const;
173 
174  QgsVector operator-( QgsPoint p ) const { return QgsVector( m_x - p.m_x, m_y - p.m_y ); }
175  QgsPoint &operator+=( const QgsVector &v ) { *this = *this + v; return *this; }
176  QgsPoint &operator-=( const QgsVector &v ) { *this = *this - v; return *this; }
177  QgsPoint operator+( const QgsVector &v ) const { return QgsPoint( m_x + v.x(), m_y + v.y() ); }
178  QgsPoint operator-( const QgsVector &v ) const { return QgsPoint( m_x - v.x(), m_y - v.y() ); }
179 
180  private:
181 
183  double m_x;
184 
186  double m_y;
187 
188 
189 }; // class QgsPoint
190 
191 
192 inline bool operator==( const QgsPoint &p1, const QgsPoint &p2 )
193 {
194  if (( p1.x() == p2.x() ) && ( p1.y() == p2.y() ) )
195  { return true; }
196  else
197  { return false; }
198 }
199 
200 inline std::ostream& operator << ( std::ostream& os, const QgsPoint &p )
201 {
202  // Use Local8Bit for printouts
203  os << p.toString().toLocal8Bit().data();
204  return os;
205 }
206 
207 #endif //QGSPOINT_H