Skip to content
Permalink
Browse files

[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
  • Loading branch information
nyalldawson committed Mar 2, 2018
1 parent d7aec7c commit a76fb0b469796183c76d5343053e5be2471de126
Showing with 17 additions and 2 deletions.
  1. +6 −1 src/core/pal/feature.cpp
  2. +5 −0 src/core/pal/pointset.cpp
  3. +6 −1 src/core/pal/pointset.h
@@ -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;
@@ -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] );
}
@@ -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;

1 comment on commit a76fb0b

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn commented on a76fb0b Mar 5, 2018

@nyalldawson , great, thanks. It'll need backporting to the 3.0 branch.

Please sign in to comment.
You can’t perform that action at this time.