diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-02-21 17:14:37 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-07-05 10:15:34 +0000 |
commit | 8095c33bcddefebd16b7cb08b07690caf877f600 (patch) | |
tree | 816731835b77eb798295c4324f95b23f9916ebef /examples/widgets/animation | |
parent | 827e53540c8de10f3a0b8548523ca80bf9e1c75b (diff) |
Use qRadiansToDegrees() and qDegreesToRadians() more widely
Especially in examples, where we should show off our convenience
functions, prefer calling these functions over doing arithmetic with
M_PI (or approximations thereto) and 180 (give or take simple
factors). This incidentally documents what's going on, just by the
name of the function used (and reveals at least one place where
variables were misnamed; the return from atan is in radians, *not*
degrees).
Task-number: QTBUG-58083
Change-Id: I6e5d66721cafab423378f970af525400423e971e
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'examples/widgets/animation')
-rw-r--r-- | examples/widgets/animation/stickman/stickman.cpp | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp index 7a4629c4d2..b7a2d87ada 100644 --- a/examples/widgets/animation/stickman/stickman.cpp +++ b/examples/widgets/animation/stickman/stickman.cpp @@ -53,13 +53,7 @@ #include <QPainter> #include <QTimer> - -#define _USE_MATH_DEFINES -#include <math.h> - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif +#include <qmath.h> static const qreal Coords[NodeCount * 2] = { 0.0, -150.0, // head, #0 @@ -300,7 +294,7 @@ void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge QPointF dist = node2->pos() - node1->pos(); qreal sinAngle = dist.x() / sqrt(pow(dist.x(), 2) + pow(dist.y(), 2)); - qreal angle = asin(sinAngle) * 180.0 / M_PI; + qreal angle = qRadiansToDegrees(asin(sinAngle)); QPointF headPos = node1->pos(); painter->translate(headPos); |