00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QGSRECT_H
00020 #define QGSRECT_H
00021
00022 #include <iosfwd>
00023
00024 class QString;
00025
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( QgsPoint const & p1, QgsPoint const & p2 );
00043 QgsRectangle( const QgsRectangle &other );
00045 ~QgsRectangle();
00047
00048 void set( const QgsPoint& p1, const QgsPoint& p2 );
00050
00051 void set( double xmin, double ymin, double xmax, double ymax );
00053 void setXMinimum( double x );
00055 void setXMaximum( double x );
00057 void setYMinimum( double y );
00059 void setYMaximum( double y );
00061
00062 void setMinimal();
00064 double xMaximum() const;
00066 double xMinimum() const;
00068 double yMaximum() const;
00070 double yMinimum() const;
00072 void normalize();
00074 double width() const;
00076 double height() const;
00078 QgsPoint center() const;
00080 void scale( double, const QgsPoint *c = 0 );
00082 void expand( double, const QgsPoint *c = 0 );
00084 QgsRectangle intersect( const QgsRectangle *rect ) const;
00086 bool intersects( const QgsRectangle& rect ) const;
00089 bool contains( const QgsRectangle& rect ) const;
00092 bool contains( const QgsPoint &p ) const;
00094 void combineExtentWith( QgsRectangle *rect );
00096 void combineExtentWith( double x, double y );
00098 bool isEmpty() const;
00100 QString asWktCoordinates() const;
00102 QString toString( bool automaticPrecision = false ) const;
00104 QString toString( int thePrecision ) const;
00106 QString asPolygon() const;
00110 bool operator==( const QgsRectangle &r1 ) const;
00114 bool operator!=( const QgsRectangle &r1 ) const;
00118 QgsRectangle & operator=( const QgsRectangle &r1 );
00119
00121 void unionRect( const QgsRectangle& rect );
00122
00125 bool isFinite() const;
00126
00127 protected:
00128
00129
00130
00131
00132 double xmin;
00133 double ymin;
00134 double xmax;
00135 double ymax;
00136
00137 };
00138
00139
00140 inline QgsRectangle::~QgsRectangle()
00141 {
00142 }
00143
00144 inline void QgsRectangle::setXMinimum( double x )
00145 {
00146 xmin = x;
00147 }
00148
00149 inline void QgsRectangle::setXMaximum( double x )
00150 {
00151 xmax = x;
00152 }
00153
00154 inline void QgsRectangle::setYMinimum( double y )
00155 {
00156 ymin = y;
00157 }
00158
00159 inline void QgsRectangle::setYMaximum( double y )
00160 {
00161 ymax = y;
00162 }
00163
00164 inline double QgsRectangle::xMaximum() const
00165 {
00166 return xmax;
00167 }
00168
00169 inline double QgsRectangle::xMinimum() const
00170 {
00171 return xmin;
00172 }
00173
00174 inline double QgsRectangle::yMaximum() const
00175 {
00176 return ymax;
00177 }
00178
00179 inline double QgsRectangle::yMinimum() const
00180 {
00181 return ymin;
00182 }
00183
00184 inline double QgsRectangle::width() const
00185 {
00186 return xmax - xmin;
00187 }
00188
00189 inline double QgsRectangle::height() const
00190 {
00191 return ymax - ymin;
00192 }
00193
00194 inline QgsPoint QgsRectangle::center() const
00195 {
00196 return QgsPoint( xmin + width() / 2, ymin + height() / 2 );
00197 }
00198 inline std::ostream& operator << ( std::ostream& os, const QgsRectangle &r )
00199 {
00200 return os << r.toString().toLocal8Bit().data();
00201 }
00202
00203 #endif // QGSRECT_H