Skip to content

Commit 50cf7d3

Browse files
committed
Avoid ugly super-narrow annotation balloon callout lines at some angles
1 parent 74307d6 commit 50cf7d3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/core/annotations/qgsannotation.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,24 @@ void QgsAnnotation::updateBalloon()
215215
QLineF currentSegment = segmentList.at( i );
216216
QgsPointXY currentMinDistPoint;
217217
double currentMinDist = origin.sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint );
218-
if ( currentMinDist < minEdgeDist )
218+
bool isPreferredSegment = false;
219+
if ( qgsDoubleNear( currentMinDist, minEdgeDist ) )
220+
{
221+
// two segments are close - work out which looks nicer
222+
const double angle = fmod( origin.azimuth( currentMinDistPoint ) + 360.0, 360.0 );
223+
if ( angle < 45 || angle > 315 )
224+
isPreferredSegment = i == 0;
225+
else if ( angle < 135 )
226+
isPreferredSegment = i == 3;
227+
else if ( angle < 225 )
228+
isPreferredSegment = i == 2;
229+
else
230+
isPreferredSegment = i == 1;
231+
}
232+
else if ( currentMinDist < minEdgeDist )
233+
isPreferredSegment = true;
234+
235+
if ( isPreferredSegment )
219236
{
220237
minEdgeIndex = i;
221238
minEdgePoint = currentMinDistPoint;

0 commit comments

Comments
 (0)