From 368b24bfa00a5ef8fe14cd5e4690333675d7704a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 24 Feb 2017 15:49:29 +0100 Subject: Be consistent about values related to pi (radian / degree ratio) Use JavaScript's Math.PI to compute 180 / pi (the number of degrees in one radian), rather than a hand-coded value for this constant. Store the result in a readonly property double to avoid repeating the computation. Tweak the pitch and roll calculations to use more apt Math methods: use hypot rather than sqrt of a sum of squares, and use atan2 instead of a tan of a ratio (whose denominator is always positive, so this doesn't change which angle we get). Task-number: QTBUG-58083 Change-Id: Ic3f865dfcbd9b02a0b93f065995d850386aef18c Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Lorn Potter --- examples/sensors/maze/Mouse.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/sensors/maze/Mouse.qml') diff --git a/examples/sensors/maze/Mouse.qml b/examples/sensors/maze/Mouse.qml index 7f8ea27..cf83991 100644 --- a/examples/sensors/maze/Mouse.qml +++ b/examples/sensors/maze/Mouse.qml @@ -62,6 +62,7 @@ Item { width: Lib.cellDimension height: Lib.cellDimension property int angle + readonly property double radians_to_degrees: 180 / Math.PI AnimatedImage { id: img @@ -79,8 +80,7 @@ Item { //! [0] var a = newy - mouse.y var b = newx - mouse.x - var radians_to_degrees = 57.2957795 - angle = Math.atan2(-b, a) * radians_to_degrees + angle = Math.atan2(-b, a) * mouse.radians_to_degrees if (angle < 0) angle = 360 + angle -- cgit v1.2.1