@@ -1170,6 +1170,19 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
1170
1170
return 0 ;
1171
1171
}
1172
1172
1173
+ // calculate overall angle of line
1174
+ double lineAngle;
1175
+ double bx = mapShape->x [0 ];
1176
+ double by = mapShape->y [0 ];
1177
+ double ex = mapShape->x [ mapShape->nbPoints - 1 ];
1178
+ double ey = mapShape->y [ mapShape->nbPoints - 1 ];
1179
+ if ( qgsDoubleNear ( ey, by ) && qgsDoubleNear ( ex, bx ) )
1180
+ {
1181
+ lineAngle = 0.0 ;
1182
+ }
1183
+ else
1184
+ lineAngle = atan2 ( ey - by, ex - bx );
1185
+
1173
1186
QLinkedList<LabelPosition*> positions;
1174
1187
double delta = qMax ( li->label_height , total_distance / mLF ->layer ()->pal ->line_p );
1175
1188
@@ -1178,7 +1191,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
1178
1191
flags = FLAG_ON_LINE; // default flag
1179
1192
1180
1193
// generate curved labels
1181
- for ( int i = 0 ; i * delta < total_distance; i++ )
1194
+ for ( double i = 0 ; i < total_distance; i += delta )
1182
1195
{
1183
1196
bool flip = false ;
1184
1197
// placements may need to be reversed if using map orientation and the line has right-to-left direction
@@ -1193,7 +1206,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
1193
1206
orientation = 1 ;
1194
1207
}
1195
1208
1196
- LabelPosition* slp = curvedPlacementAtOffset ( mapShape, path_distances, orientation, 1 , i * delta , reversed, flip );
1209
+ LabelPosition* slp = curvedPlacementAtOffset ( mapShape, path_distances, orientation, 1 , i, reversed, flip );
1197
1210
if ( slp == nullptr )
1198
1211
continue ;
1199
1212
@@ -1205,7 +1218,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
1205
1218
{
1206
1219
delete slp;
1207
1220
orientation = -orientation;
1208
- slp = curvedPlacementAtOffset ( mapShape, path_distances, orientation, 1 , i * delta , reversed, flip );
1221
+ slp = curvedPlacementAtOffset ( mapShape, path_distances, orientation, 1 , i, reversed, flip );
1209
1222
}
1210
1223
}
1211
1224
if ( slp == nullptr )
@@ -1236,7 +1249,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition* >& lPos,
1236
1249
if ( cost < 0.0001 ) cost = 0.0001 ;
1237
1250
1238
1251
// penalize positions which are further from the line's midpoint
1239
- double labelCenter = ( i * delta ) + getLabelWidth () / 2 ;
1252
+ double labelCenter = i + getLabelWidth () / 2 ;
1240
1253
double costCenter = qAbs ( total_distance / 2 - labelCenter ) / total_distance; // <0, 0.5>
1241
1254
cost += costCenter / 1000 ; // < 0, 0.0005 >
1242
1255
slp->setCost ( cost );
@@ -1753,7 +1766,7 @@ bool FeaturePart::showUprightLabels() const
1753
1766
return uprightLabel;
1754
1767
}
1755
1768
1756
- bool FeaturePart::nextCharPosition ( int charWidth, double segment_length, PointSet* path_positions, int & index, double & distance,
1769
+ bool FeaturePart::nextCharPosition ( double charWidth, double segment_length, PointSet* path_positions, int & index, double & distance,
1757
1770
double & start_x, double & start_y, double & end_x, double & end_y ) const
1758
1771
{
1759
1772
// Coordinates this character will start at
0 commit comments