@@ -286,68 +286,80 @@ namespace pal
286
286
}
287
287
288
288
// if multiple labels are requested for lines, split the line in pieces of desired distance
289
- if (repeatDistance > 0 ) {
289
+ if ( repeatDistance > 0 )
290
+ {
290
291
int nSimpleGeometries = simpleGeometries->size ();
291
- for (int i = 0 ; i < nSimpleGeometries; ++i) {
292
+ for ( int i = 0 ; i < nSimpleGeometries; ++i )
293
+ {
292
294
const GEOSGeometry* geom = simpleGeometries->pop_front ();
293
- if (GEOSGeomTypeId (geom) == GEOS_LINESTRING) {
295
+ if ( GEOSGeomTypeId ( geom ) == GEOS_LINESTRING )
296
+ {
297
+ const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq ( geom );
294
298
295
299
// get number of points
296
- int n = GEOSGeomGetNumPoints (geom);
300
+ unsigned int n;
301
+ GEOSCoordSeq_getSize ( cs, &n );
297
302
298
303
// Read points
299
- std::vector<Point > points (n);
300
- for (int i = 0 ; i < n; ++i) {
301
- GEOSGeometry* p = GEOSGeomGetPointN (geom, i);
302
- GEOSGeomGetX (p, &points[i].x );
303
- GEOSGeomGetY (p, &points[i].y );
304
- GEOSGeom_destroy (p);
304
+ std::vector<Point > points ( n );
305
+ for ( unsigned int i = 0 ; i < n; ++i )
306
+ {
307
+ GEOSCoordSeq_getX ( cs, i, &points[i].x );
308
+ GEOSCoordSeq_getY ( cs, i, &points[i].y );
305
309
}
306
310
307
311
// Cumulative length vector
308
- std::vector<double > len (n, 0 );
309
- for (int i = 1 ; i < n; ++i) {
312
+ std::vector<double > len ( n, 0 );
313
+ for ( unsigned int i = 1 ; i < n; ++i )
314
+ {
310
315
double dx = points[i].x - points[i - 1 ].x ;
311
316
double dy = points[i].y - points[i - 1 ].y ;
312
- len[i] = len[i - 1 ] + std::sqrt (dx * dx + dy * dy);
317
+ len[i] = len[i - 1 ] + std::sqrt ( dx * dx + dy * dy );
313
318
}
314
319
315
320
// Walk along line
316
- int cur = 0 ;
321
+ unsigned int cur = 0 ;
317
322
double lambda = 0 ;
318
323
std::vector<Point > part;
319
- while (true ) {
324
+ for ( ;; )
325
+ {
320
326
lambda += repeatDistance;
321
- for (; cur < n && lambda > len[cur]; ++cur) {
322
- part.push_back (points[cur]);
327
+ for ( ; cur < n && lambda > len[cur]; ++cur )
328
+ {
329
+ part.push_back ( points[cur] );
323
330
}
324
- if (cur >= n) {
331
+ if ( cur >= n )
332
+ {
325
333
break ;
326
334
}
327
- double c = (lambda - len[cur - 1 ]) / (len[cur] - len[cur - 1 ]);
335
+ double c = ( lambda - len[cur - 1 ] ) / ( len[cur] - len[cur - 1 ] );
328
336
Point p;
329
- p.x = points[cur - 1 ].x + c * (points[cur].x - points[cur - 1 ].x );
330
- p.y = points[cur - 1 ].y + c * (points[cur].y - points[cur - 1 ].y );
331
- part.push_back (p);
332
- GEOSCoordSequence* cooSeq = GEOSCoordSeq_create (part.size (), 2 );
333
- for (std::size_t i = 0 ; i < part.size (); ++i) {
334
- GEOSCoordSeq_setX (cooSeq, i, part[i].x );
335
- GEOSCoordSeq_setY (cooSeq, i, part[i].y );
337
+ p.x = points[cur - 1 ].x + c * ( points[cur].x - points[cur - 1 ].x );
338
+ p.y = points[cur - 1 ].y + c * ( points[cur].y - points[cur - 1 ].y );
339
+ part.push_back ( p );
340
+ GEOSCoordSequence* cooSeq = GEOSCoordSeq_create ( part.size (), 2 );
341
+ for ( std::size_t i = 0 ; i < part.size (); ++i )
342
+ {
343
+ GEOSCoordSeq_setX ( cooSeq, i, part[i].x );
344
+ GEOSCoordSeq_setY ( cooSeq, i, part[i].y );
336
345
}
337
346
338
- simpleGeometries->push_back (GEOSGeom_createLineString (cooSeq) );
347
+ simpleGeometries->push_back ( GEOSGeom_createLineString ( cooSeq ) );
339
348
part.clear ();
340
- part.push_back (p );
349
+ part.push_back ( p );
341
350
}
342
351
// Create final part
343
- part.push_back (points[n - 1 ]);
344
- GEOSCoordSequence* cooSeq = GEOSCoordSeq_create (part.size (), 2 );
345
- for (std::size_t i = 0 ; i < part.size (); ++i) {
346
- GEOSCoordSeq_setX (cooSeq, i, part[i].x );
347
- GEOSCoordSeq_setY (cooSeq, i, part[i].y );
352
+ part.push_back ( points[n - 1 ] );
353
+ GEOSCoordSequence* cooSeq = GEOSCoordSeq_create ( part.size (), 2 );
354
+ for ( std::size_t i = 0 ; i < part.size (); ++i )
355
+ {
356
+ GEOSCoordSeq_setX ( cooSeq, i, part[i].x );
357
+ GEOSCoordSeq_setY ( cooSeq, i, part[i].y );
348
358
}
349
- simpleGeometries->push_back (GEOSGeom_createLineString (cooSeq));
350
- }else {
359
+ simpleGeometries->push_back ( GEOSGeom_createLineString ( cooSeq ) );
360
+ }
361
+ else
362
+ {
351
363
simpleGeometries->push_back ( geom );
352
364
}
353
365
}
@@ -418,7 +430,7 @@ namespace pal
418
430
modMutex->unlock ();
419
431
420
432
// if using only biggest parts...
421
- if (( ( mode == LabelPerFeature && repeatDistance == 0.0 ) || f->fixedPosition () ) && biggest_part != NULL )
433
+ if ((( mode == LabelPerFeature && repeatDistance == 0.0 ) || f->fixedPosition () ) && biggest_part != NULL )
422
434
{
423
435
addFeaturePart ( biggest_part, labelText );
424
436
first_feat = false ;
0 commit comments