~ubuntu-branches/ubuntu/quantal/qgis/quantal

« back to all changes in this revision

Viewing changes to src/core/qgsrect.h

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          qgsrect.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
/* $Id: qgsrect.h 5894 2006-09-30 19:53:00Z g_j_m $ */
 
18
 
 
19
#ifndef QGSRECT_H
 
20
#define QGSRECT_H
 
21
 
 
22
#include <iosfwd>
 
23
 
 
24
class QString;
 
25
 
 
26
#include "qgspoint.h"
 
27
 
 
28
 
 
29
/*! \class QgsRect
 
30
 * \brief A rectangle specified with double values.
 
31
 *
 
32
 * QgsRect is used to store a rectangle when double values are required. 
 
33
 * Examples are storing a layer extent or the current view extent of a map
 
34
 */
 
35
class QgsRect
 
36
{
 
37
 public:
 
38
    //! Constructor
 
39
    QgsRect(double xmin=0, double ymin=0, double xmax=0, double ymax=0);
 
40
    //! Construct a rectangle from two points. The rectangle is normalized after construction.
 
41
    QgsRect(QgsPoint const & p1, QgsPoint const & p2);
 
42
    //! Copy constructor
 
43
    QgsRect(const QgsRect &other);
 
44
    //! Destructor
 
45
    ~QgsRect();
 
46
    //! Set the rectangle from two QgsPoints. The rectangle is
 
47
    //normalised after construction. 
 
48
    void set(const QgsPoint& p1, const QgsPoint& p2);
 
49
    //! Set the rectangle from four points. The rectangle is
 
50
    //  normalised after construction. 
 
51
    void set(double xmin, double ymin, double xmax, double ymax);
 
52
    //! Set the minimum x value
 
53
    void setXmin(double x);
 
54
    //! Set the maximum x value
 
55
    void setXmax(double x);
 
56
    //! Set the maximum y value
 
57
    void setYmin(double y);
 
58
    //! Set the maximum y value
 
59
    void setYmax(double y);
 
60
    //! Set a rectangle so that min corner is at max
 
61
    // and max corner is at min. It is NOT normalized.
 
62
    void setMinimal();
 
63
    //! Get the x maximum value (right side of rectangle)
 
64
    double xMax() const;
 
65
    //! Get the x maximum value (right side of rectangle)
 
66
    double xMin() const;
 
67
    //! Get the x minimum value (left side of rectangle)
 
68
    double yMax() const;
 
69
    //! Get the y maximum value (top side of rectangle)
 
70
    double yMin() const;
 
71
    //! Normalize the rectangle so it has non-negative width/height
 
72
    void normalize();
 
73
    //! Width of the rectangle
 
74
    double width() const;
 
75
    //! Height of the rectangle
 
76
    double height() const;
 
77
    //! Center point of the rectangle
 
78
    QgsPoint center() const;
 
79
    //! Scale the rectangle around its center point
 
80
    void scale(double, const QgsPoint *c =0);
 
81
    //! Expand the rectangle to support zoom out scaling
 
82
    void expand(double, const QgsPoint *c = 0);
 
83
    //! return the intersection with the given rectangle
 
84
    QgsRect intersect(QgsRect *rect);
 
85
    //! expand the rectangle so that covers both the original rectangle and the given rectangle
 
86
    void combineExtentWith(QgsRect *rect);
 
87
    //! expand the rectangle so that covers both the original rectangle and the given point
 
88
    void combineExtentWith(double x, double y);
 
89
    //! test if rectangle is empty
 
90
    bool isEmpty() const;
 
91
    //! returns string representation in WKT form
 
92
    QString asWKTCoords() const;
 
93
    //! returns string representation of form xmin,ymin xmax,ymax
 
94
    QString stringRep(bool automaticPrecision = false) const;
 
95
    //! overloaded stringRep that allows precision of numbers to be set
 
96
    QString stringRep(int thePrecision) const;
 
97
    //! returns rectangle s a polygon 
 
98
    QString asPolygon() const;
 
99
    /*! Comparison operator
 
100
      @return True if rectangles are equal
 
101
    */
 
102
    bool operator==(const QgsRect &r1) const;
 
103
    /*! Comparison operator
 
104
    @return False if rectangles are equal
 
105
     */
 
106
    bool operator!=(const QgsRect &r1) const;
 
107
    /*! Assignment operator
 
108
     * @param r1 QgsRect to assign from
 
109
     */
 
110
    QgsRect & operator=(const QgsRect &r1);
 
111
    
 
112
    /** updates rectangle to include passed argument */
 
113
    void unionRect(const QgsRect& rect);
 
114
 
 
115
    /** Returns true if the rectangle has finite boundaries. Will
 
116
        return false if any of the rectangle boundaries are NaN or Inf. */
 
117
    bool isFinite() const;
 
118
 
 
119
protected:
 
120
 
 
121
    // These are protected instead of private so that things like
 
122
    // the QgsPostGisBox3d can get at them.
 
123
    
 
124
    double xmin;
 
125
    double ymin;
 
126
    double xmax;
 
127
    double ymax;
 
128
   
 
129
};
 
130
 
 
131
 
 
132
inline QgsRect::~QgsRect()
 
133
{
 
134
}
 
135
 
 
136
inline void QgsRect::setXmin(double x)
 
137
{
 
138
    xmin = x;
 
139
}
 
140
 
 
141
inline void QgsRect::setXmax(double x)
 
142
{
 
143
    xmax = x;
 
144
}
 
145
 
 
146
inline void QgsRect::setYmin(double y)
 
147
{
 
148
    ymin = y;
 
149
}
 
150
 
 
151
inline void QgsRect::setYmax(double y)
 
152
{
 
153
    ymax = y;
 
154
}
 
155
 
 
156
inline double QgsRect::xMax() const
 
157
{
 
158
    return xmax;
 
159
}
 
160
 
 
161
inline double QgsRect::xMin() const
 
162
{
 
163
    return xmin;
 
164
}
 
165
 
 
166
inline double QgsRect::yMax() const
 
167
{
 
168
    return ymax;
 
169
}
 
170
 
 
171
inline double QgsRect::yMin() const
 
172
{
 
173
    return ymin;
 
174
}
 
175
 
 
176
inline double QgsRect::width() const
 
177
{
 
178
    return xmax - xmin;
 
179
}
 
180
 
 
181
inline double QgsRect::height() const
 
182
{
 
183
    return ymax - ymin;
 
184
}
 
185
 
 
186
inline QgsPoint QgsRect::center() const
 
187
{
 
188
    return QgsPoint(xmin + width() / 2 ,  ymin + height() / 2);
 
189
}
 
190
inline std::ostream& operator << (std::ostream& os, const QgsRect &r)
 
191
{
 
192
  return os << r.stringRep().toLocal8Bit().data();
 
193
}
 
194
  
 
195
#endif // QGSRECT_H