Quantum GIS API Documentation  1.8
src/core/qgsrectangle.h
Go to the documentation of this file.
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 
00023 class QString;
00024 
00025 #include "qgspoint.h"
00026 
00027 
00034 class CORE_EXPORT QgsRectangle
00035 {
00036   public:
00038     QgsRectangle( double xmin = 0, double ymin = 0, double xmax = 0, double ymax = 0 );
00040     QgsRectangle( QgsPoint const & p1, QgsPoint const & p2 );
00042     QgsRectangle( const QgsRectangle &other );
00044     ~QgsRectangle();
00046     //normalised after construction.
00047     void set( const QgsPoint& p1, const QgsPoint& p2 );
00049     //  normalised after construction.
00050     void set( double xmin, double ymin, double xmax, double ymax );
00052     void setXMinimum( double x );
00054     void setXMaximum( double x );
00056     void setYMinimum( double y );
00058     void setYMaximum( double y );
00060     // and max corner is at min. It is NOT normalized.
00061     void setMinimal();
00063     double xMaximum() const;
00065     double xMinimum() const;
00067     double yMaximum() const;
00069     double yMinimum() const;
00071     void normalize();
00073     double width() const;
00075     double height() const;
00077     QgsPoint center() const;
00079     void scale( double, const QgsPoint *c = 0 );
00081     void expand( double, const QgsPoint *c = 0 );
00083     QgsRectangle intersect( const QgsRectangle *rect ) const;
00085     bool intersects( const QgsRectangle& rect ) const;
00088     bool contains( const QgsRectangle& rect ) const;
00091     bool contains( const QgsPoint &p ) const;
00093     void combineExtentWith( QgsRectangle *rect );
00095     void combineExtentWith( double x, double y );
00097     bool isEmpty() const;
00099     QString asWktCoordinates() const;
00101     QString toString( bool automaticPrecision = false ) const;
00103     QString toString( int thePrecision ) const;
00105     QString asPolygon() const;
00109     bool operator==( const QgsRectangle &r1 ) const;
00113     bool operator!=( const QgsRectangle &r1 ) const;
00117     QgsRectangle & operator=( const QgsRectangle &r1 );
00118 
00120     void unionRect( const QgsRectangle& rect );
00121 
00124     bool isFinite() const;
00125 
00128     void invert();
00129 
00130   protected:
00131 
00132     // These are protected instead of private so that things like
00133     // the QgsPostGisBox3d can get at them.
00134 
00135     double xmin;
00136     double ymin;
00137     double xmax;
00138     double ymax;
00139 
00140 };
00141 
00142 
00143 inline QgsRectangle::~QgsRectangle()
00144 {
00145 }
00146 
00147 inline void QgsRectangle::setXMinimum( double x )
00148 {
00149   xmin = x;
00150 }
00151 
00152 inline void QgsRectangle::setXMaximum( double x )
00153 {
00154   xmax = x;
00155 }
00156 
00157 inline void QgsRectangle::setYMinimum( double y )
00158 {
00159   ymin = y;
00160 }
00161 
00162 inline void QgsRectangle::setYMaximum( double y )
00163 {
00164   ymax = y;
00165 }
00166 
00167 inline double QgsRectangle::xMaximum() const
00168 {
00169   return xmax;
00170 }
00171 
00172 inline double QgsRectangle::xMinimum() const
00173 {
00174   return xmin;
00175 }
00176 
00177 inline double QgsRectangle::yMaximum() const
00178 {
00179   return ymax;
00180 }
00181 
00182 inline double QgsRectangle::yMinimum() const
00183 {
00184   return ymin;
00185 }
00186 
00187 inline double QgsRectangle::width() const
00188 {
00189   return xmax - xmin;
00190 }
00191 
00192 inline double QgsRectangle::height() const
00193 {
00194   return ymax - ymin;
00195 }
00196 
00197 inline QgsPoint QgsRectangle::center() const
00198 {
00199   return QgsPoint( xmin + width() / 2,  ymin + height() / 2 );
00200 }
00201 inline std::ostream& operator << ( std::ostream& os, const QgsRectangle &r )
00202 {
00203   return os << r.toString().toLocal8Bit().data();
00204 }
00205 
00206 #endif // QGSRECT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines