35#include "moc_qgsrectangle.cpp"
37using namespace Qt::StringLiterals;
47 if ( polygon->numInteriorRings() > 0 )
53 return QgsRectangle( exterior->xAt( 0 ), exterior->yAt( 0 ), exterior->xAt( 2 ), exterior->yAt( 2 ) );
62 const double xMax = xMin +
width;
64 const double yMax = yMin +
height;
77 const double xmin = mXmin - v.
x();
78 const double xmax = mXmax - v.
x();
79 const double ymin = mYmin - v.
y();
80 const double ymax = mYmax - v.
y();
86 const double xmin = mXmin + v.
x();
87 const double xmax = mXmax + v.
x();
88 const double ymin = mYmin + v.
y();
89 const double ymax = mYmax + v.
y();
122 return u
"Polygon EMPTY"_s;
137 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
139 if ( precision > 20 )
147 rep = u
"%1,%2 : %3,%4"_s.arg( mXmin, 0,
'f', precision ).arg( mYmin, 0,
'f', precision ).arg( mXmax, 0,
'f', precision ).arg( mYmax, 0,
'f', precision );
163 QTextStream foo( &rep );
165 foo.setRealNumberPrecision( 8 );
166 foo.setRealNumberNotation( QTextStream::FixedNotation );
169 foo << mXmin <<
' ' << mYmin <<
", " << mXmin <<
' ' << mYmax <<
", " << mXmax <<
' ' << mYmax <<
", " << mXmax <<
' ' << mYmin <<
", " << mXmin <<
' ' << mYmin;
176 return QgsBox3D( mXmin, mYmin, zMin, mXmax, mYmax, zMax );
185 auto gridifyValue = [](
double value,
double spacing ) ->
double {
187 return std::round( value / spacing ) * spacing;
192 return QgsRectangle( gridifyValue( mXmin, spacing ), gridifyValue( mYmin, spacing ), gridifyValue( mXmax, spacing ), gridifyValue( mYmax, spacing ) );
203 double xmin, ymin, xmax, ymax;
204 in >> xmin >> ymin >> xmax >> ymax;
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
A 3-dimensional box composed of x, y, z coordinates.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Line string geometry type, with support for z-dimension and m-values.
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.
QgsRectangle & operator+=(QgsVector v)
Moves this rectangle in the direction of the vector.
QgsRectangle()=default
Constructor for a null rectangle.
static QgsRectangle fromWkt(const QString &wkt)
Creates a new rectangle from a wkt string.
void setYMinimum(double y)
Set the minimum y value.
QgsRectangle & operator-=(QgsVector v)
Moves this rectangle in the direction of the reversed vector.
void setXMinimum(double x)
Set the minimum x value.
Q_INVOKABLE QString asWktPolygon() const
Returns a string representation of the rectangle as a WKT Polygon.
Q_INVOKABLE QString asWktCoordinates() const
Returns a string representation of the rectangle in WKT format.
QgsRectangle operator-(QgsVector v) const
Returns a rectangle offset from this one in the direction of the reversed vector.
QgsRectangle scaled(double scaleFactor, const QgsPointXY *center=nullptr) const
Scale the rectangle around its center point.
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
static QgsRectangle fromCenterAndSize(const QgsPointXY ¢er, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
QString asPolygon() const
Returns the rectangle as a polygon.
QgsRectangle snappedToGrid(double spacing) const
Returns a copy of this rectangle that is snapped to a grid with the specified spacing between the gri...
QgsRectangle operator+(QgsVector v) const
Returns a rectangle offset from this one in the direction of the vector.
QgsBox3D toBox3d(double zMin, double zMax) const
Converts the rectangle to a 3D box, with the specified zMin and zMax z values.
Represent a 2-dimensional vector.
double y() const
Returns the vector's y-component.
double x() const
Returns the vector's x-component.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
#define QgsDebugMsgLevel(str, level)
QDataStream & operator>>(QDataStream &in, QgsRectangle &rectangle)
Reads a rectangle from stream in into rectangle.
QDataStream & operator<<(QDataStream &out, const QgsRectangle &rectangle)
Writes the list rectangle to stream out.