QGIS API Documentation  2.99.0-Master (dcec6bb)
Public Member Functions | List of all members
QgsRectangle Class Reference

A rectangle specified with double values. More...

#include <qgsrectangle.h>

Public Member Functions

 QgsRectangle (double xMin=0, double yMin=0, double xMax=0, double yMax=0)
 Constructor. More...
 
 QgsRectangle (const QgsPointXY &p1, const QgsPointXY &p2)
 Construct a rectangle from two points. The rectangle is normalized after construction. More...
 
 QgsRectangle (const QRectF &qRectF)
 Construct a rectangle from a QRectF. The rectangle is normalized after construction. More...
 
 QgsRectangle (const QgsRectangle &other)
 Copy constructor. More...
 
double area () const
 Returns the area of the rectangle. More...
 
QString asPolygon () const
 Returns the rectangle as a polygon. More...
 
QString asWktCoordinates () const
 Returns a string representation of the rectangle in WKT format. More...
 
QString asWktPolygon () const
 Returns a string representation of the rectangle as a WKT Polygon. More...
 
QgsRectangle buffer (double width)
 Get rectangle enlarged by buffer. More...
 
QgsPointXY center () const
 Returns the center point of the rectangle. More...
 
void combineExtentWith (const QgsRectangle &rect)
 Expand the rectangle so that covers both the original rectangle and the given rectangle. More...
 
void combineExtentWith (double x, double y)
 Expand the rectangle so that covers both the original rectangle and the given point. More...
 
bool contains (const QgsRectangle &rect) const
 Return true when rectangle contains other rectangle. More...
 
bool contains (const QgsPointXY &p) const
 Return true when rectangle contains a point. More...
 
void grow (double delta)
 Grows the rectangle by the specified amount. More...
 
double height () const
 Returns the height of the rectangle. More...
 
void include (const QgsPointXY &p)
 Updates the rectangle to include the specified point. More...
 
QgsRectangle intersect (const QgsRectangle *rect) const
 Return the intersection with the given rectangle. More...
 
bool intersects (const QgsRectangle &rect) const
 Returns true when rectangle intersects with other rectangle. More...
 
void invert ()
 Swap x/y coordinates in the rectangle. More...
 
bool isEmpty () const
 Returns true if the rectangle is empty. More...
 
bool isFinite () const
 Returns true if the rectangle has finite boundaries. More...
 
bool isNull () const
 Test if the rectangle is null (all coordinates zero or after call to setMinimal()). More...
 
void normalize ()
 Normalize the rectangle so it has non-negative width/height. More...
 
bool operator!= (const QgsRectangle &r1) const
 Comparison operator. More...
 
QgsRectangle operator+ (const QgsVector v) const
 Returns a rectangle offset from this one in the direction of the vector. More...
 
QgsRectangleoperator+= (const QgsVector v)
 Moves this rectangle in the direction of the vector. More...
 
QgsRectangle operator- (const QgsVector v) const
 Returns a rectangle offset from this one in the direction of the reversed vector. More...
 
QgsRectangleoperator-= (const QgsVector v)
 Moves this rectangle in the direction of the reversed vector. More...
 
QgsRectangleoperator= (const QgsRectangle &r1)
 Assignment operator. More...
 
bool operator== (const QgsRectangle &r1) const
 Comparison operator. More...
 
double perimeter () const
 Returns the perimeter of the rectangle. More...
 
void scale (double scaleFactor, const QgsPointXY *c=nullptr)
 Scale the rectangle around its center point. More...
 
void scale (double scaleFactor, double centerX, double centerY)
 Scale the rectangle around its center point. More...
 
void set (const QgsPointXY &p1, const QgsPointXY &p2)
 Sets the rectangle from two QgsPoints. More...
 
void set (double mXmin, double mYmin, double mXmax, double mYmax)
 Sets the rectangle from four points. More...
 
