52 , reversed( isReversed )
54 , quadrant( quadrant )
56 , mHasObstacleConflict( false )
57 , mUpsideDownCharCount( 0 )
65 while ( this->alpha > 2 * M_PI )
66 this->alpha -= 2 * M_PI;
68 while ( this->alpha < 0 )
69 this->alpha += 2 * M_PI;
71 double beta = this->alpha + M_PI_2;
73 double dx1, dx2, dy1, dy2;
75 dx1 = std::cos( this->alpha ) *
w;
76 dy1 = std::sin( this->alpha ) *
w;
78 dx2 = std::cos( beta ) *
h;
79 dy2 = std::sin( beta ) *
h;
87 x[2] = x1 + dx1 + dx2;
88 y[2] = y1 + dy1 + dy2;
95 this->alpha > M_PI_2 && this->alpha <= 3 * M_PI_2 )
120 if ( this->alpha < M_PI )
131 for (
int i = 0; i <
nbPoints; ++i )
153 if ( other.mNextPart )
154 mNextPart = qgis::make_unique< LabelPosition >( *other.mNextPart );
160 mHasObstacleConflict = other.mHasObstacleConflict;
161 mUpsideDownCharCount = other.mUpsideDownCharCount;
168 for ( i = 0; i < 4; i++ )
170 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
171 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
176 return mNextPart->isIn( bbox );
185 for ( i = 0; i < 4; i++ )
187 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
188 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
193 return mNextPart->isIntersect( bbox );
209 else if ( mNextPart )
211 return mNextPart->intersects( geometry );
214 catch ( GEOSException &e )
234 else if ( mNextPart )
236 return mNextPart->within( geometry );
239 catch ( GEOSException &e )
250 for (
int i = 0; i < 4; i++ )
252 if ( !(
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
253 y[i] >= bbox[1] &&
y[i] <= bbox[3] ) )
258 return mNextPart->isInside( bbox );
269 return isInConflictSinglePart( lp );
271 return isInConflictMultiPart( lp );
274 bool LabelPosition::isInConflictSinglePart(
const LabelPosition *lp )
const
291 bool result = ( GEOSPreparedIntersects_r( geosctxt,
preparedGeom(), lp->
mGeos ) == 1 );
294 catch ( GEOSException &e )
301 bool LabelPosition::isInConflictMultiPart(
const LabelPosition *lp )
const
311 if ( tmp1->isInConflictSinglePart( tmp2 ) )
321 int LabelPosition::partCount()
const
324 return mNextPart->partCount() + 1;
331 for (
int i = 0; i < 4; i++ )
338 mNextPart->offsetPosition( xOffset, yOffset );
350 return ( i >= 0 && i < 4 ?
x[i] : -1 );
355 return ( i >= 0 && i < 4 ?
y[i] : -1 );
367 mCost -= int ( mCost );
380 mNextPart->getBoundingBox( amin, amax );
384 amin[0] = std::numeric_limits<double>::max();
385 amax[0] = std::numeric_limits<double>::lowest();
386 amin[1] = std::numeric_limits<double>::max();
387 amax[1] = std::numeric_limits<double>::lowest();
389 for (
int c = 0;
c < 4;
c++ )
391 if (
x[
c] < amin[0] )
393 if (
x[
c] > amax[0] )
395 if (
y[
c] < amin[1] )
397 if (
y[
c] > amax[1] )
404 mHasObstacleConflict = conflicts;
406 mNextPart->setConflictsWithObstacle( conflicts );
411 mHasHardConflict = conflicts;
413 mNextPart->setHasHardObstacleConflict( conflicts );
435 bool contains =
false;
439 contains =
x[0] <= xp &&
x[1] >= xp &&
y[0] <= yp &&
y[2] >= yp;
446 double distance = -1;
451 const double dx = std::max( std::max(
x[0] - xp, 0.0 ), xp -
x[1] );
452 const double dy = std::max( std::max(
y[0] - yp, 0.0 ), yp -
y[2] );
453 distance = std::sqrt( dx * dx + dy * dy );
461 if ( mNextPart && distance > 0 )
462 return std::min( distance, mNextPart->getDistanceToPoint( xp, yp ) );
482 else if ( mNextPart )
484 return mNextPart->crossesLine( line );
487 catch ( GEOSException &e )
501 if ( !polygon->
mGeos )
512 else if ( mNextPart )
514 return mNextPart->crossesBoundary( polygon );
517 catch ( GEOSException &e )
529 double totalCost = polygonIntersectionCostForParts( polygon );
531 return std::ceil( totalCost / n );
539 if ( !polygon->
mGeos )
550 catch ( GEOSException &e )
557 return mNextPart->intersectsWithPolygon( polygon );
565 double LabelPosition::polygonIntersectionCostForParts(
PointSet *polygon )
const
570 if ( !polygon->
mGeos )
585 for (
int i = 0; i < 4; ++i )
590 for (
int a = 0; a < 2; ++a )
594 px = (
x[i] +
x[( i + 1 ) % 4] ) / 2.0;
595 py = (
y[i] +
y[( i + 1 ) % 4] ) / 2.0;
599 px = (
x[0] +
x[2] ) / 2.0;
600 py = (
y[0] +
y[2] ) / 2.0;
607 catch ( GEOSException &e )
617 cost += mNextPart->polygonIntersectionCostForParts( polygon );