@@ -275,6 +275,55 @@ namespace pal
275
275
return f->uid ;
276
276
}
277
277
278
+ LabelPosition::Quadrant FeaturePart::quadrantFromOffset () const
279
+ {
280
+ if ( f->quadOffsetX < 0 )
281
+ {
282
+ if ( f->quadOffsetY < 0 )
283
+ {
284
+ return LabelPosition::QuadrantAboveLeft;
285
+ }
286
+ else if ( f->quadOffsetY > 0 )
287
+ {
288
+ return LabelPosition::QuadrantBelowLeft;
289
+ }
290
+ else
291
+ {
292
+ return LabelPosition::QuadrantLeft;
293
+ }
294
+ }
295
+ else if ( f->quadOffsetX > 0 )
296
+ {
297
+ if ( f->quadOffsetY < 0 )
298
+ {
299
+ return LabelPosition::QuadrantAboveRight;
300
+ }
301
+ else if ( f->quadOffsetY > 0 )
302
+ {
303
+ return LabelPosition::QuadrantBelowRight;
304
+ }
305
+ else
306
+ {
307
+ return LabelPosition::QuadrantRight;
308
+ }
309
+ }
310
+ else
311
+ {
312
+ if ( f->quadOffsetY < 0 )
313
+ {
314
+ return LabelPosition::QuadrantAbove;
315
+ }
316
+ else if ( f->quadOffsetY > 0 )
317
+ {
318
+ return LabelPosition::QuadrantBelow;
319
+ }
320
+ else
321
+ {
322
+ return LabelPosition::QuadrantOver;
323
+ }
324
+ }
325
+ }
326
+
278
327
int FeaturePart::setPositionOverPoint ( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle )
279
328
{
280
329
Q_UNUSED ( scale );
@@ -322,6 +371,7 @@ namespace pal
322
371
delete lp;
323
372
}
324
373
374
+ LabelPosition::Quadrant quadrant = f->quadOffset ? quadrantFromOffset () : LabelPosition::QuadrantOver;
325
375
if ( f->quadOffset )
326
376
{
327
377
if ( f->quadOffsetX != 0 )
@@ -349,7 +399,7 @@ namespace pal
349
399
lx = x + xdiff;
350
400
ly = y + ydiff;
351
401
352
- ( *lPos )[0 ] = new LabelPosition ( id, lx, ly, label_x, label_y, angle, cost, this );
402
+ ( *lPos )[0 ] = new LabelPosition ( id, lx, ly, label_x, label_y, angle, cost, this , false , quadrant );
353
403
return nbp;
354
404
}
355
405
@@ -443,6 +493,8 @@ namespace pal
443
493
if ( alpha > a360 )
444
494
alpha -= a360;
445
495
496
+ LabelPosition::Quadrant quadrant = LabelPosition::QuadrantOver;
497
+
446
498
if ( alpha < gamma1 || alpha > a360 - gamma1 ) // on the right
447
499
{
448
500
lx += distlabel;
@@ -452,44 +504,53 @@ namespace pal
452
504
453
505
// ly += -yrm/2.0 + tan(alpha)*(distlabel + xrm/2);
454
506
ly += -yrm + yrm * iota / ( 2 * gamma1 );
507
+
508
+ quadrant = LabelPosition::QuadrantRight;
455
509
}
456
510
else if ( alpha < a90 - gamma2 ) // top-right
457
511
{
458
512
lx += distlabel * cos ( alpha );
459
513
ly += distlabel * sin ( alpha );
514
+ quadrant = LabelPosition::QuadrantAboveRight;
460
515
}
461
516
else if ( alpha < a90 + gamma2 ) // top
462
517
{
463
518
// lx += -xrm/2.0 - tan(alpha+a90)*(distlabel + yrm/2);
464
519
lx += -xrm * ( alpha - a90 + gamma2 ) / ( 2 * gamma2 );
465
520
ly += distlabel;
521
+ quadrant = LabelPosition::QuadrantAbove;
466
522
}
467
523
else if ( alpha < a180 - gamma1 ) // top left
468
524
{
469
525
lx += distlabel * cos ( alpha ) - xrm;
470
526
ly += distlabel * sin ( alpha );
527
+ quadrant = LabelPosition::QuadrantAboveLeft;
471
528
}
472
529
else if ( alpha < a180 + gamma1 ) // left
473
530
{
474
531
lx += -distlabel - xrm;
475
532
// ly += -yrm/2.0 - tan(alpha)*(distlabel + xrm/2);
476
533
ly += - ( alpha - a180 + gamma1 ) * yrm / ( 2 * gamma1 );
534
+ quadrant = LabelPosition::QuadrantLeft;
477
535
}
478
536
else if ( alpha < a270 - gamma2 ) // down - left
479
537
{
480
538
lx += distlabel * cos ( alpha ) - xrm;
481
539
ly += distlabel * sin ( alpha ) - yrm;
540
+ quadrant = LabelPosition::QuadrantBelowLeft;
482
541
}
483
542
else if ( alpha < a270 + gamma2 ) // down
484
543
{
485
544
ly += -distlabel - yrm;
486
545
// lx += -xrm/2.0 + tan(alpha+a90)*(distlabel + yrm/2);
487
546
lx += -xrm + ( alpha - a270 + gamma2 ) * xrm / ( 2 * gamma2 );
547
+ quadrant = LabelPosition::QuadrantBelow;
488
548
}
489
- else if ( alpha < a360 )
549
+ else if ( alpha < a360 ) // down - right
490
550
{
491
551
lx += distlabel * cos ( alpha );
492
552
ly += distlabel * sin ( alpha ) - yrm;
553
+ quadrant = LabelPosition::QuadrantBelowRight;
493
554
}
494
555
495
556
double cost;
@@ -499,7 +560,7 @@ namespace pal
499
560
else
500
561
cost = 0.0001 + 0.0020 * double ( icost ) / double ( nbp - 1 );
501
562
502
- ( *lPos )[i] = new LabelPosition ( i, lx, ly, xrm, yrm, angle, cost, this );
563
+ ( *lPos )[i] = new LabelPosition ( i, lx, ly, xrm, yrm, angle, cost, this , false , quadrant );
503
564
504
565
icost += inc;
505
566
0 commit comments