void setMinimal ()
 Set a rectangle so that min corner is at max and max corner is at min. More...
 
void setXMaximum (double x)
 Set the maximum x value. More...
 
void setXMinimum (double x)
 Set the minimum x value. More...
 
void setYMaximum (double y)
 Set the maximum y value. More...
 
void setYMinimum (double y)
 Set the minimum y value. More...
 
QgsBox3d toBox3d (double zMin, double zMax) const
 Converts the rectangle to a 3D box, with the specified zMin and zMax z values. More...
 
QRectF toRectF () const
 Returns a QRectF with same coordinates as the rectangle. More...
 
QString toString (int precision=16) const
 Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the specified precision. More...
 
double width () const
 Returns the width of the rectangle. More...
 
double xMaximum () const
 Returns the x maximum value (right side of rectangle). More...
 
double xMinimum () const
 Returns the x minimum value (left side of rectangle). More...
 
double yMaximum () const
 Returns the y maximum value (top side of rectangle). More...
 
double yMinimum () const
 Returns the y minimum value (bottom side of rectangle). More...
 

Detailed Description

A rectangle specified with double values.

QgsRectangle is used to store a rectangle when double values are required. Examples are storing a layer extent or the current view extent of a map

See also
QgsBox3d

Definition at line 38 of file qgsrectangle.h.

Constructor & Destructor Documentation

◆ QgsRectangle() [1/4]

QgsRectangle::QgsRectangle ( double  xMin = 0,
double  yMin = 0,
double  xMax = 0,
double  yMax = 0 
)

Constructor.

Definition at line 33 of file qgsrectangle.cpp.

◆ QgsRectangle() [2/4]

QgsRectangle::QgsRectangle ( const QgsPointXY p1,
const QgsPointXY p2 
)

Construct a rectangle from two points. The rectangle is normalized after construction.

Definition at line 42 of file qgsrectangle.cpp.

◆ QgsRectangle() [3/4]

QgsRectangle::QgsRectangle ( const QRectF &  qRectF)

Construct a rectangle from a QRectF. The rectangle is normalized after construction.

Definition at line 47 of file qgsrectangle.cpp.

◆ QgsRectangle() [4/4]

QgsRectangle::QgsRectangle ( const QgsRectangle other)

Copy constructor.

Definition at line 55 of file qgsrectangle.cpp.

Member Function Documentation

◆ area()

double QgsRectangle::area ( ) const
inline

Returns the area of the rectangle.

Since
QGIS 3.0
See also
width()
height()
perimeter()

Definition at line 134 of file qgsrectangle.h.

◆ asPolygon()

QString QgsRectangle::asPolygon ( ) const

Returns the rectangle as a polygon.

Definition at line 332 of file qgsrectangle.cpp.

◆ asWktCoordinates()

QString QgsRectangle::asWktCoordinates ( ) const

Returns a string representation of the rectangle in WKT format.

Definition at line 274 of file qgsrectangle.cpp.

◆ asWktPolygon()

QString QgsRectangle::asWktPolygon ( ) const

Returns a string representation of the rectangle as a WKT Polygon.

Definition at line 283 of file qgsrectangle.cpp.

◆ buffer()

QgsRectangle QgsRectangle::buffer ( double  width)

Get rectangle enlarged by buffer.

Since
QGIS 2.1

Definition at line 151 of file qgsrectangle.cpp.

◆ center()

QgsPointXY QgsRectangle::center ( ) const
inline

Returns the center point of the rectangle.

Definition at line 146 of file qgsrectangle.h.

◆ combineExtentWith() [1/2]

void QgsRectangle::combineExtentWith ( const QgsRectangle rect)

Expand the rectangle so that covers both the original rectangle and the given rectangle.

Definition at line 196 of file qgsrectangle.cpp.

◆ combineExtentWith() [2/2]

void QgsRectangle::combineExtentWith ( double  x,
double  y 
)

Expand the rectangle so that covers both the original rectangle and the given point.

