23 #include <QTextStream> 52 mXmin = qRectF.topLeft().x();
53 mYmin = qRectF.topLeft().y();
54 mXmax = qRectF.bottomRight().x();
55 mYmax = qRectF.bottomRight().y();
74 if ( poly.size() != 1 )
78 if ( polyline.size() == 5 && polyline.at( 0 ) == polyline.at( 4 ) && geom.
isGeosValid() )
79 return QgsRectangle( polyline.at( 0 ).x(), polyline.at( 0 ).y(), polyline.at( 2 ).x(), polyline.at( 2 ).y() );
86 double xMin = center.
x() - width / 2.0;
87 double xMax = xMin +
width;
88 double yMin = center.
y() - height / 2.0;
89 double yMax = yMin +
height;
118 std::swap( mXmin, mXmax );
122 std::swap( mYmin, mYmax );
128 mXmin = std::numeric_limits<double>::max();
129 mYmin = std::numeric_limits<double>::max();
130 mXmax = -std::numeric_limits<double>::max();
131 mYmax = -std::numeric_limits<double>::max();
137 double centerX, centerY;
145 centerX = mXmin +
width() / 2;
146 centerY = mYmin +
height() / 2;
148 scale( scaleFactor, centerX, centerY );
153 double newWidth =
width() * scaleFactor;
154 double newHeight =
height() * scaleFactor;
155 mXmin = centerX - newWidth / 2.0;
156 mXmax = centerX + newWidth / 2.0;
157 mYmin = centerY - newHeight / 2.0;
158 mYmax = centerY + newHeight / 2.0;
183 return QgsRectangle( mXmin - width, mYmin - width, mXmax + width, mYmax + width );
201 double x1 = ( mXmin > rect.mXmin ? mXmin : rect.mXmin );
202 double x2 = ( mXmax < rect.mXmax ? mXmax : rect.mXmax );
205 double y1 = ( mYmin > rect.mYmin ? mYmin : rect.mYmin );
206 double y2 = ( mYmax < rect.mYmax ? mYmax : rect.mYmax );
212 return ( rect.mXmin >= mXmin && rect.mXmax <= mXmax && rect.mYmin >= mYmin && rect.mYmax <= mYmax );
217 return mXmin <= p.
x() && p.
x() <= mXmax &&
218 mYmin <= p.
y() && p.
y() <= mYmax;
225 else if ( !rect.
isNull() )
227 mXmin = std::min( mXmin, rect.
xMinimum() );
228 mXmax = std::max( mXmax, rect.
xMaximum() );
229 mYmin = std::min( mYmin, rect.
yMinimum() );
230 mYmax = std::max( mYmax, rect.
yMaximum() );;
240 mXmin = ( ( mXmin < x ) ? mXmin : x );
241 mXmax = ( ( mXmax > x ) ? mXmax : x );
243 mYmin = ( ( mYmin < y ) ? mYmin : y );
244 mYmax = ( ( mYmax > y ) ? mYmax : y );
250 double xmin = mXmin - v.
x();
251 double xmax = mXmax - v.
x();
252 double ymin = mYmin - v.
y();
253 double ymax = mYmax - v.
y();
259 double xmin = mXmin + v.
x();
260 double xmax = mXmax + v.
x();
261 double ymin = mYmin + v.
y();
262 double ymax = mYmax + v.
y();
309 QStringLiteral(
"POLYGON((" ) +
315 QStringLiteral(
"))" );
322 return QRectF( static_cast< qreal >( mXmin ), static_cast< qreal >( mYmin ), static_cast< qreal >( mXmax - mXmin ), static_cast< qreal >( mYmax - mYmin ) );
334 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
336 if ( precision > 20 )
342 rep = QStringLiteral(
"Empty" );
344 rep = QStringLiteral(
"%1,%2 : %3,%4" )
345 .arg( mXmin, 0,
'f', precision )
346 .arg( mYmin, 0,
'f', precision )
347 .arg( mXmax, 0,
'f', precision )
348 .arg( mYmax, 0,
'f', precision );
361 QTextStream foo( &rep );
363 foo.setRealNumberPrecision( 8 );
364 foo.setRealNumberNotation( QTextStream::FixedNotation );
368 << mXmin <<
' ' << mYmin <<
", " 369 << mXmin <<
' ' << mYmax <<
", " 370 << mXmax <<
' ' << mYmax <<
", " 371 << mXmax <<
' ' << mYmin <<
", " 372 << mXmin <<
' ' << mYmin;
388 return ( !
operator==( r1 ) );
406 if ( std::isinf( mXmin ) || std::isinf( mYmin ) || std::isinf( mXmax ) || std::isinf( mYmax ) )
410 if ( std::isnan( mXmin ) || std::isnan( mYmin ) || std::isnan( mXmax ) || std::isnan( mYmax ) )
419 std::swap( mXmin, mYmin );
420 std::swap( mXmax, mYmax );
425 return QgsBox3d( mXmin, mYmin, zMin, mXmax, mYmax, zMax );
436 double xmin, ymin, xmax, ymax;
437 in >> xmin >> ymin >> xmax >> ymax;
QgsRectangle & operator+=(const QgsVector v)
Moves this rectangle in the direction of the vector.
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.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
void setXMaximum(double x)
Set the maximum x value.
static QgsRectangle fromWkt(const QString &wkt)
Creates a new rectangle from a wkt string.
A class to represent a 2D point.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
QDataStream & operator>>(QDataStream &in, QgsRectangle &rectangle)
Reads a rectangle from stream in into rectangle.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
void include(const QgsPointXY &p)
Updates the rectangle to include the specified point.
A geometry is the spatial representation of a feature.
QgsRectangle intersect(const QgsRectangle *rect) const
Return the intersection with the given rectangle.
A 3-dimensional box composed of x, y, z coordinates.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
bool isGeosValid() const
Checks validity of the geometry using GEOS.
QString asWktPolygon() const
Returns a string representation of the rectangle as a WKT Polygon.
QgsRectangle operator-(const QgsVector v) const
Returns a rectangle offset from this one in the direction of the reversed vector. ...
QgsRectangle operator+(const QgsVector v) const
Returns a rectangle offset from this one in the direction of the vector.
QgsRectangle buffered(double width) const
Get rectangle enlarged by buffer.
static QgsRectangle fromCenterAndSize(QgsPointXY center, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
#define QgsDebugMsgLevel(str, level)
void grow(double delta)
Grows the rectangle in place by the specified amount.
bool isEmpty() const
Returns true if the rectangle is empty.
QgsPolygonXY asPolygon() const
Returns contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list...
double width() const
Returns the 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 the rectangle as a polygon.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
QString asWktCoordinates() const
Returns a string representation of the rectangle in WKT format.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
A class to represent a vector.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns 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.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
bool operator==(const QgsRectangle &r1) const
Comparison operator.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
void setYMaximum(double y)
Set the maximum y value.
QgsRectangle()=default
Constructor for a null rectangle.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
double x() const
Returns the vector's x-component.
QgsPointXY center() const
Returns the center point of the rectangle.
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.
double y() const
Returns the vector's y-component.
QgsRectangle & operator-=(const QgsVector v)
Moves this rectangle in the direction of the reversed vector.
QDataStream & operator<<(QDataStream &out, const QgsRectangle &rectangle)
Writes the list rectangle to stream out.
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
QgsBox3d toBox3d(double zMin, double zMax) const
Converts the rectangle to a 3D box, with the specified zMin and zMax z values.
void setXMinimum(double x)
Set the minimum x value.
void invert()
Swap x/y coordinates in the rectangle.
double height() const
Returns the height of the rectangle.