summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/xcb
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2017-02-24 14:40:51 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-01-27 15:00:57 +0100
commitb08368d99fa41b3f84cf30468c2dc9f5c2c43423 (patch)
tree9b5f6400423c7f23a547c0a21675a989683c4b7e /src/plugins/platforms/xcb
parentad16f79e5fac13f8a9dab8604de6adb6c46fe7bd (diff)
Add qHypot() to qmath.h, exposing and extending std::hypot()
We have plenty of places where we add some squares and take a square root; this may be done more accurately and faster by hypot(). Introduce QHypotHelper to handle hypot with more than 3 parameters, and with 3 when the C++17 version is missing (which it never should be). Include an overload taking arbitrarily many valus and ensure that we can use qHypot() with qfloat16. Illustrate with some example uses, add some tests. [ChangeLog][QtCore][QMath] Header <QMath> now provides qHypot(), an implementation of std::hypot() taking arbitrarily many numeric values, including support for qfloat16, while avoiding the overflow and underflow problems that arise when naively taking the square root of a sum of squares. Change-Id: Ia4e3913fe83fc27d17d8e7f1a52f03ad445c1fed Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/plugins/platforms/xcb')
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection_xi2.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
index 07f66af9e3..f69655e403 100644
--- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
@@ -43,11 +43,11 @@
#include "qxcbscreen.h"
#include "qxcbwindow.h"
#include "QtCore/qmetaobject.h"
+#include "QtCore/qmath.h"
#include <QtGui/qpointingdevice.h>
#include <QtGui/private/qpointingdevice_p.h>
#include <qpa/qwindowsysteminterface_p.h>
#include <QDebug>
-#include <cmath>
#include <xcb/xinput.h>
@@ -758,11 +758,11 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
} else if (vci.label == QXcbAtom::AbsMTTouchMajor) {
const qreal sw = screen->geometry().width();
const qreal sh = screen->geometry().height();
- w = valuatorNormalized * std::sqrt(sw * sw + sh * sh);
+ w = valuatorNormalized * qHypot(sw, sh);
} else if (vci.label == QXcbAtom::AbsMTTouchMinor) {
const qreal sw = screen->geometry().width();
const qreal sh = screen->geometry().height();
- h = valuatorNormalized * std::sqrt(sw * sw + sh * sh);
+ h = valuatorNormalized * qHypot(sw, sh);
} else if (vci.label == QXcbAtom::AbsMTOrientation) {
// Find the closest axis.
// 0 corresponds to the Y axis, vci.max to the X axis.