QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Public Member Functions | Protected Attributes | 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 QgsPoint &p1, const QgsPoint &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...
 
 ~QgsRectangle ()
 Destructor. More...
 
QString asPolygon () const
 returns rectangle as a polygon More...
 
QString asWktCoordinates () const
 returns string representation in Wkt form More...
 
QString asWktPolygon () const
 returns string representation as WKT Polygon More...
 
QgsRectangle buffer (double width)
 Get rectangle enlarged by buffer. More...
 
QgsPoint center () const
 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 QgsPoint &p) const
 return true when rectangle contains a point More...
 
void grow (double delta)
 Grow the rectangle by the specified amount. More...
 
double height () const
 Height of the rectangle. More...
 
void include (const QgsPoint &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 More...
 
bool isEmpty () const
 test if 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...
 
QgsRectangleoperator= (const QgsRectangle &r1)
 Assignment operator. More...
 
bool operator== (const QgsRectangle &r1) const
 Comparison operator. More...
 
void scale (double scaleFactor, const QgsPoint *c=nullptr)
 Scale the rectangle around its center point. More...
 
void scale (double scaleFactor, double centerX, double centerY)
 
void set (const QgsPoint &p1, const QgsPoint &p2)
 Set the rectangle from two QgsPoints. More...
 
void set (double xmin, double ymin, double xmax, double ymax)
 Set 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...
 
QRectF toRectF () const
 returns a QRectF with same coordinates. More...
 
QString toString (bool automaticPrecision=false) const
 returns string representation of form xmin,ymin xmax,ymax More...
 
QString toString (int thePrecision) const
 overloaded toString that allows precision of numbers to be set More...
 
void unionRect (const QgsRectangle &rect)
 Updates rectangle to include passed argument. More...
 
double width () const
 Width of the rectangle. More...
 
double xMaximum () const
 Get the x maximum value (right side of rectangle) More...
 
double xMinimum () const
 Get the x minimum value (left side of rectangle) More...
 
double yMaximum () const
 Get the y maximum value (top side of rectangle) More...
 
double yMinimum () const
 Get the y minimum value (bottom side of rectangle) More...
 

Protected Attributes

double xmax
 
double xmin
 
double ymax
 
double ymin
 

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

Definition at line 35 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 32 of file qgsrectangle.cpp.

◆ QgsRectangle() [2/4]

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

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

Definition at line 41 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 46 of file qgsrectangle.cpp.

◆ QgsRectangle() [4/4]

QgsRectangle::QgsRectangle ( const QgsRectangle other)

Copy constructor.

Definition at line 54 of file qgsrectangle.cpp.

◆ ~QgsRectangle()

QgsRectangle::~QgsRectangle ( )
inline

Destructor.

Definition at line 163 of file qgsrectangle.h.

Member Function Documentation

◆ asPolygon()

QString QgsRectangle::asPolygon ( ) const

returns rectangle as a polygon

Definition at line 301 of file qgsrectangle.cpp.

◆ asWktCoordinates()

QString QgsRectangle::asWktCoordinates ( ) const

returns string representation in Wkt form

Definition at line 232 of file qgsrectangle.cpp.

◆ asWktPolygon()

QString QgsRectangle::asWktPolygon ( ) const

returns string representation as WKT Polygon

Definition at line 241 of file qgsrectangle.cpp.

◆ buffer()

QgsRectangle QgsRectangle::buffer ( double  width)

Get rectangle enlarged by buffer.

Note
added in 2.1

Definition at line 152 of file qgsrectangle.cpp.

◆ center()

QgsPoint QgsRectangle::center ( ) const
inline

Center point of the rectangle.

Definition at line 217 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 197 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 208 of file qgsrectangle.cpp.

◆ contains() [1/2]

bool QgsRectangle::contains ( const QgsRectangle rect) const

return true when rectangle contains other rectangle

Definition at line 186 of file qgsrectangle.cpp.

◆ contains() [2/2]

bool QgsRectangle::contains ( const QgsPoint p) const

return true when rectangle contains a point

Definition at line 191 of file qgsrectangle.cpp.

◆ grow()

void QgsRectangle::grow ( double  delta)

Grow the rectangle by the specified amount.

Definition at line 132 of file qgsrectangle.cpp.

◆ height()

double QgsRectangle::height ( ) const
inline

Height of the rectangle.

Definition at line 212 of file qgsrectangle.h.

◆ include()

void QgsRectangle::include ( const QgsPoint p)

Updates the rectangle to include the specified point.

Definition at line 140 of file qgsrectangle.cpp.

◆ intersect()

QgsRectangle QgsRectangle::intersect ( const QgsRectangle rect) const

return the intersection with the given rectangle

Definition at line 157 of file qgsrectangle.cpp.

◆ intersects()

bool QgsRectangle::intersects ( const QgsRectangle rect) const

returns true when rectangle intersects with other rectangle

Definition at line 173 of file qgsrectangle.cpp.

◆ invert()

void QgsRectangle::invert ( )

swap x/y

Definition at line 379 of file qgsrectangle.cpp.

◆ isEmpty()

bool QgsRectangle::isEmpty ( ) const

test if rectangle is empty.

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

Definition at line 219 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 366 of file qgsrectangle.cpp.

◆ isNull()

bool QgsRectangle::isNull ( ) const

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

Null rectangle is also an empty rectangle.

Note
added in 2.4

Definition at line 224 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 334 of file qgsrectangle.cpp.

◆ operator=()

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

Assignment operator.

Parameters
r1QgsRectangle to assign from

Definition at line 340 of file qgsrectangle.cpp.

◆ operator==()

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

Comparison operator.

Returns
True if rectangles are equal

Definition at line 325 of file qgsrectangle.cpp.

◆ scale() [1/2]

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

Scale the rectangle around its center point.

Definition at line 105 of file qgsrectangle.cpp.

◆ scale() [2/2]

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

Definition at line 122 of file qgsrectangle.cpp.

◆ set() [1/2]

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

Set 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  xmin,
double  ymin,
double  xmax,
double  ymax 
)

