@@ -51,6 +51,18 @@ static QList<QgsFeature> _pointFeatures()
51
51
return feats;
52
52
}
53
53
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
+
54
66
class TestQgsSpatialIndexKdBush : public QObject
55
67
{
56
68
Q_OBJECT
@@ -75,42 +87,30 @@ class TestQgsSpatialIndexKdBush : public QObject
75
87
QgsSpatialIndexKDBush index ( *vl->dataProvider () );
76
88
QCOMPARE ( index.size (), 4 );
77
89
78
- QSet<QgsFeatureId > fids = index.intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
90
+ QList<QgsSpatialIndexKDBushData > fids = index.intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
79
91
QVERIFY ( fids.count () == 1 );
80
- QVERIFY ( fids. contains ( 1 ) );
92
+ QVERIFY ( testContains ( fids, 1 , QgsPointXY ( 1 , 1 ) ) );
81
93
82
- QSet<QgsFeatureId > fids2 = index.intersect ( QgsRectangle ( -10 , -10 , 0 , 10 ) );
94
+ QList<QgsSpatialIndexKDBushData > fids2 = index.intersect ( QgsRectangle ( -10 , -10 , 0 , 10 ) );
83
95
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 ) ) );
86
98
87
- QSet<QgsFeatureId > fids3 = index.within ( QgsPointXY ( 0 , 0 ), 2 );
99
+ QList<QgsSpatialIndexKDBushData > fids3 = index.within ( QgsPointXY ( 0 , 0 ), 2 );
88
100
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 ) ) );
93
105
94
- QSet<QgsFeatureId > fids4 = index.within ( QgsPointXY ( 0 , 0 ), 1 );
106
+ QList<QgsSpatialIndexKDBushData > fids4 = index.within ( QgsPointXY ( 0 , 0 ), 1 );
95
107
QCOMPARE ( fids4.count (), 0 );
96
108
97
- QSet<QgsFeatureId > fids5 = index.within ( QgsPointXY ( -1 , -1 ), 2.1 );
109
+ QList<QgsSpatialIndexKDBushData > fids5 = index.within ( QgsPointXY ( -1 , -1 ), 2.1 );
98
110
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 ) ) );
114
114
}
115
115
116
116
void testCopy ()
@@ -128,9 +128,9 @@ class TestQgsSpatialIndexKdBush : public QObject
128
128
QVERIFY ( index->d ->ref == 2 );
129
129
130
130
// 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 ) );
132
132
QVERIFY ( fids.count () == 1 );
133
- QVERIFY ( fids. contains ( 1 ) );
133
+ QVERIFY ( testContains ( fids, 1 , QgsPointXY ( 1 , 1 ) ) );
134
134
135
135
// check that the index is still shared
136
136
QVERIFY ( index->d == indexCopy->d );
@@ -141,7 +141,7 @@ class TestQgsSpatialIndexKdBush : public QObject
141
141
// test that copied index still works
142
142
fids = indexCopy->intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
143
143
QVERIFY ( fids.count () == 1 );
144
- QVERIFY ( fids. contains ( 1 ) );
144
+ QVERIFY ( testContains ( fids, 1 , QgsPointXY ( 1 , 1 ) ) );
145
145
QVERIFY ( indexCopy->d ->ref == 1 );
146
146
147
147
// assignment operator
@@ -157,7 +157,7 @@ class TestQgsSpatialIndexKdBush : public QObject
157
157
QVERIFY ( index3.d ->ref == 2 );
158
158
fids = index3.intersect ( QgsRectangle ( 0 , 0 , 10 , 10 ) );
159
159
QVERIFY ( fids.count () == 1 );
160
- QVERIFY ( fids. contains ( 1 ) );
160
+ QVERIFY ( testContains ( fids, 1 , QgsPointXY ( 1 , 1 ) ) );
161
161
162
162
indexCopy.reset ();
163
163
QVERIFY ( index3.d ->ref == 1 );
0 commit comments