Skip to content

Commit 8333949

Browse files
author
wonder
committed
Changed my insanely expensive conflict check for multipart labels with something actually usable.
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11308 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 17052b5 commit 8333949

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/core/pal/labelposition.cpp

+33-19
Original file line numberDiff line numberDiff line change
@@ -149,29 +149,35 @@ namespace pal
149149

150150
bool LabelPosition::isInConflict( LabelPosition *lp )
151151
{
152-
int i, i2, j;
153-
int d1, d2;
154-
155152
if ( this->probFeat == lp->probFeat ) // bugfix #1
156153
return false; // always overlaping itself !
157154

158-
double cp1, cp2;
155+
if (nextPart == NULL && lp->nextPart == NULL)
156+
return isInConflictSinglePart(lp);
157+
else
158+
return isInConflictMultiPart(lp);
159+
}
159160

161+
bool LabelPosition::isInConflictSinglePart( LabelPosition* lp )
162+
{
163+
// TODO: add bounding box test to possibly avoid cross product calculation
164+
165+
int i, i2, j;
166+
int d1, d2;
167+
double cp1, cp2;
160168

161-
//std::cout << "Check intersect" << std::endl;
162169
for ( i = 0;i < 4;i++ )
163170
{
164171
i2 = ( i + 1 ) % 4;
165172
d1 = -1;
166173
d2 = -1;
167-
//std::cout << "new seg..." << std::endl;
174+
168175
for ( j = 0;j < 4;j++ )
169176
{
170177
cp1 = cross_product( x[i], y[i], x[i2], y[i2], lp->x[j], lp->y[j] );
171178
if ( cp1 > 0 )
172179
{
173180
d1 = 1;
174-
//std::cout << " cp1: " << cp1 << std::endl;
175181
}
176182
cp2 = cross_product( lp->x[i], lp->y[i],
177183
lp->x[i2], lp->y[i2],
@@ -180,25 +186,33 @@ namespace pal
180186
if ( cp2 > 0 )
181187
{
182188
d2 = 1;
183-
//std::cout << " cp2 " << cp2 << std::endl;
184189
}
185190
}
186191

187192
if ( d1 == -1 || d2 == -1 ) // disjoint
188-
{
189-
if ( lp->getNextPart() )
190-
{
191-
if ( isInConflict(lp->getNextPart()) )
192-
return true;
193-
}
193+
return false;
194+
}
195+
return true;
196+
}
194197

195-
if (nextPart)
196-
return nextPart->isInConflict( lp );
197-
else
198-
return false;
198+
bool LabelPosition::isInConflictMultiPart( LabelPosition* lp )
199+
{
200+
// check all parts against all parts of other one
201+
LabelPosition* tmp1 = this;
202+
while (tmp1)
203+
{
204+
// check tmp1 against parts of other label
205+
LabelPosition* tmp2 = lp;
206+
while (tmp2)
207+
{
208+
if (tmp1->isInConflictSinglePart(tmp2))
209+
return true;
210+
tmp2 = tmp2->nextPart;
199211
}
212+
213+
tmp1 = tmp1->nextPart;
200214
}
201-
return true;
215+
return false; // no conflict found
202216
}
203217

204218
int LabelPosition::getId() const

src/core/pal/labelposition.h

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ namespace pal
7474
LabelPosition* nextPart;
7575
int partId;
7676

77+
bool isInConflictSinglePart( LabelPosition* lp );
78+
bool isInConflictMultiPart( LabelPosition* lp );
79+
7780
public:
7881
/**
7982
* \brief create a new LabelPosition

0 commit comments

Comments
 (0)