QGIS API Documentation  2.99.0-Master (314842d)
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 #include "qgspoint.h"
28 
29 
36 class CORE_EXPORT QgsRectangle
37 {
38  public:
40  QgsRectangle( double xmin = 0, double ymin = 0, double xmax = 0, double ymax = 0 );
42  QgsRectangle( const QgsPoint &p1, const QgsPoint &p2 );
44  QgsRectangle( const QRectF &qRectF );
46  QgsRectangle( const QgsRectangle &other );
47 
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 = nullptr );
84  void scale( double scaleFactor, double centerX, double centerY );
86  void grow( double delta );
88  void include( const QgsPoint &p );
89 
92  QgsRectangle buffer( double width );
94  QgsRectangle intersect( const QgsRectangle *rect ) const;
96  bool intersects( const QgsRectangle &rect ) const;
98  bool contains( const QgsRectangle &rect ) const;
100  bool contains( const QgsPoint &p ) const;
102  void combineExtentWith( const QgsRectangle &rect );
104  void combineExtentWith( double x, double y );
107  bool isEmpty() const;
111  bool isNull() const;
113  QString asWktCoordinates() const;
115  QString asWktPolygon() const;
117  QRectF toRectF() const;
118 
124  QString toString( int precision = 16 ) const;
126  QString asPolygon() const;
127 
131  bool operator==( const QgsRectangle &r1 ) const;
132 
136  bool operator!=( const QgsRectangle &r1 ) const;
137 
141  QgsRectangle &operator=( const QgsRectangle &r1 );
142 
144  void unionRect( const QgsRectangle &rect );
145 
149  bool isFinite() const;
150 
152  void invert();
153 
154  protected:
155 
156  // These are protected instead of private so that things like
157  // the QgsPostGisBox3d can get at them.
158 
159  double xmin;
160  double ymin;
161  double xmax;
162  double ymax;
163 
164 };
165 
167 CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsRectangle &rectangle );
169 CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsRectangle &rectangle );
170 
172 {
173 }
174 
175 inline void QgsRectangle::setXMinimum( double x )
176 {
177  xmin = x;
178 }
179 
180 inline void QgsRectangle::setXMaximum( double x )
181 {
182  xmax = x;
183 }
184 
185 inline void QgsRectangle::setYMinimum( double y )
186 {
187  ymin = y;
188 }
189 
190 inline void QgsRectangle::setYMaximum( double y )
191 {
192  ymax = y;
193 }
194 
195 inline double QgsRectangle::xMaximum() const
196 {
197  return xmax;
198 }
199 
200 inline double QgsRectangle::xMinimum() const
201 {
202  return xmin;
203 }
204 
205 inline double QgsRectangle::yMaximum() const
206 {
207  return ymax;
208 }
209 
210 inline double QgsRectangle::yMinimum() const
211 {
212  return ymin;
213 }
214 
215 inline double QgsRectangle::width() const
216 {
217  return xmax - xmin;
218 }
219 
220 inline double QgsRectangle::height() const
221 {
222  return ymax - ymin;
223 }
224 
226 {
227  return QgsPoint( xmin + width() / 2, ymin + height() / 2 );
228 }
229 inline std::ostream &operator << ( std::ostream &os, const QgsRectangle &r )
230 {
231  return os << r.toString().toLocal8Bit().data();
232 }
233 
234 #endif // QGSRECTANGLE_H
A rectangle specified with double values.
Definition: qgsrectangle.h:36
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:225
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:180
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsRectangle &rectangle)
Writes the list rectangle to stream out. QGIS version compatibility is not guaranteed.
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:215
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:185
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 yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:210
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:195
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsRectangle &rectangle)
Reads a rectangle from stream in into rectangle. QGIS version compatibility is not guaranteed...
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:190
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:200
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:205
bool isNull(const QVariant &v)
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:175
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:220