23 #include <QTextStream> 108 double centerX, centerY;
119 scale( scaleFactor, centerX, centerY );
124 double newWidth =
width() * scaleFactor;
125 double newHeight =
height() * scaleFactor;
126 xmin = centerX - newWidth / 2.0;
127 xmax = centerX + newWidth / 2.0;
128 ymin = centerY - newHeight / 2.0;
129 ymax = centerY + newHeight / 2.0;
258 return QRectF( static_cast< qreal >(
xmin ), static_cast< qreal >(
ymin ), static_cast< qreal >(
xmax -
xmin ), static_cast< qreal >(
ymax -
ymin ) );
264 if ( automaticPrecision )
269 precision =
static_cast<int>( ceil( -1.0 * log10( qMin(
width(),
height() ) ) ) ) + 1;
271 if ( precision > 20 )
288 rep =
QString(
"%1,%2 : %3,%4" )
289 .
arg(
xmin, 0,
'f', thePrecision )
290 .
arg(
ymin, 0,
'f', thePrecision )
291 .
arg(
xmax, 0,
'f', thePrecision )
292 .
arg(
ymax, 0,
'f', thePrecision );
336 return ( !
operator==( r1 ) );
399 in >> xmin >> ymin >> xmax >>
ymax;
void unionRect(const QgsRectangle &rect)
Updates rectangle to include passed argument.
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
QgsRectangle & operator=(const QgsRectangle &r1)
Assignment operator.
A rectangle specified with double values.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
void setRealNumberNotation(RealNumberNotation notation)
void setXMaximum(double x)
Set the maximum x value.
QgsRectangle buffer(double width)
Get rectangle enlarged by buffer.
void setRealNumberPrecision(int precision)
QDataStream & operator>>(QDataStream &in, QgsRectangle &rectangle)
Reads a rectangle from stream in into rectangle.
void scale(double scaleFactor, const QgsPoint *c=nullptr)
Scale the rectangle around its center point.
QgsRectangle intersect(const QgsRectangle *rect) const
return the intersection with the given rectangle
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
double y() const
Get the y value of the point.
void set(const QgsPoint &p1, const QgsPoint &p2)
Set the rectangle from two QgsPoints.
QString asWktPolygon() const
returns string representation as WKT Polygon
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
QgsRectangle(double xmin=0, double ymin=0, double xmax=0, double ymax=0)
Constructor.
#define QgsDebugMsgLevel(str, level)
void grow(double delta)
Grow the rectangle by the specified amount.
bool isEmpty() const
test if rectangle is empty.
void include(const QgsPoint &p)
Updates the rectangle to include the specified point.
double width() const
Width of the rectangle.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
void setYMinimum(double y)
Set the minimum y value.
QString asPolygon() const
returns rectangle as a polygon
A class to represent a point.
QString asWktCoordinates() const
returns string representation in Wkt form
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
void combineExtentWith(const QgsRectangle &rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
bool operator==(const QgsRectangle &r1) const
Comparison operator.
QRectF toRectF() const
returns a QRectF with same coordinates.
void setYMaximum(double y)
Set the maximum y value.
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
double xMinimum() const
Get the x minimum value (left side of rectangle)
double yMaximum() const
Get the y maximum value (top side of rectangle)
QPointF bottomRight() const
void normalize()
Normalize the rectangle so it has non-negative width/height.
bool operator!=(const QgsRectangle &r1) const
Comparison operator.
bool intersects(const QgsRectangle &rect) const
returns true when rectangle intersects with other rectangle
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QDataStream & operator<<(QDataStream &out, const QgsRectangle &rectangle)
Writes the list rectangle to stream out.
double x() const
Get the x value of the point.
void setXMinimum(double x)
Set the minimum x value.
double height() const
Height of the rectangle.