QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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...
 
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 setXMinimum (double x)
 Set the minimum x value. More...
 
void setXMaximum (double x)
 Set the maximum x value. More...
 
void setYMinimum (double y)
 Set the minimum y value. More...
 
void setYMaximum (double y)
 Set the maximum y value. More...
 
void setMinimal ()
 Set a rectangle so that min corner is at max and max corner is at min. 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...
 
void normalize ()
 Normalize the rectangle so it has non-negative width/height. More...
 
double width () const
 Width of the rectangle. More...
 
double height () const
 Height of the rectangle. More...
 
QgsPoint center () const
 Center point of the rectangle. More...
 
void scale (double scaleFactor, const QgsPoint *c=0)
 Scale the rectangle around its center point. More...
 
void scale (double scaleFactor, double centerX, double centerY)
 
QgsRectangle buffer (double width)
 Get rectangle enlarged by buffer. 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...
 
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 combineExtentWith (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 isEmpty () const
 test if rectangle is empty. More...
 
bool isNull () const
 test if the rectangle is null (all coordinates zero or after call to setMinimal()). More...
 
QString asWktCoordinates () const
 returns string representation in Wkt form More...
 
QString asWktPolygon () const
 returns string representation as WKT Polygon 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...
 
QString asPolygon () const
 returns rectangle as a polygon More...
 
bool operator== (const QgsRectangle &r1) const
 
bool operator!= (const QgsRectangle &r1) const
 
QgsRectangleoperator= (const QgsRectangle &r1)
 
void unionRect (const QgsRectangle &rect)
 updates rectangle to include passed argument More...
 
bool isFinite () const
 Returns true if the rectangle has finite boundaries. More...
 
void invert ()
 swap x/y More...
 

Protected Attributes

double xmin
 
double ymin
 
double xmax
 
double ymax
 

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

Constructor & Destructor Documentation

QgsRectangle::QgsRectangle ( double  xmin = 0,
double  ymin = 0,
double  xmax = 0,
double  ymax = 0 
)

Constructor.

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

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

QgsRectangle::QgsRectangle ( const QRectF &  qRectF)

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

QgsRectangle::QgsRectangle ( const QgsRectangle other)

Copy constructor.

QgsRectangle::~QgsRectangle ( )
inline

Destructor.

Member Function Documentation

QString QgsRectangle::asPolygon ( ) const

returns rectangle as a polygon

QString QgsRectangle::asWktCoordinates ( ) const

returns string representation in Wkt form

QString QgsRectangle::asWktPolygon ( ) const

returns string representation as WKT Polygon

QgsRectangle QgsRectangle::buffer ( double  width)

Get rectangle enlarged by buffer.

Note
added in 2.1
QgsPoint QgsRectangle::center ( ) const
inline

Center point of the rectangle.

void QgsRectangle::combineExtentWith ( QgsRectangle rect)

expand the rectangle so that covers both the original rectangle and the given rectangle

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

expand the rectangle so that covers both the original rectangle and the given point

bool QgsRectangle::contains ( const QgsRectangle rect) const

return true when rectangle contains other rectangle

bool QgsRectangle::contains ( const QgsPoint p) const

return true when rectangle contains a point

double QgsRectangle::height ( ) const
inline

Height of the rectangle.

QgsRectangle QgsRectangle::intersect ( const QgsRectangle rect) const

return the intersection with the given rectangle

bool QgsRectangle::intersects ( const QgsRectangle rect) const

returns true when rectangle intersects with other rectangle

void QgsRectangle::invert ( )

swap x/y

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)

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.

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
void QgsRectangle::normalize ( )

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

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

Comparison operator

Returns
False if rectangles are equal
QgsRectangle & QgsRectangle::operator= ( const QgsRectangle r1)

Assignment operator

Parameters
r1QgsRectangle to assign from
bool QgsRectangle::operator== ( const QgsRectangle r1) const

Comparison operator

Returns
True if rectangles are equal
void QgsRectangle::scale ( double  scaleFactor,
const QgsPoint c = 0 
)

Scale the rectangle around its center point.

void QgsRectangle::scale ( double  scaleFactor,
double  centerX,
double  centerY 
)
void QgsRectangle::set ( const QgsPoint p1,
const QgsPoint p2 
)

Set the rectangle from two QgsPoints.

The rectangle is normalised after construction.

void QgsRectangle::set ( double  xmin,
double  ymin,
double  xmax,
double  ymax 
)

Set the rectangle from four points.

The rectangle is normalised after construction.

void QgsRectangle::setMinimal ( )

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

It is NOT normalized.

void QgsRectangle::setXMaximum ( double  x)
inline

Set the maximum x value.

void QgsRectangle::setXMinimum ( double  x)
inline

Set the minimum x value.

void QgsRectangle::setYMaximum ( double  y)
inline

Set the maximum y value.

void QgsRectangle::setYMinimum ( double  y)
inline

Set the minimum y value.

QRectF QgsRectangle::toRectF ( ) const

returns a QRectF with same coordinates.

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

returns string representation of form xmin,ymin xmax,ymax

QString QgsRectangle::toString ( int  thePrecision) const

overloaded toString that allows precision of numbers to be set

void QgsRectangle::unionRect ( const QgsRectangle rect)

updates rectangle to include passed argument

double QgsRectangle::width ( ) const
inline

Width of the rectangle.

double QgsRectangle::xMaximum ( ) const
inline

Get the x maximum value (right side of rectangle)

double QgsRectangle::xMinimum ( ) const
inline

Get the x minimum value (left side of rectangle)

double QgsRectangle::yMaximum ( ) const
inline

Get the y maximum value (top side of rectangle)

double QgsRectangle::yMinimum ( ) const
inline

Get the y minimum value (bottom side of rectangle)

Member Data Documentation

double QgsRectangle::xmax
protected
double QgsRectangle::xmin
protected
double QgsRectangle::ymax
protected
double QgsRectangle::ymin
protected

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