QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
18 #ifndef QGSRECTANGLE_H
19 #define QGSRECTANGLE_H
21 #include "qgis_core.h"
24 #include <QDomDocument>
54 explicit QgsRectangle(
double xMin,
double yMin = 0,
double xMax = 0,
double yMax = 0,
bool normalize =
true )
SIP_HOLDGIL
72 set( p1, p2, normalize );
82 mXmin = qRectF.topLeft().x();
83 mYmin = qRectF.topLeft().y();
84 mXmax = qRectF.bottomRight().x();
85 mYmax = qRectF.bottomRight().y();
91 mXmin = other.xMinimum();
92 mYmin = other.yMinimum();
93 mXmax = other.xMaximum();
94 mYmax = other.yMaximum();
138 void set(
double xMin,
double yMin,
double xMax,
double yMax,
bool normalize =
true )
174 mXmin = std::numeric_limits<double>::max();
175 mYmin = std::numeric_limits<double>::max();
176 mXmax = -std::numeric_limits<double>::max();
177 mYmax = -std::numeric_limits<double>::max();
210 std::swap( mXmin, mXmax );
214 std::swap( mYmin, mYmax );
259 double centerX, centerY;
267 centerX = mXmin + width() / 2;
268 centerY = mYmin + height() / 2;
270 scale( scaleFactor, centerX, centerY );
276 void scale(
double scaleFactor,
double centerX,
double centerY )
278 const double newWidth = width() * scaleFactor;
279 const double newHeight = height() * scaleFactor;
280 mXmin = centerX - newWidth / 2.0;
281 mXmax = centerX + newWidth / 2.0;
282 mYmin = centerY - newHeight / 2.0;
283 mYmax = centerY + newHeight / 2.0;
309 if ( p.
x() < xMinimum() )
310 setXMinimum( p.
x() );
311 if ( p.
x() > xMaximum() )
312 setXMaximum( p.
x() );
313 if ( p.
y() < yMinimum() )
314 setYMinimum( p.
y() );
315 if ( p.
y() > yMaximum() )
316 setYMaximum( p.
y() );
327 return QgsRectangle( mXmin - width, mYmin - width, mXmax + width, mYmax + width );
336 if ( intersects( rect ) )
351 const double x1 = ( mXmin > rect.mXmin ? mXmin : rect.mXmin );
352 const double x2 = ( mXmax < rect.mXmax ? mXmax : rect.mXmax );
355 const double y1 = ( mYmin > rect.mYmin ? mYmin : rect.mYmin );
356 const double y2 = ( mYmax < rect.mYmax ? mYmax : rect.mYmax );
365 return ( rect.mXmin >= mXmin && rect.mXmax <= mXmax && rect.mYmin >= mYmin && rect.mYmax <= mYmax );
373 return mXmin <= p.x() && p.x() <= mXmax &&
374 mYmin <= p.y() && p.y() <= mYmax;
384 return mXmin <= x && x <= mXmax &&
385 mYmin <= y && y <= mYmax;
395 else if ( !rect.
isNull() )
397 mXmin = std::min( mXmin, rect.
xMinimum() );
398 mXmax = std::max( mXmax, rect.
xMaximum() );
399 mYmin = std::min( mYmin, rect.
yMinimum() );
400 mYmax = std::max( mYmax, rect.
yMaximum() );
413 mXmin = ( ( mXmin < x ) ? mXmin : x );
414 mXmax = ( ( mXmax > x ) ? mXmax : x );
416 mYmin = ( ( mYmin < y ) ? mYmin : y );
417 mYmax = ( ( mYmax > y ) ? mYmax : y );
427 combineExtentWith( point.
x(), point.
y() );
436 const double dx = std::max( std::max( mXmin - point.
x(), 0.0 ), point.
x() - mXmax );
437 const double dy = std::max( std::max( mYmin - point.
y(), 0.0 ), point.
y() - mYmax );
438 return std::sqrt( dx * dx + dy * dy );
490 QString asWktCoordinates()
const;
495 QString asWktPolygon()
const;
502 return QRectF(
static_cast< qreal
>( mXmin ),
static_cast< qreal
>( mYmin ),
static_cast< qreal
>( mXmax - mXmin ),
static_cast< qreal
>( mYmax - mYmin ) );
510 QString toString(
int precision = 16 )
const;
515 QString asPolygon()
const;
535 return ( !
operator==( r1 ) );
561 if ( std::isinf( mXmin ) || std::isinf( mYmin ) || std::isinf( mXmax ) || std::isinf( mYmax ) )
565 if ( std::isnan( mXmin ) || std::isnan( mYmin ) || std::isnan( mXmax ) || std::isnan( mYmax ) )
577 std::swap( mXmin, mYmin );
578 std::swap( mXmax, mYmax );
586 QgsBox3d toBox3d(
double zMin,
double zMax )
const;
589 operator QVariant()
const
591 return QVariant::fromValue( *
this );
603 SIP_PYOBJECT __repr__();
605 QString
str = QStringLiteral(
"<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
606 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
635 return os << r.
toString().toLocal8Bit().data();
640 #endif // QGSRECTANGLE_H
bool intersects(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle intersects with other rectangle.
double perimeter() const SIP_HOLDGIL
Returns the perimeter of the rectangle.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
double distance(const QgsPointXY &point) const
Returns the distance from point to the nearest point on the boundary of the rectangle.
void scale(double scaleFactor, double centerX, double centerY)
Scale the rectangle around its center point.
void include(const QgsPointXY &p)
Updates the rectangle to include the specified point.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
void invert()
Swap x/y coordinates in the rectangle.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
QgsRectangle(double xMin, double yMin=0, double xMax=0, double yMax=0, bool normalize=true) SIP_HOLDGIL
Constructs a QgsRectangle from a set of x and y minimum and maximum coordinates.
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
QgsRectangle(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true) SIP_HOLDGIL
Construct a rectangle from two points.
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
A rectangle specified with double values.
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.
QgsRectangle(const QgsRectangle &other) SIP_HOLDGIL
Copy constructor.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
void combineExtentWith(double x, double y)
Expands the rectangle so that it covers both the original rectangle and the given point.
double area() const SIP_HOLDGIL
Returns the area of the rectangle.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsRectangle(const QRectF &qRectF) SIP_HOLDGIL
Construct a rectangle from a QRectF.
bool contains(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle contains other rectangle.
bool operator==(const QgsRectangle &r1) const
Comparison operator.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
A class to represent a 2D point.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
bool operator!=(const QgsRectangle &r1) const
Comparison operator.
void combineExtentWith(const QgsPointXY &point)
Expands the rectangle so that it covers both the original rectangle and the given point.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
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
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QgsInterval operator-(const QDateTime &dt1, const QDateTime &dt2)
Returns the interval between two datetimes.
A class to represent a vector. Currently no Z axis / 2.5D support is implemented.
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QDateTime operator+(const QDateTime &start, const QgsInterval &interval)
Adds an interval to a datetime.
A 3-dimensional box composed of x, y, z coordinates.
bool contains(const QgsPointXY &p) const SIP_HOLDGIL
Returns true when rectangle contains a point.
void grow(double delta)
Grows the rectangle in place by the specified amount.
bool contains(double x, double y) const SIP_HOLDGIL
Returns true when rectangle contains the point at (x, y).
bool isEmpty() const
Returns true if the rectangle is empty.
QgsRectangle & operator=(const QgsRectangle &r1)
Assignment operator.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
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.