Skip to content

Commit c3f720f

Browse files
committedAug 9, 2016
[pal] Only apply distance from line midpoint penalty to non closed linestrings
Sponsored by Andreas Neumann
1 parent dc0cc32 commit c3f720f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
 

‎src/core/pal/feature.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,14 @@ int FeaturePart::createCandidatesAlongLineNearStraightSegments( QList<LabelPosit
748748
double costCenter = 2 * qAbs( labelCenter - distanceToCenterOfSegment ) / ( distanceToEndOfSegment - distanceToStartOfSegment ); // 0 -> 1
749749
cost += costCenter * 0.0005; // < 0, 0.0005 >
750750

751-
// penalize positions which are further from absolute center of whole linestring
752-
double costLineCenter = 2 * qAbs( labelCenter - middleOfLine ) / totalLineLength; // 0 -> 1
753-
cost += costLineCenter * 0.0005; // < 0, 0.0005 >
751+
if ( !closedLine )
752+
{
753+
// penalize positions which are further from absolute center of whole linestring
754+
// this only applies to non closed linestrings, since the middle of a closed linestring is effectively arbitrary
755+
// and irrelevant to labeling
756+
double costLineCenter = 2 * qAbs( labelCenter - middleOfLine ) / totalLineLength; // 0 -> 1
757+
cost += costLineCenter * 0.0005; // < 0, 0.0005 >
758+
}
754759

755760
cost += segmentCost * 0.0005; // prefer labels on longer straight segments
756761
cost += segmentAngleCost * 0.0001; // prefer more horizontal segments, but this is less important than length considerations

0 commit comments

Comments
 (0)
Please sign in to comment.