QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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.
 QgsRectangle (const QgsPoint &p1, const QgsPoint &p2)
 Construct a rectangle from two points. The rectangle is normalized after construction.
 QgsRectangle (const QRectF &qRectF)
 Construct a rectangle from a QRectF. The rectangle is normalized after construction.
 QgsRectangle (const QgsRectangle &other)
 Copy constructor.
 ~QgsRectangle ()
 Destructor.
void set (const QgsPoint &p1, const QgsPoint &p2)
 Set the rectangle from two QgsPoints.
void set (double xmin, double ymin, double xmax, double ymax)
 Set the rectangle from four points.
void setXMinimum (double x)
 Set the minimum x value.
void setXMaximum (double x)
 Set the maximum x value.
void setYMinimum (double y)
 Set the minimum y value.
void setYMaximum (double y)
 Set the maximum y value.
void setMinimal ()
 Set a rectangle so that min corner is at max and max corner is at min.
double xMaximum () const
 Get the x maximum value (right side of rectangle)
double xMinimum () const
 Get the x minimum value (left side of rectangle)
double yMaximum () const
 Get the y maximum value (top side of rectangle)
double yMinimum () const
 Get the y minimum value (bottom side of rectangle)
void normalize ()
 Normalize the rectangle so it has non-negative width/height.
double width () const
 Width of the rectangle.
double height () const
 Height of the rectangle.
QgsPoint center () const
 Center point of the rectangle.
void scale (double scaleFactor, const QgsPoint *c=0)
 Scale the rectangle around its center point.
void scale (double scaleFactor, double centerX, double centerY)
QgsRectangle buffer (double width)
 Get rectangle enlarged by buffer.
QgsRectangle intersect (const QgsRectangle *rect) const
 return the intersection with the given rectangle
bool intersects (const QgsRectangle &rect) const
 returns true when rectangle intersects with other rectangle
bool contains (const QgsRectangle &rect) const
 return true when rectangle contains other rectangle
bool contains (const QgsPoint &p) const
 return true when rectangle contains a point
void combineExtentWith (QgsRectangle *rect)
 expand the rectangle so that covers both the original rectangle and the given rectangle
void combineExtentWith (double x, double y)
 expand the rectangle so that covers both the original rectangle and the given point
bool isEmpty () const
 test if rectangle is empty.
bool isNull () const
 test if the rectangle is null (all coordinates zero or after call to setMinimal()).
QString asWktCoordinates () const
 returns string representation in Wkt form
QString asWktPolygon () const
 returns string representation as WKT Polygon
QRectF toRectF () const
 returns a QRectF with same coordinates.
QString toString (bool automaticPrecision=false) const
 returns string representation of form xmin,ymin xmax,ymax
QString toString (int thePrecision) const
 overloaded toString that allows precision of numbers to be set
QString asPolygon () const
 returns rectangle as a polygon
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
bool isFinite () const
 Returns true if the rectangle has finite boundaries.
void invert ()
 swap x/y

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: