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@8651 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 17, 2008
1 parent 8b512ce commit b7b9f62
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 b7b9f62

Please sign in to comment.