Definition at line 211 of file qgsrectangle.cpp.

◆ contains() [1/2]

bool QgsRectangle::contains ( const QgsRectangle rect) const

Return true when rectangle contains other rectangle.

Definition at line 185 of file qgsrectangle.cpp.

◆ contains() [2/2]

bool QgsRectangle::contains ( const QgsPointXY p) const

Return true when rectangle contains a point.

Definition at line 190 of file qgsrectangle.cpp.

◆ grow()

void QgsRectangle::grow ( double  delta)

Grows the rectangle by the specified amount.

Definition at line 131 of file qgsrectangle.cpp.

◆ height()

double QgsRectangle::height ( ) const
inline

Returns the height of the rectangle.

See also
width()
area()

Definition at line 125 of file qgsrectangle.h.

◆ include()

void QgsRectangle::include ( const QgsPointXY p)

Updates the rectangle to include the specified point.

Definition at line 139 of file qgsrectangle.cpp.

◆ intersect()

QgsRectangle QgsRectangle::intersect ( const QgsRectangle rect) const

Return the intersection with the given rectangle.

Definition at line 156 of file qgsrectangle.cpp.

◆ intersects()

bool QgsRectangle::intersects ( const QgsRectangle rect) const

Returns true when rectangle intersects with other rectangle.

Definition at line 172 of file qgsrectangle.cpp.

◆ invert()

void QgsRectangle::invert ( )

Swap x/y coordinates in the rectangle.

Definition at line 394 of file qgsrectangle.cpp.

◆ isEmpty()

bool QgsRectangle::isEmpty ( ) const

Returns true if the rectangle is empty.

An empty rectangle may still be non-null if it contains valid information (e.g. bounding box of a point).

Definition at line 261 of file qgsrectangle.cpp.

◆ isFinite()

bool QgsRectangle::isFinite ( ) const

Returns true if the rectangle has finite boundaries.

Will return false if any of the rectangle boundaries are NaN or Inf.

Definition at line 381 of file qgsrectangle.cpp.

◆ isNull()

bool QgsRectangle::isNull ( ) const

Test if the rectangle is null (all coordinates zero or after call to setMinimal()).

A null rectangle is also an empty rectangle.

Since
QGIS 2.4

Definition at line 266 of file qgsrectangle.cpp.

◆ normalize()

void QgsRectangle::normalize ( )

Normalize the rectangle so it has non-negative width/height.

Definition at line 81 of file qgsrectangle.cpp.

◆ operator!=()

bool QgsRectangle::operator!= ( const QgsRectangle r1) const

Comparison operator.

Returns
False if rectangles are equal

Definition at line 363 of file qgsrectangle.cpp.

◆ operator+()

QgsRectangle QgsRectangle::operator+ ( const QgsVector  v) const

Returns a rectangle offset from this one in the direction of the vector.

Since
QGIS 3.0

Definition at line 234 of file qgsrectangle.cpp.

◆ operator+=()

QgsRectangle & QgsRectangle::operator+= ( const QgsVector  v)

Moves this rectangle in the direction of the vector.

Since
QGIS 3.0

Definition at line 252 of file qgsrectangle.cpp.

◆ operator-()

QgsRectangle QgsRectangle::operator- ( const QgsVector  v) const

Returns a rectangle offset from this one in the direction of the reversed vector.

Since
QGIS 3.0

Definition at line 225 of file qgsrectangle.cpp.

◆ operator-=()

QgsRectangle & QgsRectangle::operator-= ( const QgsVector  v)

Moves this rectangle in the direction of the reversed vector.

Since
QGIS 3.0

Definition at line 243 of file qgsrectangle.cpp.

◆ operator=()

QgsRectangle & QgsRectangle::operator= ( const QgsRectangle r1)

Assignment operator.

Parameters
r1QgsRectangle to assign from

Definition at line 368 of file qgsrectangle.cpp.

◆ operator==()

