[pal] Fix invalid candidates created for parallel line labeling

mode when a closed linestring is too small for labels to fit
within feature

Fixes #18283
This commit is contained in:
Nyall Dawson 2018-03-02 16:31:39 +10:00
parent d7aec7cc5f
commit a76fb0b469
3 changed files with 17 additions and 2 deletions

View File

@ -856,12 +856,17 @@ int FeaturePart::createCandidatesAlongLineNearMidpoint( QList<LabelPosition *> &
{
lineStepDistance = std::min( std::min( labelHeight, labelWidth ), lineStepDistance / mLF->layer()->pal->line_p );
}
else // line length < label width => centering label position
else if ( !line->isClosed() ) // line length < label width => centering label position
{
currentDistanceAlongLine = - ( labelWidth - totalLineLength ) / 2.0;
lineStepDistance = -1;
totalLineLength = labelWidth;
}
else
{
// closed line, not long enough for label => no candidates!
currentDistanceAlongLine = std::numeric_limits< double >::max();
}
double candidateLength;
double beta;

View File

@ -846,3 +846,8 @@ double PointSet::length() const
return -1;
}
}
bool PointSet::isClosed() const
{
return qgsDoubleNear( x[0], x[nbPoints - 1] ) && qgsDoubleNear( y[0], y[nbPoints - 1] );
}

View File

@ -156,13 +156,18 @@ namespace pal
*/
double length() const;
/**
* Returns true if pointset is closed.
*/
bool isClosed() const;
protected:
mutable GEOSGeometry *mGeos = nullptr;
mutable bool mOwnsGeom = false;
int nbPoints;
double *x = nullptr;
double *y; // points order is counterclockwise
double *y = nullptr; // points order is counterclockwise
int *cHull = nullptr;
int cHullSize;