@@ -51,6 +51,18 @@ static QList<QgsFeature> _pointFeatures()
5151 return feats;
5252}
5353
54+ bool testContains ( const QList<QgsSpatialIndexKDBushData> &data, QgsFeatureId id, const QgsPointXY &point )
55+ {
56+ for ( const QgsSpatialIndexKDBushData &d : data )
57+ {
58+ if ( d.id == id )
59+ {
60+ return d.point () == point;
61+ }
62+ }
63+ return false ;
64+ }
65+
5466class TestQgsSpatialIndexKdBush : public QObject
5567{
5668 Q_OBJECT
@@ -75,42 +87,30 @@ class TestQgsSpatialIndexKdBush : public QObject
7587 QgsSpatialIndexKDBush index ( *vl->dataProvider () );
7688 QCOMPARE ( index.size (), 4 );
7789
78- QSet<QgsFeatureId > fids = index.intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
90+ QList<QgsSpatialIndexKDBushData > fids = index.intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
7991 QVERIFY ( fids.count () == 1 );
80- QVERIFY ( fids. contains ( 1 ) );
92+ QVERIFY ( testContains ( fids, 1 , QgsPointXY ( 1 , 1 ) ) );
8193
82- QSet<QgsFeatureId > fids2 = index.intersect ( QgsRectangle ( -10 , -10 , 0 , 10 ) );
94+ QList<QgsSpatialIndexKDBushData > fids2 = index.intersect ( QgsRectangle ( -10 , -10 , 0 , 10 ) );
8395 QCOMPARE ( fids2.count (), 2 );
84- QVERIFY ( fids2. contains ( 2 ) );
85- QVERIFY ( fids2. contains ( 3 ) );
96+ QVERIFY ( testContains ( fids2, 2 , QgsPointXY ( - 1 , 1 ) ) );
97+ QVERIFY ( testContains ( fids2, 3 , QgsPointXY ( - 1 , - 1 ) ) );
8698
87- QSet<QgsFeatureId > fids3 = index.within ( QgsPointXY ( 0 , 0 ), 2 );
99+ QList<QgsSpatialIndexKDBushData > fids3 = index.within ( QgsPointXY ( 0 , 0 ), 2 );
88100 QCOMPARE ( fids3.count (), 4 );
89- QVERIFY ( fids3. contains ( 1 ) );
90- QVERIFY ( fids3. contains ( 2 ) );
91- QVERIFY ( fids3. contains ( 3 ) );
92- QVERIFY ( fids3. contains ( 4 ) );
101+ QVERIFY ( testContains ( fids3, 1 , QgsPointXY ( 1 , 1 ) ) );
102+ QVERIFY ( testContains ( fids3, 2 , QgsPointXY ( - 1 , 1 ) ) );
103+ QVERIFY ( testContains ( fids3, 3 , QgsPointXY ( - 1 , - 1 ) ) );
104+ QVERIFY ( testContains ( fids3, 4 , QgsPointXY ( 1 , - 1 ) ) );
93105
94- QSet<QgsFeatureId > fids4 = index.within ( QgsPointXY ( 0 , 0 ), 1 );
106+ QList<QgsSpatialIndexKDBushData > fids4 = index.within ( QgsPointXY ( 0 , 0 ), 1 );
95107 QCOMPARE ( fids4.count (), 0 );
96108
97- QSet<QgsFeatureId > fids5 = index.within ( QgsPointXY ( -1 , -1 ), 2.1 );
109+ QList<QgsSpatialIndexKDBushData > fids5 = index.within ( QgsPointXY ( -1 , -1 ), 2.1 );
98110 QCOMPARE ( fids5.count (), 3 );
99- QVERIFY ( fids5.contains ( 2 ) );
100- QVERIFY ( fids5.contains ( 3 ) );
101- QVERIFY ( fids5.contains ( 4 ) );
102-
103- QgsPointXY p;
104- QVERIFY ( !index.point ( -1 , p ) );
105- QVERIFY ( !index.point ( 5 , p ) );
106- QVERIFY ( index.point ( 1 , p ) );
107- QCOMPARE ( p, QgsPointXY ( 1 , 1 ) );
108- QVERIFY ( index.point ( 2 , p ) );
109- QCOMPARE ( p, QgsPointXY ( -1 , 1 ) );
110- QVERIFY ( index.point ( 3 , p ) );
111- QCOMPARE ( p, QgsPointXY ( -1 , -1 ) );
112- QVERIFY ( index.point ( 4 , p ) );
113- QCOMPARE ( p, QgsPointXY ( 1 , -1 ) );
111+ QVERIFY ( testContains ( fids5, 2 , QgsPointXY ( -1 , 1 ) ) );
112+ QVERIFY ( testContains ( fids5, 3 , QgsPointXY ( -1 , -1 ) ) );
113+ QVERIFY ( testContains ( fids5, 4 , QgsPointXY ( 1 , -1 ) ) );
114114 }
115115
116116 void testCopy ()
@@ -128,9 +128,9 @@ class TestQgsSpatialIndexKdBush : public QObject
128128 QVERIFY ( index->d ->ref == 2 );
129129
130130 // test that copied index works
131- QSet<QgsFeatureId > fids = indexCopy->intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
131+ QList<QgsSpatialIndexKDBushData > fids = indexCopy->intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
132132 QVERIFY ( fids.count () == 1 );
133- QVERIFY ( fids. contains ( 1 ) );
133+ QVERIFY ( testContains ( fids, 1 , QgsPointXY ( 1 , 1 ) ) );
134134
135135 // check that the index is still shared
136136 QVERIFY ( index->d == indexCopy->d );
@@ -141,7 +141,7 @@ class TestQgsSpatialIndexKdBush : public QObject
141141 // test that copied index still works
142142 fids = indexCopy->intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
143143 QVERIFY ( fids.count () == 1 );
144- QVERIFY ( fids. contains ( 1 ) );
144+ QVERIFY ( testContains ( fids, 1 , QgsPointXY ( 1 , 1 ) ) );
145145 QVERIFY ( indexCopy->d ->ref == 1 );
146146
147147 // assignment operator
@@ -157,7 +157,7 @@ class TestQgsSpatialIndexKdBush : public QObject
157157 QVERIFY ( index3.d ->ref == 2 );
158158 fids = index3.intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
159159 QVERIFY ( fids.count () == 1 );
160- QVERIFY ( fids. contains ( 1 ) );
160+ QVERIFY ( testContains ( fids, 1 , QgsPointXY ( 1 , 1 ) ) );
161161
162162 indexCopy.reset ();
163163 QVERIFY ( index3.d ->ref == 1 );
0 commit comments