1
/***************************************************************************
2
qgsrect.h - description
4
begin : Sat Jun 22 2002
5
copyright : (C) 2002 by Gary E.Sherman
6
email : sherman at mrcc.com
7
***************************************************************************/
9
/***************************************************************************
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. *
16
***************************************************************************/
17
/* $Id: qgsrect.h 5894 2006-09-30 19:53:00Z g_j_m $ */
30
* \brief A rectangle specified with double values.
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
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);
43
QgsRect(const QgsRect &other);
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.
63
//! Get the x maximum value (right side of rectangle)
65
//! Get the x maximum value (right side of rectangle)
67
//! Get the x minimum value (left side of rectangle)
69
//! Get the y maximum value (top side of rectangle)
71
//! Normalize the rectangle so it has non-negative width/height
73
//! Width of the rectangle
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
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
102
bool operator==(const QgsRect &r1) const;
103
/*! Comparison operator
104
@return False if rectangles are equal
106
bool operator!=(const QgsRect &r1) const;
107
/*! Assignment operator
108
* @param r1 QgsRect to assign from
110
QgsRect & operator=(const QgsRect &r1);
112
/** updates rectangle to include passed argument */
113
void unionRect(const QgsRect& rect);
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;
121
// These are protected instead of private so that things like
122
// the QgsPostGisBox3d can get at them.
132
inline QgsRect::~QgsRect()
136
inline void QgsRect::setXmin(double x)
141
inline void QgsRect::setXmax(double x)
146
inline void QgsRect::setYmin(double y)
151
inline void QgsRect::setYmax(double y)
156
inline double QgsRect::xMax() const
161
inline double QgsRect::xMin() const
166
inline double QgsRect::yMax() const
171
inline double QgsRect::yMin() const
176
inline double QgsRect::width() const
181
inline double QgsRect::height() const
186
inline QgsPoint QgsRect::center() const
188
return QgsPoint(xmin + width() / 2 , ymin + height() / 2);
190
inline std::ostream& operator << (std::ostream& os, const QgsRect &r)
192
return os << r.stringRep().toLocal8Bit().data();