Skip to content

Commit ef4bad2

Browse files
author
wonder
committedJun 17, 2008
Added QgsRect::intersects(QgsRect) predicate
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8651 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5984374 commit ef4bad2

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
 

‎python/core/qgsrect.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class QgsRect
5959
void expand(double, const QgsPoint *c = 0);
6060
//! return the intersection with the given rectangle
6161
QgsRect intersect(QgsRect *rect);
62+
//! returns true when rectangle intersects with other rectangle
63+
bool intersects(const QgsRect& rect) const;
6264
//! expand the rectangle so that covers both the original rectangle and the given rectangle
6365
void combineExtentWith(QgsRect *rect);
6466
//! expand the rectangle so that covers both the original rectangle and the given point

‎src/core/qgsrect.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ QgsRect QgsRect::intersect(QgsRect * rect) const
138138
return intersection;
139139
}
140140

141+
bool QgsRect::intersects(const QgsRect& rect) const
142+
{
143+
double x1 = (xmin > rect.xmin ? xmin : rect.xmin);
144+
double x2 = (xmax < rect.xmax ? xmax : rect.xmax);
145+
if (x1 > x2) return FALSE;
146+
double y1 = (ymin > rect.ymin ? ymin : rect.ymin);
147+
double y2 = (ymax < rect.ymax ? ymax : rect.ymax);
148+
if (y1 > y2) return FALSE;
149+
return TRUE;
150+
}
151+
141152

142153
void QgsRect::combineExtentWith(QgsRect * rect)
143154
{

‎src/core/qgsrect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class CORE_EXPORT QgsRect
8282
void expand(double, const QgsPoint *c = 0);
8383
//! return the intersection with the given rectangle
8484
QgsRect intersect(QgsRect *rect) const;
85+
//! returns true when rectangle intersects with other rectangle
86+
bool intersects(const QgsRect& rect) const;
8587
//! expand the rectangle so that covers both the original rectangle and the given rectangle
8688
void combineExtentWith(QgsRect *rect);
8789
//! expand the rectangle so that covers both the original rectangle and the given point

0 commit comments

Comments
 (0)
Please sign in to comment.