Set 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 97 of file qgsrectangle.cpp.

◆ setXMaximum()

void QgsRectangle::setXMaximum ( double  x)
inline

Set the maximum x value.

Definition at line 172 of file qgsrectangle.h.

◆ setXMinimum()

void QgsRectangle::setXMinimum ( double  x)
inline

Set the minimum x value.

Definition at line 167 of file qgsrectangle.h.

◆ setYMaximum()

void QgsRectangle::setYMaximum ( double  y)
inline

Set the maximum y value.

Definition at line 182 of file qgsrectangle.h.

◆ setYMinimum()

void QgsRectangle::setYMinimum ( double  y)
inline

Set the minimum y value.

Definition at line 177 of file qgsrectangle.h.

◆ toRectF()

QRectF QgsRectangle::toRectF ( ) const

returns a QRectF with same coordinates.

Definition at line 256 of file qgsrectangle.cpp.

◆ toString() [1/2]

QString QgsRectangle::toString ( bool  automaticPrecision = false) const

returns string representation of form xmin,ymin xmax,ymax

Definition at line 262 of file qgsrectangle.cpp.

◆ toString() [2/2]

QString QgsRectangle::toString ( int  thePrecision) const

overloaded toString that allows precision of numbers to be set

Definition at line 282 of file qgsrectangle.cpp.

◆ unionRect()

void QgsRectangle::unionRect ( const QgsRectangle rect)

Updates rectangle to include passed argument.

Definition at line 354 of file qgsrectangle.cpp.

◆ width()

double QgsRectangle::width ( ) const
inline

Width of the rectangle.

Definition at line 207 of file qgsrectangle.h.

◆ xMaximum()

double QgsRectangle::xMaximum ( ) const
inline

Get the x maximum value (right side of rectangle)

Definition at line 187 of file qgsrectangle.h.

◆ xMinimum()

double QgsRectangle::xMinimum ( ) const
inline

Get the x minimum value (left side of rectangle)

Definition at line 192 of file qgsrectangle.h.

◆ yMaximum()

double QgsRectangle::yMaximum ( ) const
inline

Get the y maximum value (top side of rectangle)

Definition at line 197 of file qgsrectangle.h.

◆ yMinimum()

double QgsRectangle::yMinimum ( ) const
inline

Get the y minimum value (bottom side of rectangle)

Definition at line 202 of file qgsrectangle.h.

Member Data Documentation

◆ xmax

double QgsRectangle::xmax
protected

Definition at line 153 of file qgsrectangle.h.

◆ xmin

double QgsRectangle::xmin
protected

Definition at line 151 of file qgsrectangle.h.

◆ ymax

double QgsRectangle::ymax
protected

Definition at line 154 of file qgsrectangle.h.

◆ ymin

double QgsRectangle::ymin
protected

Definition at line 152 of file qgsrectangle.h.


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