QGIS API Documentation  2.99.0-Master (7d4f81d)
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 "qgspointxy.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 QgsPointXY &p1, const QgsPointXY &p2 );
46  QgsRectangle( const QRectF &qRectF );
48  QgsRectangle( const QgsRectangle &other );
49 
54  void set( const QgsPointXY &p1, const QgsPointXY &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  QgsPointXY center() const { return QgsPointXY( mXmin + width() / 2, mYmin + height() / 2 ); }
147 
151  void scale( double scaleFactor, const QgsPointXY *c = nullptr );
152 
156  void scale( double scaleFactor, double centerX, double centerY );
157 
161  void grow( double delta );
162 
166  void include( const QgsPointXY &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 QgsPointXY &p ) const;
193 
197  void combineExtentWith( const QgsRectangle &rect );
198 
202  void combineExtentWith( double x, double y );
203 
208  QgsRectangle operator-( const QgsVector v ) const;
209 
214  QgsRectangle operator+( const QgsVector v ) const;
215 
220  QgsRectangle &operator-=( const QgsVector v );
221 
226  QgsRectangle &operator+=( const QgsVector v );
227 
232  bool isEmpty() const;
233 
239  bool isNull() const;
240 
244  QString asWktCoordinates() const;
245 
249  QString asWktPolygon() const;
250 
254  QRectF toRectF() const;
255 
261  QString toString( int precision = 16 ) const;
262 
266  QString asPolygon() const;
267 
272  bool operator==( const QgsRectangle &r1 ) const;
273 
278  bool operator!=( const QgsRectangle &r1 ) const;
279 
284  QgsRectangle &operator=( const QgsRectangle &r1 );
285 
290  bool isFinite() const;
291 
295  void invert();
296 
302  QgsBox3d toBox3d( double zMin, double zMax ) const;
303 
304  private:
305 
306  double mXmin;
307  double mYmin;
308  double mXmax;
309  double mYmax;
310 
311 };
312 
313 #ifndef SIP_RUN
314 
318 CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsRectangle &rectangle );
319 
323 CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsRectangle &rectangle );
324 
325 inline std::ostream &operator << ( std::ostream &os, const QgsRectangle &r )
326 {
327  return os << r.toString().toLocal8Bit().data();
328 }
329 
330 #endif
331 
332 #endif // QGSRECTANGLE_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
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)
A class to represent a 2D point.
Definition: qgspointxy.h:42
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...
QDateTime operator+(const QDateTime &start, QgsInterval interval)
A class to represent a vector.
Definition: qgsvector.h:26
QgsInterval operator-(const QDateTime &dt1, const QDateTime &dt2)
Returns the interval between two datetimes.
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
QgsPointXY center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:146
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