Skip to content
Permalink
Browse files

Rename intersect to intersects for consistency with QgsSpatialIndex

  • Loading branch information
nyalldawson committed Jul 7, 2018
1 parent 38251cb commit 05368e4a893b4122767a6d6a43ebdb4dcbae4f78
@@ -66,7 +66,7 @@ Copy constructor

~QgsSpatialIndexKDBush();

QList<QgsSpatialIndexKDBushData> intersect( const QgsRectangle &rectangle ) const;
QList<QgsSpatialIndexKDBushData> intersects( const QgsRectangle &rectangle ) const;
%Docstring
Returns the list of features which fall within the specified ``rectangle``.
%End
@@ -73,7 +73,7 @@ qgssize QgsSpatialIndexKDBush::size() const
return d->index->size();
}

QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::intersect( const QgsRectangle &rectangle ) const
QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle ) const
{
QList<QgsSpatialIndexKDBushData> result;
d->index->range( rectangle.xMinimum(),
@@ -83,7 +83,7 @@ QList<QgsSpatialIndexKDBushData> QgsSpatialIndexKDBush::intersect( const QgsRect
return result;
}

void QgsSpatialIndexKDBush::intersect( const QgsRectangle &rectangle, const std::function<void( QgsSpatialIndexKDBushData )> &visitor ) const
void QgsSpatialIndexKDBush::intersects( const QgsRectangle &rectangle, const std::function<void( QgsSpatialIndexKDBushData )> &visitor ) const
{
d->index->range( rectangle.xMinimum(),
rectangle.yMinimum(),
@@ -87,14 +87,14 @@ class CORE_EXPORT QgsSpatialIndexKDBush
/**
* Returns the list of features which fall within the specified \a rectangle.
*/
QList<QgsSpatialIndexKDBushData> intersect( const QgsRectangle &rectangle ) const;
QList<QgsSpatialIndexKDBushData> intersects( const QgsRectangle &rectangle ) const;

/**
* Calls a \a visitor function for all features which fall within the specified \a rectangle.
*
* \note Not available in Python bindings
*/
void intersect( const QgsRectangle &rectangle, const std::function<void( QgsSpatialIndexKDBushData )> &visitor ) const SIP_SKIP;
void intersects( const QgsRectangle &rectangle, const std::function<void( QgsSpatialIndexKDBushData )> &visitor ) const SIP_SKIP;

/**
* Returns the list of features which are within the given search \a radius
@@ -87,11 +87,11 @@ class TestQgsSpatialIndexKdBush : public QObject
QgsSpatialIndexKDBush index( *vl->dataProvider() );
QVERIFY( index.size() == 4 );

QList<QgsSpatialIndexKDBushData> fids = index.intersect( QgsRectangle( 0, 0, 10, 10 ) );
QList<QgsSpatialIndexKDBushData> fids = index.intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 1 );
QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) );

QList<QgsSpatialIndexKDBushData> fids2 = index.intersect( QgsRectangle( -10, -10, 0, 10 ) );
QList<QgsSpatialIndexKDBushData> fids2 = index.intersects( QgsRectangle( -10, -10, 0, 10 ) );
QCOMPARE( fids2.count(), 2 );
QVERIFY( testContains( fids2, 2, QgsPointXY( -1, 1 ) ) );
QVERIFY( testContains( fids2, 3, QgsPointXY( -1, -1 ) ) );
@@ -128,7 +128,7 @@ class TestQgsSpatialIndexKdBush : public QObject
QVERIFY( index->d->ref == 2 );

// test that copied index works
QList<QgsSpatialIndexKDBushData> fids = indexCopy->intersect( QgsRectangle( 0, 0, 10, 10 ) );
QList<QgsSpatialIndexKDBushData> fids = indexCopy->intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 1 );
QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) );

@@ -139,7 +139,7 @@ class TestQgsSpatialIndexKdBush : public QObject
index.reset();

// test that copied index still works
fids = indexCopy->intersect( QgsRectangle( 0, 0, 10, 10 ) );
fids = indexCopy->intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 1 );
QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) );
QVERIFY( indexCopy->d->ref == 1 );
@@ -148,14 +148,14 @@ class TestQgsSpatialIndexKdBush : public QObject
std::unique_ptr< QgsVectorLayer > vl2 = qgis::make_unique< QgsVectorLayer >( "Point", QString(), QStringLiteral( "memory" ) );
QgsSpatialIndexKDBush index3( *vl2->dataProvider() );
QVERIFY( index3.size() == 0 );
fids = index3.intersect( QgsRectangle( 0, 0, 10, 10 ) );
fids = index3.intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 0 );
QVERIFY( index3.d->ref == 1 );

index3 = *indexCopy;
QVERIFY( index3.d == indexCopy->d );
QVERIFY( index3.d->ref == 2 );
fids = index3.intersect( QgsRectangle( 0, 0, 10, 10 ) );
fids = index3.intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 1 );
QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) );

0 comments on commit 05368e4

Please sign in to comment.
You can’t perform that action at this time.