bool QgsRectangle::operator== ( const QgsRectangle r1) const

Comparison operator.

Returns
True if rectangles are equal

Definition at line 355 of file qgsrectangle.cpp.

◆ perimeter()

double QgsRectangle::perimeter ( ) const
inline

Returns the perimeter of the rectangle.

Since
QGIS 3.0
See also
area()

Definition at line 141 of file qgsrectangle.h.

◆ scale() [1/2]

void QgsRectangle::scale ( double  scaleFactor,
const QgsPointXY c = nullptr 
)

Scale the rectangle around its center point.

Definition at line 104 of file qgsrectangle.cpp.

◆ scale() [2/2]

void QgsRectangle::scale ( double  scaleFactor,
double  centerX,
double  centerY 
)

Scale the rectangle around its center point.

Definition at line 121 of file qgsrectangle.cpp.

◆ set() [1/2]

void QgsRectangle::set ( const QgsPointXY p1,
const QgsPointXY p2 
)

Sets the rectangle from two QgsPoints.

The rectangle is normalised after construction.

Definition at line 63 of file qgsrectangle.cpp.

◆ set() [2/2]

void QgsRectangle::set ( double  mXmin,
double  mYmin,
double  mXmax,
double  mYmax 
)

Sets the rectangle from four points.

The rectangle is normalised after construction.

Definition at line 72 of file qgsrectangle.cpp.

◆ setMinimal()

void QgsRectangle::setMinimal ( )

Set a rectangle so that min corner is at max and max corner is at min.

It is NOT normalized.

Definition at line 96 of file qgsrectangle.cpp.

◆ setXMaximum()

void QgsRectangle::setXMaximum ( double  x)
inline

Set the maximum x value.

Definition at line 70 of file qgsrectangle.h.

◆ setXMinimum()

void QgsRectangle::setXMinimum ( double  x)
inline

Set the minimum x value.

Definition at line 65 of file qgsrectangle.h.

◆ setYMaximum()

void QgsRectangle::setYMaximum ( double  y)
inline

Set the maximum y value.

Definition at line 80 of file qgsrectangle.h.

◆ setYMinimum()

void QgsRectangle::setYMinimum ( double  y)
inline

Set the minimum y value.

Definition at line 75 of file qgsrectangle.h.

◆ toBox3d()

QgsBox3d QgsRectangle::toBox3d ( double  zMin,
double  zMax 
) const

Converts the rectangle to a 3D box, with the specified zMin and zMax z values.

Since
QGIS 3.0

Definition at line 405 of file qgsrectangle.cpp.

◆ toRectF()

QRectF QgsRectangle::toRectF ( ) const

Returns a QRectF with same coordinates as the rectangle.

Definition at line 297 of file qgsrectangle.cpp.

◆ toString()

QString QgsRectangle::toString ( int  precision = 16) const

Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the specified precision.

If the specified precision is less than 0, a suitable minimum precision is used.

Definition at line 302 of file qgsrectangle.cpp.

◆ width()

double QgsRectangle::width ( ) const
inline

Returns the width of the rectangle.

See also
height()
area()

Definition at line 118 of file qgsrectangle.h.

◆ xMaximum()

double QgsRectangle::xMaximum ( ) const
inline

Returns the x maximum value (right side of rectangle).

Definition at line 91 of file qgsrectangle.h.

◆ xMinimum()

double QgsRectangle::xMinimum ( ) const
inline

Returns the x minimum value (left side of rectangle).

Definition at line 96 of file qgsrectangle.h.

◆ yMaximum()

double QgsRectangle::yMaximum ( ) const
inline

Returns the y maximum value (top side of rectangle).

Definition at line 101 of file qgsrectangle.h.

◆ yMinimum()

double QgsRectangle::yMinimum ( ) const
inline

Returns the y minimum value (bottom side of rectangle).

Definition at line 106 of file qgsrectangle.h.


The documentation for this class was generated from the following files: