Added QgsRect::intersects(QgsRect) predicate

git-svn-id: http://svn.osgeo.org/qgis/trunk@8651 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2008-06-17 00:15:08 +00:00
parent 8b512cea39
commit b7b9f62e70
3 changed files with 15 additions and 0 deletions

View File

@ -59,6 +59,8 @@ class QgsRect
void expand(double, const QgsPoint *c = 0);
//! return the intersection with the given rectangle
QgsRect intersect(QgsRect *rect);
//! returns true when rectangle intersects with other rectangle
bool intersects(const QgsRect& rect) const;
//! expand the rectangle so that covers both the original rectangle and the given rectangle
void combineExtentWith(QgsRect *rect);
//! expand the rectangle so that covers both the original rectangle and the given point

View File

@ -138,6 +138,17 @@ QgsRect QgsRect::intersect(QgsRect * rect) const
return intersection;
}
bool QgsRect::intersects(const QgsRect& rect) const
{
double x1 = (xmin > rect.xmin ? xmin : rect.xmin);
double x2 = (xmax < rect.xmax ? xmax : rect.xmax);
if (x1 > x2) return FALSE;
double y1 = (ymin > rect.ymin ? ymin : rect.ymin);
double y2 = (ymax < rect.ymax ? ymax : rect.ymax);
if (y1 > y2) return FALSE;
return TRUE;
}
void QgsRect::combineExtentWith(QgsRect * rect)
{

View File

@ -82,6 +82,8 @@ class CORE_EXPORT QgsRect
void expand(double, const QgsPoint *c = 0);
//! return the intersection with the given rectangle
QgsRect intersect(QgsRect *rect) const;
//! returns true when rectangle intersects with other rectangle
bool intersects(const QgsRect& rect) const;
//! expand the rectangle so that covers both the original rectangle and the given rectangle
void combineExtentWith(QgsRect *rect);
//! expand the rectangle so that covers both the original rectangle and the given point