Skip to content
Permalink
Browse files

Changed my insanely expensive conflict check for multipart labels wit…

…h something actually usable.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11308 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Aug 9, 2009
1 parent 17052b5 commit 83339495424702950600c3bc33b5f3720d87f98f
Showing with 36 additions and 19 deletions.
  1. +33 −19 src/core/pal/labelposition.cpp
  2. +3 −0 src/core/pal/labelposition.h
@@ -149,29 +149,35 @@ namespace pal

bool LabelPosition::isInConflict( LabelPosition *lp )
{
int i, i2, j;
int d1, d2;

if ( this->probFeat == lp->probFeat ) // bugfix #1
return false; // always overlaping itself !

double cp1, cp2;
if (nextPart == NULL && lp->nextPart == NULL)
return isInConflictSinglePart(lp);
else
return isInConflictMultiPart(lp);
}

bool LabelPosition::isInConflictSinglePart( LabelPosition* lp )
{
// TODO: add bounding box test to possibly avoid cross product calculation

int i, i2, j;
int d1, d2;
double cp1, cp2;

//std::cout << "Check intersect" << std::endl;
for ( i = 0;i < 4;i++ )
{
i2 = ( i + 1 ) % 4;
d1 = -1;
d2 = -1;
//std::cout << "new seg..." << std::endl;

for ( j = 0;j < 4;j++ )
{
cp1 = cross_product( x[i], y[i], x[i2], y[i2], lp->x[j], lp->y[j] );
if ( cp1 > 0 )
{
d1 = 1;
//std::cout << " cp1: " << cp1 << std::endl;
}
cp2 = cross_product( lp->x[i], lp->y[i],
lp->x[i2], lp->y[i2],
@@ -180,25 +186,33 @@ namespace pal
if ( cp2 > 0 )
{
d2 = 1;
//std::cout << " cp2 " << cp2 << std::endl;
}
}

if ( d1 == -1 || d2 == -1 ) // disjoint
{
if ( lp->getNextPart() )
{
if ( isInConflict(lp->getNextPart()) )
return true;
}
return false;
}
return true;
}

if (nextPart)
return nextPart->isInConflict( lp );
else
return false;
bool LabelPosition::isInConflictMultiPart( LabelPosition* lp )
{
// check all parts against all parts of other one
LabelPosition* tmp1 = this;
while (tmp1)
{
// check tmp1 against parts of other label
LabelPosition* tmp2 = lp;
while (tmp2)
{
if (tmp1->isInConflictSinglePart(tmp2))
return true;
tmp2 = tmp2->nextPart;
}

tmp1 = tmp1->nextPart;
}
return true;
return false; // no conflict found
}

int LabelPosition::getId() const
@@ -74,6 +74,9 @@ namespace pal
LabelPosition* nextPart;
int partId;

bool isInConflictSinglePart( LabelPosition* lp );
bool isInConflictMultiPart( LabelPosition* lp );

public:
/**
* \brief create a new LabelPosition

0 comments on commit 8333949

Please sign in to comment.
You can’t perform that action at this time.