22#include <QDomDocument>
47 Q_PROPERTY(
double xMinimum READ xMinimum WRITE setXMinimum )
48 Q_PROPERTY(
double xMaximum READ xMaximum WRITE setXMaximum )
49 Q_PROPERTY(
double yMinimum READ yMinimum WRITE setYMinimum )
50 Q_PROPERTY(
double yMaximum READ yMaximum WRITE setYMaximum )
51 Q_PROPERTY(
double width READ width )
52 Q_PROPERTY(
double height READ height )
53 Q_PROPERTY(
double area READ area )
54 Q_PROPERTY(
double perimeter READ perimeter )
56 Q_PROPERTY(
bool isEmpty READ isEmpty )
57 Q_PROPERTY(
bool isNull READ isNull )
70 explicit
QgsRectangle(
double xMin,
double yMin = 0,
double xMax = 0,
double yMax = 0,
bool normalize = true )
SIP_HOLDGIL
88 set( p1, p2, normalize );
98 mXmin = qRectF.topLeft().x();
99 mYmin = qRectF.topLeft().y();
100 mXmax = qRectF.bottomRight().x();
101 mYmax = qRectF.bottomRight().y();
106 mXmin = other.xMinimum();
107 mYmin = other.yMinimum();
108 mXmax = other.xMaximum();
109 mYmax = other.yMaximum();
151 void set(
double xMin,
double yMin,
double xMax,
double yMax,
bool normalize =
true )
193 mXmin = mYmin = std::numeric_limits<double>::max();
194 mXmax = mYmax = -std::numeric_limits<double>::max();
238 std::swap( mXmin, mXmax );
242 std::swap( mYmin, mYmax );
285 double centerX, centerY;
293 centerX = mXmin + width() / 2;
294 centerY = mYmin + height() / 2;
296 scale( scaleFactor, centerX, centerY );
302 void scale(
double scaleFactor,
double centerX,
double centerY )
304 const double newWidth = width() * scaleFactor;
305 const double newHeight = height() * scaleFactor;
306 mXmin = centerX - newWidth / 2.0;
307 mXmax = centerX + newWidth / 2.0;
308 mYmin = centerY - newHeight / 2.0;
309 mYmax = centerY + newHeight / 2.0;
339 setXMinimum( p.
x() );
340 setXMaximum( p.
x() );
341 setYMinimum( p.
y() );
342 setYMaximum( p.
y() );
345 if ( p.
x() < xMinimum() )
346 setXMinimum( p.
x() );
347 if ( p.
x() > xMaximum() )
348 setXMaximum( p.
x() );
349 if ( p.
y() < yMinimum() )
350 setYMinimum( p.
y() );
351 if ( p.
y() > yMaximum() )
352 setYMaximum( p.
y() );
364 return QgsRectangle( mXmin - width, mYmin - width, mXmax + width, mYmax + width );
373 if ( intersects( rect ) )
388 if ( isNull() || rect.isNull() )
393 const double x1 = ( mXmin > rect.mXmin ? mXmin : rect.mXmin );
394 const double x2 = ( mXmax < rect.mXmax ? mXmax : rect.mXmax );
397 const double y1 = ( mYmin > rect.mYmin ? mYmin : rect.mYmin );
398 const double y2 = ( mYmax < rect.mYmax ? mYmax : rect.mYmax );
407 return ( rect.mXmin >= mXmin && rect.mXmax <= mXmax && rect.mYmin >= mYmin && rect.mYmax <= mYmax );
415 return mXmin <= p.x() && p.x() <= mXmax &&
416 mYmin <= p.y() && p.y() <= mYmax;
426 return mXmin <= x && x <= mXmax &&
427 mYmin <= y && y <= mYmax;
437 else if ( !rect.
isNull() )
439 mXmin = std::min( mXmin, rect.
xMinimum() );
440 mXmax = std::max( mXmax, rect.
xMaximum() );
441 mYmin = std::min( mYmin, rect.
yMinimum() );
442 mYmax = std::max( mYmax, rect.
yMaximum() );
455 mXmin = ( ( mXmin < x ) ? mXmin : x );
456 mXmax = ( ( mXmax > x ) ? mXmax : x );
458 mYmin = ( ( mYmin < y ) ? mYmin : y );
459 mYmax = ( ( mYmax > y ) ? mYmax : y );
469 combineExtentWith( point.
x(), point.
y() );
478 const double dx = std::max( std::max( mXmin - point.
x(), 0.0 ), point.
x() - mXmax );
479 const double dy = std::max( std::max( mYmin - point.
y(), 0.0 ), point.
y() - mYmax );
480 return std::sqrt( dx * dx + dy * dy );
529 return ( std::isnan( mXmin ) && std::isnan( mXmax ) && std::isnan( mYmin ) && std::isnan( mYmax ) ) ||
537 Q_INVOKABLE QString asWktCoordinates()
const;
542 Q_INVOKABLE QString asWktPolygon()
const;
549 return QRectF(
static_cast< qreal
>( mXmin ),
static_cast< qreal
>( mYmin ),
static_cast< qreal
>( mXmax - mXmin ),
static_cast< qreal
>( mYmax - mYmin ) );
557 Q_INVOKABLE QString toString(
int precision = 16 )
const;
562 QString asPolygon()
const;
566 if ( isNull() )
return r1.
isNull();
576 return ( !
operator==( r1 ) );
598 if ( std::isinf( mXmin ) || std::isinf( mYmin ) || std::isinf( mXmax ) || std::isinf( mYmax ) )
602 if ( std::isnan( mXmin ) || std::isnan( mYmin ) || std::isnan( mXmax ) || std::isnan( mYmax ) )
614 std::swap( mXmin, mYmin );
615 std::swap( mXmax, mYmax );
622 QgsBox3D toBox3d(
double zMin,
double zMax )
const;
625 operator QVariant()
const
627 return QVariant::fromValue( *
this );
639 SIP_PYOBJECT __repr__();
642 if ( sipCpp->isNull() )
643 str = QStringLiteral(
"<QgsRectangle()>" );
645 str = QStringLiteral(
"<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
646 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
652 double mXmin = std::numeric_limits<double>::max();
653 double mYmin = std::numeric_limits<double>::max();
654 double mXmax = -std::numeric_limits<double>::max();
655 double mYmax = -std::numeric_limits<double>::max();
675 return os << r.
toString().toLocal8Bit().data();
A 3-dimensional box composed of x, y, z coordinates.
A class to represent a 2D point.
A rectangle specified with double values.
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
Q_DECL_DEPRECATED void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
void combineExtentWith(const QgsPointXY &point)
Expands the rectangle so that it covers both the original rectangle and the given point.
double area() const
Returns the area of the rectangle.
void include(const QgsPointXY &p)
Updates the rectangle to include the specified point.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void combineExtentWith(double x, double y)
Expands the rectangle so that it covers both the original rectangle and the given point.
QgsRectangle(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Construct a rectangle from two points.
bool contains(double x, double y) const
Returns true when rectangle contains the point at (x, y).
void setYMinimum(double y)
Set the minimum y value.
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
bool operator!=(const QgsRectangle &r1) const
void setXMinimum(double x)
Set the minimum x value.
double width() const
Returns the width of the rectangle.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool isNull() const
Test if the rectangle is null (holding no spatial information).
QgsRectangle(const QgsRectangle &other)
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsRectangle & operator=(const QgsRectangle &r1)
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
void setYMaximum(double y)
Set the maximum y value.
QgsPointXY center() const
Returns the center point of the rectangle.
void setXMaximum(double x)
Set the maximum x value.
void grow(double delta)
Grows the rectangle in place by the specified amount.
bool operator==(const QgsRectangle &r1) const
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
double perimeter() const
Returns the perimeter of the rectangle.
void set(double xMin, double yMin, double xMax, double yMax, bool normalize=true)
Sets the rectangle from four points.
void normalize()
Normalize the rectangle so it has non-negative width/height.
bool isEmpty() const
Returns true if the rectangle has no area.
QgsRectangle(const QRectF &qRectF)
Construct a rectangle from a QRectF.
double height() const
Returns the height of the rectangle.
void setNull()
Mark a rectangle as being null (holding no spatial information).
bool contains(const QgsPointXY &p) const
Returns true when rectangle contains a point.
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
void scale(double scaleFactor, double centerX, double centerY)
Scale the rectangle around its center point.
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
void invert()
Swap x/y coordinates in the rectangle.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double distance(const QgsPointXY &point) const
Returns the distance from point to the nearest point on the boundary of the rectangle.
A class to represent a vector.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QgsInterval operator-(QDate date1, QDate date2)
Returns the interval between two dates.
QDateTime operator+(const QDateTime &start, const QgsInterval &interval)
Adds an interval to a datetime.
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsRectangle &rectangle)
Writes the list rectangle to stream out.
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsRectangle &rectangle)
Reads a rectangle from stream in into rectangle.