diff options
author | 2024-11-11 21:49:51 +0000 | |
---|---|---|
committer | 2024-11-20 23:57:51 +0000 | |
commit | 53463397c3b84bb71d7fe155a8ada86fdcc0e96b (patch) | |
tree | f56a833a21b8347ba608befaeb416c109917d2bd /include | |
parent | 08ee19997d0ad4fab38465ef878b666c9fffb203 (diff) |
Fix One Euro filter's units of computation
Changed the units that the One Euro filter uses to compute the filtered
coordinates. This was causing a crash because if two timestamps were
sufficiently close to each other, by the time of implicitly converting
from nanoseconds to seconds, they were considered equal. This led to a
zero division when calculating the sampling frequency. Now, everything
is handled in the scale of nanoseconds, and conversion are done if and
only if they're necessary.
Bug: 297226446
Flag: EXEMPT bugfix
Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Change-Id: I7fced6db447074cccb3d938eb9dc7a9707433f53
Diffstat (limited to 'include')
-rw-r--r-- | include/input/CoordinateFilter.h | 2 | ||||
-rw-r--r-- | include/input/OneEuroFilter.h | 10 |
2 files changed, 6 insertions, 6 deletions
diff --git a/include/input/CoordinateFilter.h b/include/input/CoordinateFilter.h index f36472dc8c..8f2e605e85 100644 --- a/include/input/CoordinateFilter.h +++ b/include/input/CoordinateFilter.h @@ -44,7 +44,7 @@ public: * the previous call. * @param coords Coordinates to be overwritten by the corresponding filtered coordinates. */ - void filter(std::chrono::duration<float> timestamp, PointerCoords& coords); + void filter(std::chrono::nanoseconds timestamp, PointerCoords& coords); private: OneEuroFilter mXFilter; diff --git a/include/input/OneEuroFilter.h b/include/input/OneEuroFilter.h index a0168e4f91..bdd82b2ee8 100644 --- a/include/input/OneEuroFilter.h +++ b/include/input/OneEuroFilter.h @@ -56,7 +56,7 @@ public: * provided in the previous call. * @param rawPosition Position to be filtered. */ - float filter(std::chrono::duration<float> timestamp, float rawPosition); + float filter(std::chrono::nanoseconds timestamp, float rawPosition); private: /** @@ -67,7 +67,7 @@ private: /** * Slope of the cutoff frequency criterion. This is the term scaling the absolute value of the - * filtered signal's speed. The data member is dimensionless, that is, it does not have units. + * filtered signal's speed. Units are 1 / position. */ const float mBeta; @@ -78,9 +78,9 @@ private: const float mSpeedCutoffFreq; /** - * The timestamp from the previous call. Units are seconds. + * The timestamp from the previous call. */ - std::optional<std::chrono::duration<float>> mPrevTimestamp; + std::optional<std::chrono::nanoseconds> mPrevTimestamp; /** * The raw position from the previous call. @@ -88,7 +88,7 @@ private: std::optional<float> mPrevRawPosition; /** - * The filtered velocity from the previous call. Units are position per second. + * The filtered velocity from the previous call. Units are position per nanosecond. */ std::optional<float> mPrevFilteredVelocity; |