summaryrefslogtreecommitdiffstats
path: root/examples/widgets/itemviews
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2017-01-11 11:35:25 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2017-02-23 16:43:35 +0000
commit0b822c220997046e09fd9cae4414f35f88a91b21 (patch)
tree4ad858280f7911c608aa6ea397454714afd4e6fc /examples/widgets/itemviews
parent89870a35bde2f67f9c371ba145e90b86d3e2dd1b (diff)
Examples: use std::atan2 for simper angle calculations
Using std::atan2 gets the right answer directly from dy and dx, without having to fix up quadrant as we needed to with acos (albeit we have to negate dy in some cases, to match prior sense of angles). In the process, it avoids explicit division, which would be an error when the line's length is zero. Change-Id: Ia2923159d38834e08e6f15cbff6766ed419fa804 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'examples/widgets/itemviews')
-rw-r--r--examples/widgets/itemviews/chart/pieview.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/widgets/itemviews/chart/pieview.cpp b/examples/widgets/itemviews/chart/pieview.cpp
index fb439fae67..942bbe5ca5 100644
--- a/examples/widgets/itemviews/chart/pieview.cpp
+++ b/examples/widgets/itemviews/chart/pieview.cpp
@@ -125,9 +125,9 @@ QModelIndex PieView::indexAt(const QPoint &point) const
return QModelIndex();
// Determine the angle of the point.
- double angle = (180 / M_PI) * std::acos(cx / d);
- if (cy < 0)
- angle = 360 - angle;
+ double angle = (180 / M_PI) * std::atan2(cy, cx);
+ if (angle < 0)
+ angle = 360 + angle;
// Find the relevant slice of the pie.
double startAngle = 0.0;