|
QGIS API Documentation
master-59fd5e0
|
00001 /*************************************************************************** 00002 qgsrectangle.h - description 00003 ------------------- 00004 begin : Sat Jun 22 2002 00005 copyright : (C) 2002 by Gary E.Sherman 00006 email : sherman at mrcc.com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef QGSRECT_H 00019 #define QGSRECT_H 00020 00021 #include <iosfwd> 00022 #include <QDomDocument> 00023 00024 class QString; 00025 class QRectF; 00026 #include "qgspoint.h" 00027 00028 00035 class CORE_EXPORT QgsRectangle 00036 { 00037 public: 00039 QgsRectangle( double xmin = 0, double ymin = 0, double xmax = 0, double ymax = 0 ); 00041 QgsRectangle( const QgsPoint & p1, const QgsPoint & p2 ); 00043 //@note added in 2.0 00044 QgsRectangle( const QRectF & qRectF ); 00046 QgsRectangle( const QgsRectangle &other ); 00048 ~QgsRectangle(); 00050 //normalised after construction. 00051 void set( const QgsPoint& p1, const QgsPoint& p2 ); 00053 // normalised after construction. 00054 void set( double xmin, double ymin, double xmax, double ymax ); 00056 void setXMinimum( double x ); 00058 void setXMaximum( double x ); 00060 void setYMinimum( double y ); 00062 void setYMaximum( double y ); 00064 // and max corner is at min. It is NOT normalized. 00065 void setMinimal(); 00067 double xMaximum() const; 00069 double xMinimum() const; 00071 double yMaximum() const; 00073 double yMinimum() const; 00075 void normalize(); 00077 double width() const; 00079 double height() const; 00081 QgsPoint center() const; 00083 void scale( double scaleFactor, const QgsPoint *c = 0 ); 00085 QgsRectangle intersect( const QgsRectangle *rect ) const; 00087 bool intersects( const QgsRectangle& rect ) const; 00090 bool contains( const QgsRectangle& rect ) const; 00093 bool contains( const QgsPoint &p ) const; 00095 void combineExtentWith( QgsRectangle *rect ); 00097 void combineExtentWith( double x, double y ); 00099 bool isEmpty() const; 00101 QString asWktCoordinates() const; 00103 //@note added in 2.0 00104 QString asWktPolygon() const; 00106 //@note added in 2.0 00107 QRectF toRectF() const; 00109 QString toString( bool automaticPrecision = false ) const; 00111 QString toString( int thePrecision ) const; 00113 QString asPolygon() const; 00117 bool operator==( const QgsRectangle &r1 ) const; 00121 bool operator!=( const QgsRectangle &r1 ) const; 00125 QgsRectangle & operator=( const QgsRectangle &r1 ); 00126 00128 void unionRect( const QgsRectangle& rect ); 00129 00132 bool isFinite() const; 00133 00136 void invert(); 00137 00138 protected: 00139 00140 // These are protected instead of private so that things like 00141 // the QgsPostGisBox3d can get at them. 00142 00143 double xmin; 00144 double ymin; 00145 double xmax; 00146 double ymax; 00147 00148 }; 00149 00150 00151 inline QgsRectangle::~QgsRectangle() 00152 { 00153 } 00154 00155 inline void QgsRectangle::setXMinimum( double x ) 00156 { 00157 xmin = x; 00158 } 00159 00160 inline void QgsRectangle::setXMaximum( double x ) 00161 { 00162 xmax = x; 00163 } 00164 00165 inline void QgsRectangle::setYMinimum( double y ) 00166 { 00167 ymin = y; 00168 } 00169 00170 inline void QgsRectangle::setYMaximum( double y ) 00171 { 00172 ymax = y; 00173 } 00174 00175 inline double QgsRectangle::xMaximum() const 00176 { 00177 return xmax; 00178 } 00179 00180 inline double QgsRectangle::xMinimum() const 00181 { 00182 return xmin; 00183 } 00184 00185 inline double QgsRectangle::yMaximum() const 00186 { 00187 return ymax; 00188 } 00189 00190 inline double QgsRectangle::yMinimum() const 00191 { 00192 return ymin; 00193 } 00194 00195 inline double QgsRectangle::width() const 00196 { 00197 return xmax - xmin; 00198 } 00199 00200 inline double QgsRectangle::height() const 00201 { 00202 return ymax - ymin; 00203 } 00204 00205 inline QgsPoint QgsRectangle::center() const 00206 { 00207 return QgsPoint( xmin + width() / 2, ymin + height() / 2 ); 00208 } 00209 inline std::ostream& operator << ( std::ostream& os, const QgsRectangle &r ) 00210 { 00211 return os << r.toString().toLocal8Bit().data(); 00212 } 00213 00214 #endif // QGSRECT_H