@@ -83,6 +83,22 @@ template <typename RandIter, typename Type, typename CompareOp > RandIter my_bin
83
83
return not_found;
84
84
}
85
85
86
+ struct TiePointInfo
87
+ {
88
+ QgsPoint mTiedPoint ;
89
+ double mLength ;
90
+ QgsPoint mFirstPoint ;
91
+ QgsPoint mLastPoint ;
92
+ };
93
+
94
+ bool TiePointInfoCompare ( const TiePointInfo& a, const TiePointInfo& b )
95
+ {
96
+ if ( a.mFirstPoint == b.mFirstPoint )
97
+ return a.mLastPoint .x () == b.mLastPoint .x () ? a.mLastPoint .y () < b.mLastPoint .y () : a.mLastPoint .x () < b.mLastPoint .x ();
98
+
99
+ return a.mFirstPoint .x () == b.mFirstPoint .x () ? a.mFirstPoint .y () < b.mFirstPoint .y () : a.mFirstPoint .x () < b.mFirstPoint .x ();
100
+ }
101
+
86
102
QgsLineVectorLayerDirector::QgsLineVectorLayerDirector ( QgsVectorLayer *myLayer,
87
103
int directionFieldId,
88
104
const QString& directDirectionValue,
@@ -208,19 +224,22 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
208
224
points.push_back ( tiedPoint [ i ] );
209
225
}
210
226
}
211
-
227
+
212
228
QgsPointCompare pointCompare ( builder->topologyTolerance () );
213
229
214
230
qSort ( points.begin (), points.end (), pointCompare );
215
231
QVector< QgsPoint >::iterator tmp = std::unique ( points.begin (), points.end () );
216
232
points.resize ( tmp - points.begin () );
217
-
233
+
234
+
218
235
for (i=0 ;i<points.size ();++i)
219
236
builder->addVertex ( i, points[ i ] );
220
237
221
238
for ( i = 0 ; i < tiedPoint.size () ; ++i)
222
239
tiedPoint[ i ] = *(my_binary_search ( points.begin (), points.end (), tiedPoint[ i ], pointCompare ) );
223
240
241
+ qSort ( pointLengthMap.begin (), pointLengthMap.end (), TiePointInfoCompare );
242
+
224
243
{ // fill attribute list 'la'
225
244
QgsAttributeList tmpAttr;
226
245
if ( mDirectionFieldId != -1 )
@@ -254,7 +273,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
254
273
lastAttrId = *it2;
255
274
}
256
275
} // end fill attribute list 'la'
257
-
276
+
258
277
// begin graph construction
259
278
vl->select ( la );
260
279
while ( vl->nextFeature ( feature ) )
@@ -307,13 +326,28 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
307
326
std::map< double , QgsPoint > pointsOnArc;
308
327
pointsOnArc[ 0.0 ] = pt1;
309
328
pointsOnArc[ pt1.sqrDist ( pt2 )] = pt2;
310
-
311
- for ( pointLengthIt = pointLengthMap.begin (); pointLengthIt != pointLengthMap.end (); ++pointLengthIt )
329
+
330
+ TiePointInfo t;
331
+ t.mFirstPoint = pt1;
332
+ t.mLastPoint = pt2;
333
+ pointLengthIt = my_binary_search ( pointLengthMap.begin (), pointLengthMap.end (), t, TiePointInfoCompare );
334
+
335
+ if ( pointLengthIt != pointLengthMap.end () )
312
336
{
313
- if ( pointLengthIt->mFirstPoint == pt1 && pointLengthIt->mLastPoint == pt2 )
337
+ QVector< TiePointInfo >::iterator it;
338
+ for ( it = pointLengthIt; it - pointLengthMap.begin () > 0 ; --it )
314
339
{
315
- QgsPoint tiedPoint = pointLengthIt->mTiedPoint ;
316
- pointsOnArc[ pt1.sqrDist ( tiedPoint )] = tiedPoint;
340
+ if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
341
+ {
342
+ pointsOnArc[ pt1.sqrDist ( it->mTiedPoint ) ] = it->mTiedPoint ;
343
+ }
344
+ }
345
+ for ( it = pointLengthIt+1 ; it != pointLengthMap.end (); ++it )
346
+ {
347
+ if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
348
+ {
349
+ pointsOnArc[ pt2.sqrDist ( it->mTiedPoint ) ] = it->mTiedPoint ;
350
+ }
317
351
}
318
352
}
319
353
0 commit comments