25#include "moc_qgsrectangle.cpp"
43 if ( polygon->numInteriorRings() > 0 )
46 if (
const QgsLineString *exterior = qgsgeometry_cast< QgsLineString * >( polygon->exteriorRing() ) )
48 if ( exterior->numPoints() == 5
52 return QgsRectangle( exterior->xAt( 0 ), exterior->yAt( 0 ), exterior->xAt( 2 ), exterior->yAt( 2 ) );
61 const double xMax = xMin +
width;
63 const double yMax = yMin +
height;
76 const double xmin = mXmin - v.
x();
77 const double xmax = mXmax - v.
x();
78 const double ymin = mYmin - v.
y();
79 const double ymax = mYmax - v.
y();
85 const double xmin = mXmin + v.
x();
86 const double xmax = mXmax + v.
x();
87 const double ymin = mYmin + v.
y();
88 const double ymax = mYmax + v.
y();
123 return QStringLiteral(
"Polygon EMPTY" );
126 return QStringLiteral(
"Polygon ((%1 %2, %3 %2, %3 %4, %1 %4, %1 %2))" ).arg(
143 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
151 rep = QStringLiteral(
"Null" );
153 rep = QStringLiteral(
"%1,%2 : %3,%4" )
168 return QStringLiteral(
"EMPTY" );
173 QTextStream foo( &rep );
175 foo.setRealNumberPrecision( 8 );
176 foo.setRealNumberNotation( QTextStream::FixedNotation );
180 << mXmin <<
' ' << mYmin <<
", "
181 << mXmin <<
' ' << mYmax <<
", "
182 << mXmax <<
' ' << mYmax <<
", "
183 << mXmax <<
' ' << mYmin <<
", "
184 << mXmin <<
' ' << mYmin;
192 return QgsBox3D( mXmin, mYmin, zMin, mXmax, mYmax, zMax );
197 if (
isNull() )
return *
this;
200 auto gridifyValue = [](
double value,
double spacing ) ->
double
203 return std::round( value / spacing ) * spacing;
209 gridifyValue( mXmin, spacing ),
210 gridifyValue( mYmin, spacing ),
211 gridifyValue( mXmax, spacing ),
212 gridifyValue( mYmax, spacing )
224 double xmin, ymin, xmax, ymax;
225 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 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.
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.
A class to represent a 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)
#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.