Skip to content

Commit

Permalink
[pal] Fix invalid candidates created for parallel line labeling
Browse files Browse the repository at this point in the history
mode when a closed linestring is too small for labels to fit
within feature

Fixes #18283

(cherry-picked from a76fb0b)
  • Loading branch information
nyalldawson committed Mar 6, 2018
1 parent d97ea9c commit 3552764
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/core/pal/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/core/pal/pointset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] );
}
7 changes: 6 additions & 1 deletion src/core/pal/pointset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3552764

Please sign in to comment.