Skip to content

Commit

Permalink
Added QgsRect::intersects(QgsRect) predicate
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8651 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 17, 2008
1 parent 5984374 commit ef4bad2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/core/qgsrect.sip
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsrect.cpp
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsrect.h
Expand Up @@ -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
Expand Down

0 comments on commit ef4bad2

Please sign in to comment.