@@ -149,29 +149,35 @@ namespace pal
149
149
150
150
bool LabelPosition::isInConflict ( LabelPosition *lp )
151
151
{
152
- int i, i2, j;
153
- int d1, d2;
154
-
155
152
if ( this ->probFeat == lp->probFeat ) // bugfix #1
156
153
return false ; // always overlaping itself !
157
154
158
- double cp1, cp2;
155
+ if (nextPart == NULL && lp->nextPart == NULL )
156
+ return isInConflictSinglePart (lp);
157
+ else
158
+ return isInConflictMultiPart (lp);
159
+ }
159
160
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;
160
168
161
- // std::cout << "Check intersect" << std::endl;
162
169
for ( i = 0 ;i < 4 ;i++ )
163
170
{
164
171
i2 = ( i + 1 ) % 4 ;
165
172
d1 = -1 ;
166
173
d2 = -1 ;
167
- // std::cout << "new seg..." << std::endl;
174
+
168
175
for ( j = 0 ;j < 4 ;j++ )
169
176
{
170
177
cp1 = cross_product ( x[i], y[i], x[i2], y[i2], lp->x [j], lp->y [j] );
171
178
if ( cp1 > 0 )
172
179
{
173
180
d1 = 1 ;
174
- // std::cout << " cp1: " << cp1 << std::endl;
175
181
}
176
182
cp2 = cross_product ( lp->x [i], lp->y [i],
177
183
lp->x [i2], lp->y [i2],
@@ -180,25 +186,33 @@ namespace pal
180
186
if ( cp2 > 0 )
181
187
{
182
188
d2 = 1 ;
183
- // std::cout << " cp2 " << cp2 << std::endl;
184
189
}
185
190
}
186
191
187
192
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
+ }
194
197
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 ;
199
211
}
212
+
213
+ tmp1 = tmp1->nextPart ;
200
214
}
201
- return true ;
215
+ return false ; // no conflict found
202
216
}
203
217
204
218
int LabelPosition::getId () const
0 commit comments