QGIS API Documentation  2.2.0-Valmiera
 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 );
44  QgsRectangle( const QRectF & qRectF );
46  QgsRectangle( const QgsRectangle &other );
48  ~QgsRectangle();
51  void set( const QgsPoint& p1, const QgsPoint& p2 );
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 );
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 );
84  void scale( double scaleFactor, double centerX, double centerY );
87  QgsRectangle buffer( double width );
89  QgsRectangle intersect( const QgsRectangle *rect ) const;
91  bool intersects( const QgsRectangle& rect ) const;
94  bool contains( const QgsRectangle& rect ) const;
97  bool contains( const QgsPoint &p ) const;
99  void combineExtentWith( QgsRectangle *rect );
101  void combineExtentWith( double x, double y );
103  bool isEmpty() const;
105  QString asWktCoordinates() const;
108  QString asWktPolygon() const;
111  QRectF toRectF() const;
113  QString toString( bool automaticPrecision = false ) const;
115  QString toString( int thePrecision ) const;
117  QString asPolygon() const;
121  bool operator==( const QgsRectangle &r1 ) const;
125  bool operator!=( const QgsRectangle &r1 ) const;
129  QgsRectangle & operator=( const QgsRectangle &r1 );
130 
132  void unionRect( const QgsRectangle& rect );
133 
136  bool isFinite() const;
137 
140  void invert();
141 
142  protected:
143 
144  // These are protected instead of private so that things like
145  // the QgsPostGisBox3d can get at them.
146 
147  double xmin;
148  double ymin;
149  double xmax;
150  double ymax;
151 
152 };
153 
154 
156 {
157 }
158 
159 inline void QgsRectangle::setXMinimum( double x )
160 {
161  xmin = x;
162 }
163 
164 inline void QgsRectangle::setXMaximum( double x )
165 {
166  xmax = x;
167 }
168 
169 inline void QgsRectangle::setYMinimum( double y )
170 {
171  ymin = y;
172 }
173 
174 inline void QgsRectangle::setYMaximum( double y )
175 {
176  ymax = y;
177 }
178 
179 inline double QgsRectangle::xMaximum() const
180 {
181  return xmax;
182 }
183 
184 inline double QgsRectangle::xMinimum() const
185 {
186  return xmin;
187 }
188 
189 inline double QgsRectangle::yMaximum() const
190 {
191  return ymax;
192 }
193 
194 inline double QgsRectangle::yMinimum() const
195 {
196  return ymin;
197 }
198 
199 inline double QgsRectangle::width() const
200 {
201  return xmax - xmin;
202 }
203 
204 inline double QgsRectangle::height() const
205 {
206  return ymax - ymin;
207 }
208 
210 {
211  return QgsPoint( xmin + width() / 2, ymin + height() / 2 );
212 }
213 inline std::ostream& operator << ( std::ostream& os, const QgsRectangle &r )
214 {
215  return os << r.toString().toLocal8Bit().data();
216 }
217 
218 #endif // QGSRECT_H