Use qmath.h's conversions between degrees and radians

The make the semantics overt and avoid the joys of yet another
approximation to pi/180 hard-coded in our source-code.

Change-Id: I9dcbaada2e7de119e385fc7056bc601ecd59311a
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Edward Welbourne 2021-09-08 09:32:26 +02:00
parent c942bae4eb
commit 72338c12bc
2 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
@ -569,7 +569,6 @@ QTransform & QTransform::shear(qreal sh, qreal sv)
return *this;
}
const qreal deg2rad = qreal(0.017453292519943295769); // pi/180
const qreal inv_dist_to_plane = 1. / 1024.;
/*!
@ -606,7 +605,7 @@ QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
else if (a == 180.)
cosa = -1.;
else{
qreal b = deg2rad*a; // convert to radians
qreal b = qDegreesToRadians(a);
sina = qSin(b); // fast and convenient
cosa = qCos(b);
}

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
@ -50,6 +50,7 @@
#include "qiosmenu.h"
#endif
#include <QtCore/qmath.h>
#include <QtGui/qpointingdevice.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qwindow_p.h>
@ -388,10 +389,10 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
// azimuth unit vector: +x to the right, +y going downwards
CGVector azimuth = [cTouch azimuthUnitVectorInView: self];
// azimuthAngle given in radians, zero when the stylus points towards +x axis; converted to degrees with 0 pointing straight up
qreal azimuthAngle = [cTouch azimuthAngleInView: self] * 180 / M_PI + 90;
qreal azimuthAngle = qRadiansToDegrees([cTouch azimuthAngleInView: self]) + 90;
// altitudeAngle given in radians, pi / 2 is with the stylus perpendicular to the iPad, smaller values mean more tilted, but never negative.
// Convert to degrees with zero being perpendicular.
qreal altitudeAngle = 90 - cTouch.altitudeAngle * 180 / M_PI;
qreal altitudeAngle = 90 - qRadiansToDegrees(cTouch.altitudeAngle);
qCDebug(lcQpaTablet) << i << ":" << timeStamp << localViewPosition << pressure << state << "azimuth" << azimuth.dx << azimuth.dy
<< "angle" << azimuthAngle << "altitude" << cTouch.altitudeAngle
<< "xTilt" << qBound(-60.0, altitudeAngle * azimuth.dx, 60.0) << "yTilt" << qBound(-60.0, altitudeAngle * azimuth.dy, 60.0);