QGIS API Documentation  2.4.0-Chugiak
 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 );
104  bool isEmpty() const;
108  bool isNull() const;
110  QString asWktCoordinates() const;
113  QString asWktPolygon() const;
116  QRectF toRectF() const;
118  QString toString( bool automaticPrecision = false ) const;
120  QString toString( int thePrecision ) const;
122  QString asPolygon() const;
126  bool operator==( const QgsRectangle &r1 ) const;
130  bool operator!=( const QgsRectangle &r1 ) const;
134  QgsRectangle & operator=( const QgsRectangle &r1 );
135 
137  void unionRect( const QgsRectangle& rect );
138 
141  bool isFinite() const;
142 
145  void invert();
146 
147  protected:
148 
149  // These are protected instead of private so that things like
150  // the QgsPostGisBox3d can get at them.
151 
152  double xmin;
153  double ymin;
154  double xmax;
155  double ymax;
156 
157 };
158 
159 
161 {
162 }
163 
164 inline void QgsRectangle::setXMinimum( double x )
165 {
166  xmin = x;
167 }
168 
169 inline void QgsRectangle::setXMaximum( double x )
170 {
171  xmax = x;
172 }
173 
174 inline void QgsRectangle::setYMinimum( double y )
175 {
176  ymin = y;
177 }
178 
179 inline void QgsRectangle::setYMaximum( double y )
180 {
181  ymax = y;
182 }
183 
184 inline double QgsRectangle::xMaximum() const
185 {
186  return xmax;
187 }
188 
189 inline double QgsRectangle::xMinimum() const
190 {
191  return xmin;
192 }
193 
194 inline double QgsRectangle::yMaximum() const
195 {
196  return ymax;
197 }
198 
199 inline double QgsRectangle::yMinimum() const
200 {
201  return ymin;
202 }
203 
204 inline double QgsRectangle::width() const
205 {
206  return xmax - xmin;
207 }
208 
209 inline double QgsRectangle::height() const
210 {
211  return ymax - ymin;
212 }
213 
215 {
216  return QgsPoint( xmin + width() / 2, ymin + height() / 2 );
217 }
218 inline std::ostream& operator << ( std::ostream& os, const QgsRectangle &r )
219 {
220  return os << r.toString().toLocal8Bit().data();
221 }
222 
223 #endif // QGSRECT_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:169
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:194
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
~QgsRectangle()
Destructor.
Definition: qgsrectangle.h:160
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:199
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:184
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:174
A class to represent a point geometry.
Definition: qgspoint.h:63
std::ostream & operator<<(std::ostream &os, const QgsRectangle &r)
Definition: qgsrectangle.h:218
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:179
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:204
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:189
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:214
bool isNull(const QVariant &v)
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:164
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:209