QGIS API Documentation  2.99.0-Master (c42dad3)
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 <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  QgsRectangle( const QRectF & qRectF );
45  QgsRectangle( const QgsRectangle &other );
47  ~QgsRectangle();
50  void set( const QgsPoint& p1, const QgsPoint& p2 );
53  void set( double xmin, double ymin, double xmax, double ymax );
55  void setXMinimum( double x );
57  void setXMaximum( double x );
59  void setYMinimum( double y );
61  void setYMaximum( double y );
64  void setMinimal();
66  double xMaximum() const;
68  double xMinimum() const;
70  double yMaximum() const;
72  double yMinimum() const;
74  void normalize();
76  double width() const;
78  double height() const;
80  QgsPoint center() const;
82  void scale( double scaleFactor, const QgsPoint *c = nullptr );
83  void scale( double scaleFactor, double centerX, double centerY );
85  void grow( double delta );
87  void include( const QgsPoint& p );
88 
91  QgsRectangle buffer( double width );
93  QgsRectangle intersect( const QgsRectangle *rect ) const;
95  bool intersects( const QgsRectangle& rect ) const;
97  bool contains( const QgsRectangle& rect ) const;
99  bool contains( const QgsPoint &p ) const;
101  void combineExtentWith( const QgsRectangle& rect );
103  void combineExtentWith( double x, double y );
106  bool isEmpty() const;
110  bool isNull() const;
112  QString asWktCoordinates() const;
114  QString asWktPolygon() const;
116  QRectF toRectF() const;
118  QString toString( bool automaticPrecision = false ) const;
120  QString toString( int thePrecision ) const;
122  QString asPolygon() const;
123 
127  bool operator==( const QgsRectangle &r1 ) const;
128 
132  bool operator!=( const QgsRectangle &r1 ) const;
133 
137  QgsRectangle & operator=( const QgsRectangle &r1 );
138 
140  void unionRect( const QgsRectangle& rect );
141 
145  bool isFinite() const;
146 
148  void invert();
149 
150  protected:
151 
152  // These are protected instead of private so that things like
153  // the QgsPostGisBox3d can get at them.
154 
155  double xmin;
156  double ymin;
157  double xmax;
158  double ymax;
159 
160 };
161 
163 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsRectangle& rectangle );
165 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsRectangle& rectangle );
166 
168 {
169 }
170 
171 inline void QgsRectangle::setXMinimum( double x )
172 {
173  xmin = x;
174 }
175 
176 inline void QgsRectangle::setXMaximum( double x )
177 {
178  xmax = x;
179 }
180 
181 inline void QgsRectangle::setYMinimum( double y )
182 {
183  ymin = y;
184 }
185 
186 inline void QgsRectangle::setYMaximum( double y )
187 {
188  ymax = y;
189 }
190 
191 inline double QgsRectangle::xMaximum() const
192 {
193  return xmax;
194 }
195 
196 inline double QgsRectangle::xMinimum() const
197 {
198  return xmin;
199 }
200 
201 inline double QgsRectangle::yMaximum() const
202 {
203  return ymax;
204 }
205 
206 inline double QgsRectangle::yMinimum() const
207 {
208  return ymin;
209 }
210 
211 inline double QgsRectangle::width() const
212 {
213  return xmax - xmin;
214 }
215 
216 inline double QgsRectangle::height() const
217 {
218  return ymax - ymin;
219 }
220 
222 {
223  return QgsPoint( xmin + width() / 2, ymin + height() / 2 );
224 }
225 inline std::ostream& operator << ( std::ostream& os, const QgsRectangle &r )
226 {
227  return os << r.toString().toLocal8Bit().data();
228 }
229 
230 #endif // QGSRECTANGLE_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:221
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:176
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
~QgsRectangle()
Destructor.
Definition: qgsrectangle.h:167
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsRectangle &rectangle)
Writes the list rectangle to stream out. QGIS version compatibility is not guaranteed.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:211
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:181
A class to represent a point.
Definition: qgspoint.h:111
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:206
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:191
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:186
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:196
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:201
bool isNull(const QVariant &v)
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:171
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:216