1
/***************************************************************************
2
qgsrect.cpp - 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.cpp,v 1.21 2004/10/21 17:27:38 mcoletti Exp $ */
23
QgsRect::QgsRect(QgsPoint const & p1, QgsPoint const & p2)
32
QgsRect::QgsRect(const QgsRect &r){
39
void QgsRect::normalize()
55
void QgsRect::scale(double scaleFactor, QgsPoint * cp)
57
// scale from the center
58
double centerX, centerY;
65
centerX = xmin + width() / 2;
66
centerY = ymin + height() / 2;
68
double newWidth = width() * scaleFactor;
69
double newHeight = height() * scaleFactor;
70
xmin = centerX - newWidth / 2.0;
71
xmax = centerX + newWidth / 2.0;
72
ymin = centerY - newHeight / 2.0;
73
ymax = centerY + newHeight / 2.0;
75
void QgsRect::expand(double scaleFactor, QgsPoint * cp)
77
// scale from the center
78
double centerX, centerY;
85
centerX = xmin + width() / 2;
86
centerY = ymin + height() / 2;
89
double newWidth = width() * scaleFactor;
90
double newHeight = height() * scaleFactor;
91
xmin = centerX - newWidth;
92
xmax = centerX + newWidth;
93
ymin = centerY - newHeight;
94
ymax = centerY + newHeight;
97
QgsRect QgsRect::intersect(QgsRect * rect)
99
QgsRect intersection = QgsRect();
101
intersection.setXmin(xmin > rect->xMin()?xmin:rect->xMin());
102
intersection.setXmax(xmax < rect->xMax()?xmax:rect->xMax());
103
intersection.setYmin(ymin > rect->yMin()?ymin:rect->yMin());
104
intersection.setYmax(ymax < rect->yMax()?ymax:rect->yMax());
107
bool QgsRect::isEmpty()
109
if (xmax <= xmin || ymax <= ymin)
117
// Return a string representation of the rectangle with high precision
118
QString QgsRect::stringRep() const
121
QString rep = tmp.sprintf("%16f %16f,%16f %16f", xmin, ymin, xmax, ymax);
125
// overloaded version of above fn to allow precision to be set
126
// Return a string representation of the rectangle with high precision
127
QString QgsRect::stringRep(int thePrecision) const
130
QString rep = QString::number(xmin,'f',thePrecision) +
132
QString::number(ymin,'f',thePrecision) +
134
QString::number(xmax,'f',thePrecision) +
136
QString::number(ymax,'f',thePrecision) ;
138
std::cout << "Extents : " << rep << std::endl;
142
// Return the rectangle as a set of polygon coordinates
143
QString QgsRect::asPolygon() const
146
QString rep = tmp.sprintf("%16f %16f,%16f %16f,%16f %16f,%16f %16f,%16f %16f",
147
xmin, ymin, xmin, ymax, xmax, ymax, xmax, ymin, xmin, ymin);
151
bool QgsRect::operator==(const QgsRect & r1)
153
return (r1.xMax() == this->xMax() && r1.xMin() == this->xMin() && r1.yMax() == this->yMax() && r1.yMin() == this->yMin());
156
QgsRect & QgsRect::operator=(const QgsRect & r)