QGIS API Documentation  2.99.0-Master (bdf46d7)
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 QGSRECTANGLE_H
19 #define QGSRECTANGLE_H
20 
21 #include "qgis_core.h"
22 #include <iosfwd>
23 #include <QDomDocument>
24 
25 class QString;
26 class QRectF;
27 class QgsBox3d;
28 #include "qgspoint.h"
29 
30 
38 class CORE_EXPORT QgsRectangle
39 {
40  public:
42  QgsRectangle( double xMin = 0, double yMin = 0, double xMax = 0, double yMax = 0 );
44  QgsRectangle( const QgsPoint &p1, const QgsPoint &p2 );
46  QgsRectangle( const QRectF &qRectF );
48  QgsRectangle( const QgsRectangle &other );
49 
54  void set( const QgsPoint &p1, const QgsPoint &p2 );
55 
60  void set( double mXmin, double mYmin, double mXmax, double mYmax );
61 
65  void setXMinimum( double x ) { mXmin = x; }
66 
70  void setXMaximum( double x ) { mXmax = x; }
71 
75  void setYMinimum( double y ) { mYmin = y; }
76 
80  void setYMaximum( double y ) { mYmax = y; }
81 
86  void setMinimal();
87 
91  double xMaximum() const { return mXmax; }
92 
96  double xMinimum() const { return mXmin; }
97 
101  double yMaximum() const { return mYmax; }
102 
106  double yMinimum() const { return mYmin; }
107 
111  void normalize();
112 
118  double width() const { return mXmax - mXmin; }
119 
125  double height() const { return mYmax - mYmin; }
126 
134  double area() const { return ( mXmax - mXmin ) * ( mYmax - mYmin ); }
135 
141  double perimeter() const { return 2 * ( mXmax - mXmin ) + 2 * ( mYmax - mYmin ); }
142 
146  QgsPoint center() const { return QgsPoint( mXmin + width() / 2, mYmin + height() / 2 ); }
147 
151  void scale( double scaleFactor, const QgsPoint *c = nullptr );
152 
156  void scale( double scaleFactor, double centerX, double centerY );
157 
161  void grow( double delta );
162 
166  void include( const QgsPoint &p );
167 
172  QgsRectangle buffer( double width );
173 
177  QgsRectangle intersect( const QgsRectangle *rect ) const;
178 
182  bool intersects( const QgsRectangle &rect ) const;
183 
187  bool contains( const QgsRectangle &rect ) const;
188 
192  bool contains( const QgsPoint &p ) const;
193 
197  void combineExtentWith( const QgsRectangle &rect );
198 
202  void combineExtentWith( double x, double y );
203 
208  bool isEmpty() const;
209 
215  bool isNull() const;
216 
220  QString asWktCoordinates() const;
221 
225  QString asWktPolygon() const;
226 
230  QRectF toRectF() const;
231 
237  QString toString( int precision = 16 ) const;
238 
242  QString asPolygon() const;
243 
248  bool operator==( const QgsRectangle &r1 ) const;
249 
254  bool operator!=( const QgsRectangle &r1 ) const;
255 
260  QgsRectangle &operator=( const QgsRectangle &r1 );
261 
265  void unionRect( const QgsRectangle &rect );
266 
271  bool isFinite() const;
272 
276  void invert();
277 
283  QgsBox3d toBox3d( double zMin, double zMax ) const;
284 
285  private:
286 
287  double mXmin;
288  double mYmin;
289  double mXmax;
290  double mYmax;
291 
292 };
293 
294 #ifndef SIP_RUN
295 
299 CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsRectangle &rectangle );
300 
304 CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsRectangle &rectangle );
305 
306 inline std::ostream &operator << ( std::ostream &os, const QgsRectangle &r )
307 {
308  return os << r.toString().toLocal8Bit().data();
309 }
310 
311 #endif
312 
313 #endif // QGSRECTANGLE_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
QgsPoint center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:146
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:70
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
double perimeter() const
Returns the perimeter of the rectangle.
Definition: qgsrectangle.h:141
A 3-dimensional box composed of x, y, z coordinates.
Definition: qgsbox3d.h:34
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsRectangle &rectangle)
Writes the list rectangle to stream out.
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:118
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:75
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
A class to represent a point.
Definition: qgspoint.h:37
double area() const
Returns the area of the rectangle.
Definition: qgsrectangle.h:134
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:106
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:91
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsRectangle &rectangle)
Reads a rectangle from stream in into rectangle.
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:80
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:96
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:101
bool isNull(const QVariant &v)
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:65
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:125