1 | // Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | #ifndef QT3DANIMATION_ANIMATION_FUNCTIONRANGEFINDER_P_H |
4 | #define QT3DANIMATION_ANIMATION_FUNCTIONRANGEFINDER_P_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists for the convenience |
11 | // of other Qt classes. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include <QtCore/qlist.h> |
18 | #include <private/qglobal_p.h> |
19 | |
20 | #include <cmath> |
21 | #include <cstdlib> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | namespace Qt3DAnimation { |
26 | namespace Animation { |
27 | |
28 | class Q_AUTOTEST_EXPORT FunctionRangeFinder |
29 | { |
30 | public: |
31 | FunctionRangeFinder(QList<float> *x); |
32 | |
33 | inline int findLowerBound(float x) const { return m_correlated ? hunt(x) : locate(x); } |
34 | |
35 | int rangeSize() const { return m_rangeSize; } |
36 | void setRangeSize(int rangeSize) { m_rangeSize = rangeSize; } |
37 | |
38 | bool isAscending() const { return m_ascending; } |
39 | void setAscending(bool ascending) { m_ascending = ascending; } |
40 | |
41 | int correlationThreshold() const { return m_correlationThreshold; } |
42 | void updateAutomaticCorrelationThreshold() |
43 | { |
44 | m_correlationThreshold = std::max(a: 1, b: int(std::pow(x: float(m_x->size()), y: 0.25))); |
45 | } |
46 | |
47 | private: |
48 | int locate(float x) const; |
49 | int hunt(float x) const; |
50 | |
51 | QList<float> *m_x; |
52 | mutable qsizetype m_previousLowerBound; |
53 | mutable bool m_correlated; |
54 | int m_rangeSize; |
55 | int m_correlationThreshold; |
56 | bool m_ascending; |
57 | }; |
58 | |
59 | } // namespace Animation |
60 | } // namespace Qt3DAnimation |
61 | |
62 | QT_END_NAMESPACE |
63 | |
64 | #endif // QT3DANIMATION_ANIMATION_FUNCTIONRANGEFINDER_P_H |
65 | |