msTestLabelCacheCollisions() ** ** Compares current label against labels already drawn and markers from cache and discards it ** by setting cachePtr->status=MS_FALSE if it is a duplicate, collides with another label, ** or collides with a marker. ** ** This function is used by the various msDrawLabelCacheXX() implementations. */
| 477 | ** This function is used by the various msDrawLabelCacheXX() implementations. |
| 478 | */ |
| 479 | void msTestLabelCacheCollisions(labelCacheObj *labelcache, labelObj *labelPtr, |
| 480 | int mapwidth, int mapheight, int buffer, |
| 481 | labelCacheMemberObj *cachePtr, int current_priority, |
| 482 | int current_label, int mindistance, double label_size) |
| 483 | { |
| 484 | int i, p; |
| 485 | |
| 486 | /* Check against image bounds first |
| 487 | ** Pass mapwidth=-1 to skip this test |
| 488 | */ |
| 489 | if(!labelPtr->partials && mapwidth > 0 && mapheight > 0) { |
| 490 | if(labelInImage(mapwidth, mapheight, cachePtr->poly, buffer) == MS_FALSE) { |
| 491 | cachePtr->status = MS_FALSE; |
| 492 | return; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | /* Compare against all rendered markers from this priority level and higher. |
| 497 | ** Labels can overlap their own marker and markers from lower priority levels |
| 498 | */ |
| 499 | for (p=current_priority; p < MS_MAX_LABEL_PRIORITY; p++) { |
| 500 | labelCacheSlotObj *markerslot; |
| 501 | markerslot = &(labelcache->slots[p]); |
| 502 | |
| 503 | for ( i = 0; i < markerslot->nummarkers; i++ ) { |
| 504 | if ( !(p == current_priority && current_label == markerslot->markers[i].id) ) { /* labels can overlap their own marker */ |
| 505 | if ( intersectLabelPolygons(markerslot->markers[i].poly, cachePtr->poly ) == MS_TRUE ) { |
| 506 | cachePtr->status = MS_FALSE; /* polys intersect */ |
| 507 | return; |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | /* compare against rendered labels */ |
| 514 | i = current_label+1; |
| 515 | |
| 516 | for(p=current_priority; p<MS_MAX_LABEL_PRIORITY; p++) { |
| 517 | labelCacheSlotObj *cacheslot; |
| 518 | cacheslot = &(labelcache->slots[p]); |
| 519 | |
| 520 | for( ; i < cacheslot->numlabels; i++) { |
| 521 | if(cacheslot->labels[i].status == MS_TRUE) { /* compare bounding polygons and check for duplicates */ |
| 522 | /* We add the label_size to the mindistance value when comparing because we do want the mindistance |
| 523 | value between the labels and not only from point to point. */ |
| 524 | if(label_size > 0 && (mindistance != -1) && |
| 525 | (cachePtr->layerindex == cacheslot->labels[i].layerindex) && (cachePtr->classindex == cacheslot->labels[i].classindex) && |
| 526 | (strcmp(cachePtr->text,cacheslot->labels[i].text) == 0) && |
| 527 | (msDistancePointToPoint(&(cachePtr->point), &(cacheslot->labels[i].point)) <= (mindistance + label_size))) { /* label is a duplicate */ |
| 528 | cachePtr->status = MS_FALSE; |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | if(intersectLabelPolygons(cacheslot->labels[i].poly, cachePtr->poly) == MS_TRUE) { /* polys intersect */ |
| 533 | cachePtr->status = MS_FALSE; |
| 534 | return; |
| 535 | } |
| 536 | } |
no test coverage detected