@@ -75,7 +75,7 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e )
7575
7676 if ( true )
7777 {
78- mCurrentMouseAzimuth = azimuthToCCW ( mRotationPoint .azimuth ( toMapCoordinates ( e->pos () ) ) );
78+ mCurrentMouseAzimuth = convertAzimuth ( mRotationPoint .azimuth ( toMapCoordinates ( e->pos () ) ) );
7979
8080 bool hasRotationValue;
8181 int rotationCol;
@@ -91,8 +91,7 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e )
9191 mRotationPreviewBox = createRotationPreviewBox ();
9292
9393 mRotationItem = new QgsPointRotationItem ( mCanvas );
94- mRotationItem ->setOrientation ( QgsPointRotationItem::Counterclockwise );
95- mRotationItem ->setSymbol ( QgsApplication::getThemePixmap ( QStringLiteral ( " mActionRotatePointSymbols.svg" ) ).toImage () );
94+ mRotationItem ->setOrientation ( QgsPointRotationItem::Clockwise );
9695 mRotationItem ->setPointLocation ( mRotationPoint );
9796 mRotationItem ->setSymbolRotation ( mCurrentRotation );
9897 }
@@ -104,15 +103,17 @@ void QgsMapToolRotateLabel::canvasMoveEvent( QgsMapMouseEvent *e )
104103 if ( mLabelRubberBand )
105104 {
106105 QgsPointXY currentPoint = toMapCoordinates ( e->pos () );
107- double azimuth = azimuthToCCW ( mRotationPoint .azimuth ( currentPoint ) );
106+ double azimuth = convertAzimuth ( mRotationPoint .azimuth ( currentPoint ) );
108107 double azimuthDiff = azimuth - mCurrentMouseAzimuth ;
109108 azimuthDiff = azimuthDiff > 180 ? azimuthDiff - 360 : azimuthDiff;
110109
111110 mCurrentRotation += azimuthDiff;
112- mCurrentRotation = mCurrentRotation - static_cast <float >( static_cast <int >( mCurrentRotation / 360 ) ) * 360 ; // mCurrentRotation % 360;
113- mCurrentRotation = mCurrentRotation < 0 ? 360 - mCurrentRotation : mCurrentRotation ;
111+ if ( mCurrentRotation >= 360 || mCurrentRotation <= -360 )
112+ mCurrentRotation = std::fmod ( mCurrentRotation , 360.0 );
113+ if ( mCurrentRotation < 0 )
114+ mCurrentRotation += 360.0 ;
114115
115- mCurrentMouseAzimuth = azimuth - static_cast < float >( static_cast < int >( azimuth / 360 ) ) * 360 ;
116+ mCurrentMouseAzimuth = std::fmod ( azimuth, 360.0 ) ;
116117
117118 // if shift-modifier is pressed, round to 15 degrees
118119 int displayValue;
@@ -181,9 +182,10 @@ int QgsMapToolRotateLabel::roundTo15Degrees( double n )
181182 return ( m * 15 );
182183}
183184
184- double QgsMapToolRotateLabel::azimuthToCCW ( double a )
185+ double QgsMapToolRotateLabel::convertAzimuth ( double a )
185186{
186- return ( a > 0 ? 360 - a : -a );
187+ a -= 90 ; // convert from 0 = north to 0 = east
188+ return ( a <= -180.0 ? 360 + a : a );
187189}
188190
189191QgsRubberBand *QgsMapToolRotateLabel::createRotationPreviewBox ()
@@ -218,15 +220,15 @@ void QgsMapToolRotateLabel::setRotationPreviewBox( double rotation )
218220
219221 for ( int i = 0 ; i < boxPoints.size (); ++i )
220222 {
221- mRotationPreviewBox ->addPoint ( rotatePointCounterClockwise ( boxPoints.at ( i ), mRotationPoint , rotation ) );
223+ mRotationPreviewBox ->addPoint ( rotatePointClockwise ( boxPoints.at ( i ), mRotationPoint , rotation ) );
222224 }
223- mRotationPreviewBox ->addPoint ( rotatePointCounterClockwise ( boxPoints.at ( 0 ), mRotationPoint , rotation ) );
225+ mRotationPreviewBox ->addPoint ( rotatePointClockwise ( boxPoints.at ( 0 ), mRotationPoint , rotation ) );
224226 mRotationPreviewBox ->show ();
225227}
226228
227- QgsPointXY QgsMapToolRotateLabel::rotatePointCounterClockwise ( const QgsPointXY &input, const QgsPointXY ¢erPoint, double degrees )
229+ QgsPointXY QgsMapToolRotateLabel::rotatePointClockwise ( const QgsPointXY &input, const QgsPointXY ¢erPoint, double degrees ) const
228230{
229- double rad = degrees / 180 * M_PI;
231+ double rad = - degrees / 180 * M_PI;
230232 double v1x = input.x () - centerPoint.x ();
231233 double v1y = input.y () - centerPoint.y ();
232234
0 commit comments