27#include <QDomDocument>
31using namespace Qt::StringLiterals;
106 mXmin = qRectF.topLeft().x();
107 mYmin = qRectF.topLeft().y();
108 mXmax = qRectF.bottomRight().x();
109 mYmax = qRectF.bottomRight().y();
114 mXmin = other.xMinimum();
115 mYmin = other.yMinimum();
116 mXmax = other.xMaximum();
117 mYmax = other.yMaximum();
171 void set(
double xMin,
double yMin,
double xMax,
double yMax,
bool normalize =
true )
213 mXmin = mYmin = std::numeric_limits<double>::max();
214 mXmax = mYmax = -std::numeric_limits<double>::max();
328 std::swap( mXmin, mXmax );
332 std::swap( mYmin, mYmax );
375 double centerX, centerY;
383 centerX = mXmin +
width() / 2;
384 centerY = mYmin +
height() / 2;
386 scale( scaleFactor, centerX, centerY );
392 void scale(
double scaleFactor,
double centerX,
double centerY )
394 const double newWidth =
width() * scaleFactor;
395 const double newHeight =
height() * scaleFactor;
396 mXmin = centerX - newWidth / 2.0;
397 mXmax = centerX + newWidth / 2.0;
398 mYmin = centerY - newHeight / 2.0;
399 mYmax = centerY + newHeight / 2.0;
478 if (
isNull() || rect.isNull() )
483 const double x1 = ( mXmin > rect.mXmin ? mXmin : rect.mXmin );
484 const double x2 = ( mXmax < rect.mXmax ? mXmax : rect.mXmax );
487 const double y1 = ( mYmin > rect.mYmin ? mYmin : rect.mYmin );
488 const double y2 = ( mYmax < rect.mYmax ? mYmax : rect.mYmax );
505 return containsRange(mXmin, mXmax, rect.mXmin, rect.mXmax) && containsRange(mYmin, mYmax, rect.mYmin, rect.mYmax);
514 return mXmin <= p.x() && p.x() <= mXmax &&
515 mYmin <= p.y() && p.y() <= mYmax;
525 return mXmin <= x && x <= mXmax &&
526 mYmin <= y && y <= mYmax;
536 else if ( !rect.
isNull() )
538 mXmin = std::min( mXmin, rect.
xMinimum() );
539 mXmax = std::max( mXmax, rect.
xMaximum() );
540 mYmin = std::min( mYmin, rect.
yMinimum() );
541 mYmax = std::max( mYmax, rect.
yMaximum() );
554 mXmin = ( ( mXmin < x ) ? mXmin : x );
555 mXmax = ( ( mXmax > x ) ? mXmax : x );
557 mYmin = ( ( mYmin < y ) ? mYmin : y );
558 mYmax = ( ( mYmax > y ) ? mYmax : y );
577 const double dx = std::max( std::max( mXmin - point.
x(), 0.0 ), point.
x() - mXmax );
578 const double dy = std::max( std::max( mYmin - point.
y(), 0.0 ), point.
y() - mYmax );
579 return std::sqrt( dx * dx + dy * dy );
661 return ( std::isnan( mXmin ) && std::isnan( mXmax ) && std::isnan( mYmin ) && std::isnan( mYmax ) ) ||
677 if ( ( !
isFinite() ) || ( mXmax <= mXmin ) || ( mYmax <= mYmin ) )
698 return ( std::isinf( mXmin ) || mXmin == std::numeric_limits<double>::lowest() )
699 && ( std::isinf( mYmin ) || mYmin == std::numeric_limits<double>::lowest() )
700 && ( std::isinf( mXmax ) || mXmax == std::numeric_limits<double>::max() )
701 && ( std::isinf( mYmax ) || mYmax == std::numeric_limits<double>::max() );
707 Q_INVOKABLE QString asWktCoordinates()
const;
712 Q_INVOKABLE QString asWktPolygon()
const;
719 return QRectF(
static_cast< qreal
>( mXmin ),
static_cast< qreal
>( mYmin ),
static_cast< qreal
>( mXmax - mXmin ),
static_cast< qreal
>( mYmax - mYmin ) );
727 Q_INVOKABLE QString toString(
int precision = 16 )
const;
732 QString asPolygon()
const;
746 return ( !
operator==( r1 ) );
772 if ( std::isinf( mXmin ) || std::isinf( mYmin ) || std::isinf( mXmax ) || std::isinf( mYmax ) )
776 if ( std::isnan( mXmin ) || std::isnan( mYmin ) || std::isnan( mXmax ) || std::isnan( mYmax ) )
788 std::swap( mXmin, mYmin );
789 std::swap( mXmax, mYmax );
796 QgsBox3D toBox3d(
double zMin,
double zMax )
const;
814 std::pair< QgsRectangle, QgsRectangle > splitAtAntimeridian()
const;
817 operator QVariant()
const
819 return QVariant::fromValue( *
this );
832 SIP_PYOBJECT __repr__();
835 if ( sipCpp->isNull() )
836 str = u
"<QgsRectangle()>"_s;
838 str = u
"<QgsRectangle: %1>"_s.arg( sipCpp->asWktCoordinates() );
839 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
846 double mXmin = std::numeric_limits<double>::max();
847 double mYmin = std::numeric_limits<double>::max();
848 double mXmax = -std::numeric_limits<double>::max();
849 double mYmax = -std::numeric_limits<double>::max();
855 static bool containsRange(
double aMin,
double aMax,
double bMin,
double bMax)
857 const bool aNormalized = (aMax >= aMin);
858 const bool bNormalized = (bMax >= bMin);
860 if (aNormalized && bNormalized)
865 else if (!aNormalized && bNormalized)
869 else if ( aNormalized && !bNormalized )
898 return os << r.
toString().toLocal8Bit().data();
A 3-dimensional box composed of x, y, z coordinates.
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 rounded to the spec...
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.
QgsRectangle()=default
Constructor for a null rectangle.
double area() const
Returns the area of the rectangle.
void include(const QgsPointXY &p)
Updates the rectangle to include the specified point.
bool isMaximal() const
Test if the rectangle is the maximal possible rectangle.
double xMinimum() const
Returns the x minimum value.
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).
static QgsRectangle fromWkt(const QString &wkt)
Creates a new rectangle from a wkt string.
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.
bool operator!=(const QgsRectangle &r1) const
void setXMinimum(double x)
Set the minimum x value.
static QgsRectangle fromEdges(double left, double top, double right, double bottom)
Creates a rectangle from the left, top, right and bottom edges.
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.
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.
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
bool isValid() const
Test if the rectangle is valid.
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.
double left() const
Returns the left side of the rectangle.
void normalize()
Normalize the rectangle so it has non-negative width/height.
double right() const
Returns the right side of the rectangle.
bool isEmpty() const
Returns true if the rectangle has no area.
QgsRectangle(const QRectF &qRectF)
Construct a rectangle from a QRectF.
static QgsRectangle fromCenterAndSize(const QgsPointXY ¢er, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
bool isNormalized() const
Returns true if the rectangle is normalized.
double height() const
Returns the height of the rectangle.
void setNull()
Mark a rectangle as being null (holding no spatial information).
bool isPoint() const
Returns true if the rectangle represents a point.
double bottom() const
Returns the bottom side of the rectangle.
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.
double top() const
Returns the top side of the rectangle.
Represent a 2-dimensional 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).
bool qgsDoubleGreaterThanOrNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles to see if one is greater than the other or very near to the other.
bool qgsDoubleLessThanOrNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles to see if one is less than the other or very near to the other.
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.