Skip to content

Commit

Permalink
Optimise some trivial point/rectangle intersection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 19, 2019
1 parent f9f00d3 commit 19d0b11
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -1133,6 +1133,12 @@ bool QgsGeometry::intersects( const QgsRectangle &r ) const
if ( !boundingBoxIntersects( r ) )
return false;

// optimise trivial case for point intersections -- the bounding box test has already given us the answer
if ( QgsWkbTypes::flatType( d->geometry->wkbType() ) == QgsWkbTypes::Point )
{
return true;
}

QgsGeometry g = fromRect( r );
return intersects( g );
}
Expand All @@ -1156,6 +1162,13 @@ bool QgsGeometry::boundingBoxIntersects( const QgsRectangle &rectangle ) const
return false;
}

// optimise trivial case for point intersections
if ( QgsWkbTypes::flatType( d->geometry->wkbType() ) == QgsWkbTypes::Point )
{
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( d->geometry.get() );
return rectangle.contains( QgsPointXY( point->x(), point->y() ) );
}

return d->geometry->boundingBox().intersects( rectangle );
}

Expand Down

0 comments on commit 19d0b11

Please sign in to comment.