File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -255,20 +255,24 @@ bool QgsDecorationNorthArrow::calculateNorthDirection()
255
255
double x = cos ( p1.y () ) * sin ( p2.y () ) -
256
256
sin ( p1.y () ) * cos ( p2.y () ) * cos ( p2.x () - p1.x () );
257
257
258
+ // Use TOL to decide if the quotient is big enough.
259
+ // Both x and y can be very small, if heavily zoomed
260
+ // For small y/x, we set directly angle 0. Not sure
261
+ // if this is needed.
258
262
if ( y > 0.0 )
259
263
{
260
- if ( x > TOL )
264
+ if ( x > 0.0 && ( y / x ) > TOL )
261
265
angle = atan ( y / x );
262
- else if ( x < -TOL )
266
+ else if ( x < 0.0 && ( y / x ) < -TOL )
263
267
angle = PI - atan ( -y / x );
264
268
else
265
269
angle = 0.5 * PI;
266
270
}
267
271
else if ( y < 0.0 )
268
272
{
269
- if ( x > TOL )
273
+ if ( x > 0.0 && ( y / x ) < - TOL )
270
274
angle = -atan ( -y / x );
271
- else if ( x < - TOL )
275
+ else if ( x < 0.0 && ( y / x ) > TOL )
272
276
angle = atan ( y / x ) - PI;
273
277
else
274
278
angle = 1.5 * PI;
You can’t perform that action at this time.
0 commit comments