1 | // Copyright (C) 2019 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICK3DUTILS_P_H |
5 | #define QQUICK3DUTILS_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <type_traits> |
19 | |
20 | #include <QtCore/QtGlobal> |
21 | #include <private/qglobal_p.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | // Assigns 'updated' to 'orig' and returns true if they are different |
26 | template<typename T, typename std::enable_if<!std::is_floating_point<T>::value, int>::type = 0> |
27 | bool qUpdateIfNeeded(T &orig, T updated) |
28 | { |
29 | if (orig == updated) |
30 | return false; |
31 | orig = updated; |
32 | return true; |
33 | } |
34 | |
35 | // Assigns 'updated' to 'orig' and returns true if they are different, compared with qFuzzyCompare |
36 | template <typename T, typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0> |
37 | bool qUpdateIfNeeded(T &orig, T updated) |
38 | { |
39 | if (qFuzzyCompare(orig, updated)) |
40 | return false; |
41 | orig = updated; |
42 | return true; |
43 | } |
44 | |
45 | QT_END_NAMESPACE |
46 | |
47 | #endif // QQUICK3DUTILS_P_H |
48 | |