Skip to content
Permalink
Browse files

Add QgsRectangle::contains overload which doesn't require QgsPoint/Qg…

…sPointXY objects
  • Loading branch information
nyalldawson committed Mar 11, 2021
1 parent 7fb3c83 commit 5445aceafff4cebcf5c8787f54f6492dc4fbfbf6
@@ -234,19 +234,26 @@ Gets rectangle enlarged by buffer.
Returns the intersection with the given rectangle.
%End

bool intersects( const QgsRectangle &rect ) const;
bool intersects( const QgsRectangle &rect ) const /HoldGIL/;
%Docstring
Returns ``True`` when rectangle intersects with other rectangle.
%End

bool contains( const QgsRectangle &rect ) const;
bool contains( const QgsRectangle &rect ) const /HoldGIL/;
%Docstring
Returns ``True`` when rectangle contains other rectangle.
%End

bool contains( const QgsPointXY &p ) const;
bool contains( const QgsPointXY &p ) const /HoldGIL/;
%Docstring
Returns ``True`` when rectangle contains a point.
%End

bool contains( double x, double y ) const /HoldGIL/;
%Docstring
Returns ``True`` when rectangle contains the point at (``x``, ``y``).

.. versionadded:: 3.20
%End

void combineExtentWith( const QgsRectangle &rect );
@@ -109,7 +109,7 @@ bool QgsBox3d::contains( const QgsBox3d &other ) const

bool QgsBox3d::contains( const QgsPoint &p ) const
{
if ( !mBounds2d.contains( QgsPointXY( p.x(), p.y() ) ) )
if ( !mBounds2d.contains( p.x(), p.y() ) )
return false;

if ( p.is3D() )
@@ -346,7 +346,7 @@ class CORE_EXPORT QgsRectangle
/**
* Returns TRUE when rectangle intersects with other rectangle.
*/
bool intersects( const QgsRectangle &rect ) const
bool intersects( const QgsRectangle &rect ) const SIP_HOLDGIL
{
double x1 = ( mXmin > rect.mXmin ? mXmin : rect.mXmin );
double x2 = ( mXmax < rect.mXmax ? mXmax : rect.mXmax );
@@ -360,20 +360,31 @@ class CORE_EXPORT QgsRectangle
/**
* Returns TRUE when rectangle contains other rectangle.
*/
bool contains( const QgsRectangle &rect ) const
bool contains( const QgsRectangle &rect ) const SIP_HOLDGIL
{
return ( rect.mXmin >= mXmin && rect.mXmax <= mXmax && rect.mYmin >= mYmin && rect.mYmax <= mYmax );
}

/**
* Returns TRUE when rectangle contains a point.
*/
bool contains( const QgsPointXY &p ) const
bool contains( const QgsPointXY &p ) const SIP_HOLDGIL
{
return mXmin <= p.x() && p.x() <= mXmax &&
mYmin <= p.y() && p.y() <= mYmax;
}

/**
* Returns TRUE when rectangle contains the point at (\a x, \a y).
*
* \since QGIS 3.20
*/
bool contains( double x, double y ) const SIP_HOLDGIL
{
return mXmin <= x && x <= mXmax &&
mYmin <= y && y <= mYmax;
}

/**
* Expands the rectangle so that it covers both the original rectangle and the given rectangle.
*/
@@ -95,7 +95,7 @@ void QgsPointCloudAttributeByRampRenderer::renderBlock( const QgsPointCloudBlock
}

pointXY( context, ptr, i, x, y );
if ( visibleExtent.contains( QgsPointXY( x, y ) ) )
if ( visibleExtent.contains( x, y ) )
{
if ( reproject )
{
@@ -113,7 +113,7 @@ void QgsPointCloudClassifiedRenderer::renderBlock( const QgsPointCloudBlock *blo
continue;

pointXY( context, ptr, i, x, y );
if ( visibleExtent.contains( QgsPointXY( x, y ) ) )
if ( visibleExtent.contains( x, y ) )
{
if ( reproject )
{
@@ -110,7 +110,7 @@ void QgsPointCloudRgbRenderer::renderBlock( const QgsPointCloudBlock *block, Qgs
}

pointXY( context, ptr, i, x, y );
if ( visibleExtent.contains( QgsPointXY( x, y ) ) )
if ( visibleExtent.contains( x, y ) )
{
if ( reproject )
{
@@ -429,7 +429,7 @@ bool QgsGeometryValidator::intersectLines( double px, double py, QgsVector v, do

bool QgsGeometryValidator::pointInRing( const QgsLineString *ring, double pX, double pY )
{
if ( !ring->boundingBox().contains( QgsPointXY( pX, pY ) ) )
if ( !ring->boundingBox().contains( pX, pY ) )
return false;

bool inside = false;
@@ -498,7 +498,7 @@ bool ProjectorData::preciseSrcRowCol( int destRow, int destCol, int *srcRow, int
QgsDebugMsgLevel( QStringLiteral( "x = %1 y = %2" ).arg( x ).arg( y ), 5 );
#endif

if ( !mExtent.contains( QgsPointXY( x, y ) ) )
if ( !mExtent.contains( x, y ) )
{
return false;
}
@@ -558,7 +558,7 @@ bool ProjectorData::approximateSrcRowCol( int destRow, int destCol, int *srcRow,
double mySrcX = bx + ( tx - bx ) * yfrac;
double mySrcY = by + ( ty - by ) * yfrac;

if ( !mExtent.contains( QgsPointXY( mySrcX, mySrcY ) ) )
if ( !mExtent.contains( mySrcX, mySrcY ) )
{
return false;
}
@@ -199,7 +199,7 @@ bool QgsGPXFeatureIterator::readWaypoint( const QgsWaypoint &wpt, QgsFeature &fe
{
if ( !mFilterRect.isNull() )
{
if ( ! mFilterRect.contains( QgsPointXY( wpt.lon, wpt.lat ) ) )
if ( ! mFilterRect.contains( wpt.lon, wpt.lat ) )
return false;
}

0 comments on commit 5445ace

Please sign in to comment.