QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrectangle.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrectangle.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 
18 #ifndef QGSRECT_H
19 #define QGSRECT_H
20 
21 #include <iosfwd>
22 #include <QDomDocument>
23 
24 class QString;
25 class QRectF;
26 #include "qgspoint.h"
27 
28 
35 class CORE_EXPORT QgsRectangle
36 {
37  public:
39  QgsRectangle( double xmin = 0, double ymin = 0, double xmax = 0, double ymax = 0 );
41  QgsRectangle( const QgsPoint & p1, const QgsPoint & p2 );
43  //@note added in 2.0
44  QgsRectangle( const QRectF & qRectF );
46  QgsRectangle( const QgsRectangle &other );
48  ~QgsRectangle();
50  //normalised after construction.
51  void set( const QgsPoint& p1, const QgsPoint& p2 );
53  // normalised after construction.
54  void set( double xmin, double ymin, double xmax, double ymax );
56  void setXMinimum( double x );
58  void setXMaximum( double x );
60  void setYMinimum( double y );
62  void setYMaximum( double y );
64  // and max corner is at min. It is NOT normalized.
65  void setMinimal();
67  double xMaximum() const;
69  double xMinimum() const;
71  double yMaximum() const;
73  double yMinimum() const;
75  void normalize();
77  double width() const;
79  double height() const;
81  QgsPoint center() const;
83  void scale( double scaleFactor, const QgsPoint *c = 0 );
85  QgsRectangle intersect( const QgsRectangle *rect ) const;
87  bool intersects( const QgsRectangle& rect ) const;
90  bool contains( const QgsRectangle& rect ) const;
93  bool contains( const QgsPoint &p ) const;
95  void combineExtentWith( QgsRectangle *rect );
97  void combineExtentWith( double x, double y );
99  bool isEmpty() const;
101  QString asWktCoordinates() const;
103  //@note added in 2.0
104  QString asWktPolygon() const;
106  //@note added in 2.0
107  QRectF toRectF() const;
109  QString toString( bool automaticPrecision = false ) const;
111  QString toString( int thePrecision ) const;
113  QString asPolygon() const;
117  bool operator==( const QgsRectangle &r1 ) const;
121  bool operator!=( const QgsRectangle &r1 ) const;
125  QgsRectangle & operator=( const QgsRectangle &r1 );
126 
128  void unionRect( const QgsRectangle& rect );
129 
132  bool isFinite() const;
133 
136  void invert();
137 
138  protected:
139 
140  // These are protected instead of private so that things like
141  // the QgsPostGisBox3d can get at them.
142 
143  double xmin;
144  double ymin;
145  double xmax;
146  double ymax;
147 
148 };
149 
150 
152 {
153 }
154 
155 inline void QgsRectangle::setXMinimum( double x )
156 {
157  xmin = x;
158 }
159 
160 inline void QgsRectangle::setXMaximum( double x )
161 {
162  xmax = x;
163 }
164 
165 inline void QgsRectangle::setYMinimum( double y )
166 {
167  ymin = y;
168 }
169 
170 inline void QgsRectangle::setYMaximum( double y )
171 {
172  ymax = y;
173 }
174 
175 inline double QgsRectangle::xMaximum() const
176 {
177  return xmax;
178 }
179 
180 inline double QgsRectangle::xMinimum() const
181 {
182  return xmin;
183 }
184 
185 inline double QgsRectangle::yMaximum() const
186 {
187  return ymax;
188 }
189 
190 inline double QgsRectangle::yMinimum() const
191 {
192  return ymin;
193 }
194 
195 inline double QgsRectangle::width() const
196 {
197  return xmax - xmin;
198 }
199 
200 inline double QgsRectangle::height() const
201 {
202  return ymax - ymin;
203 }
204 
206 {
207  return QgsPoint( xmin + width() / 2, ymin + height() / 2 );
208 }
209 inline std::ostream& operator << ( std::ostream& os, const QgsRectangle &r )
210 {
211  return os << r.toString().toLocal8Bit().data();
212 }
213 
214 #endif // QGSRECT_H