Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f58a2b9c authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing wrong velocity state when there are too few samples

Bug: 160568387
Change-Id: I32b3b7ee1bff5595941fc0c0b37c9f5a28d1a1fa
(cherry picked from commit 48afb6b3)
parent 9b98d130
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -358,19 +358,24 @@ public class MotionPauseDetector {

            if (count < 3) {
                // Too few samples
                if (count == 2) {
                switch (count) {
                    case 2: {
                        int endPos = pointPos - 1;
                        if (endPos < 0) {
                            endPos += HISTORY_SIZE;
                        }
                        float denominator = eventTime - mHistoricTimes[endPos];
                        if (denominator != 0) {
                        return (eventTime - mHistoricPos[endPos]) / denominator;

                            return (mHistoricPos[pointPos] - mHistoricPos[endPos]) / denominator;
                        }
                    }
                    // fall through
                    case 1:
                        return 0f;
                    default:
                        return null;
                }
            }

            float Sxx = sxi2 - sxi * sxi / count;
            float Sxy = sxiyi - sxi * syi / count;