Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "VelocityTracker_test" |
| 18 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 19 | #include <array> |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 20 | #include <chrono> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 21 | #include <math.h> |
| 22 | |
| 23 | #include <android-base/stringprintf.h> |
chaviw | 09c8d2d | 2020-08-24 15:48:26 -0700 | [diff] [blame] | 24 | #include <attestation/HmacKeyManager.h> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 25 | #include <gtest/gtest.h> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 26 | #include <gui/constants.h> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 27 | #include <input/VelocityTracker.h> |
| 28 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 29 | using namespace std::chrono_literals; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 30 | using android::base::StringPrintf; |
| 31 | |
| 32 | namespace android { |
| 33 | |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 34 | constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; // default display id |
| 35 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 36 | constexpr int32_t DEFAULT_POINTER_ID = 0; // pointer ID used for manually defined tests |
| 37 | |
| 38 | // velocity must be in the range (1-tol)*EV <= velocity <= (1+tol)*EV |
| 39 | // here EV = expected value, tol = VELOCITY_TOLERANCE |
| 40 | constexpr float VELOCITY_TOLERANCE = 0.2; |
| 41 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 42 | // estimate coefficients must be within 0.001% of the target value |
| 43 | constexpr float COEFFICIENT_TOLERANCE = 0.00001; |
| 44 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 45 | // --- VelocityTrackerTest --- |
| 46 | class VelocityTrackerTest : public testing::Test { }; |
| 47 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 48 | /* |
| 49 | * Similar to EXPECT_NEAR, but ensures that the difference between the two float values |
| 50 | * is at most a certain fraction of the target value. |
| 51 | * If fraction is zero, require exact match. |
| 52 | */ |
| 53 | static void EXPECT_NEAR_BY_FRACTION(float actual, float target, float fraction) { |
| 54 | float tolerance = fabsf(target * fraction); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 55 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 56 | if (target == 0 && fraction != 0) { |
| 57 | // If target is zero, this would force actual == target, which is too harsh. |
| 58 | // Relax this requirement a little. The value is determined empirically from the |
| 59 | // coefficients computed by the quadratic least squares algorithms. |
| 60 | tolerance = 1E-6; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 61 | } |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 62 | EXPECT_NEAR(actual, target, tolerance); |
| 63 | } |
| 64 | |
| 65 | static void checkVelocity(float Vactual, float Vtarget) { |
| 66 | EXPECT_NEAR_BY_FRACTION(Vactual, Vtarget, VELOCITY_TOLERANCE); |
| 67 | } |
| 68 | |
| 69 | static void checkCoefficient(float actual, float target) { |
| 70 | EXPECT_NEAR_BY_FRACTION(actual, target, COEFFICIENT_TOLERANCE); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 73 | struct Position { |
Siarhei Vishniakou | 01ca486 | 2019-03-06 13:22:13 -0800 | [diff] [blame] | 74 | float x; |
| 75 | float y; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * If both values are NAN, then this is considered to be an empty entry (no pointer data). |
| 79 | * If only one of the values is NAN, this is still a valid entry, |
| 80 | * because we may only care about a single axis. |
| 81 | */ |
| 82 | bool isValid() const { |
| 83 | return !(isnan(x) && isnan(y)); |
| 84 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 85 | }; |
| 86 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 87 | struct MotionEventEntry { |
| 88 | std::chrono::nanoseconds eventTime; |
| 89 | std::vector<Position> positions; |
| 90 | }; |
| 91 | |
| 92 | static BitSet32 getValidPointers(const std::vector<Position>& positions) { |
| 93 | BitSet32 pointers; |
| 94 | for (size_t i = 0; i < positions.size(); i++) { |
| 95 | if (positions[i].isValid()) { |
| 96 | pointers.markBit(i); |
| 97 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 98 | } |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 99 | return pointers; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 102 | static uint32_t getChangingPointerId(BitSet32 pointers, BitSet32 otherPointers) { |
| 103 | BitSet32 difference(pointers.value ^ otherPointers.value); |
| 104 | uint32_t pointerId = difference.clearFirstMarkedBit(); |
| 105 | EXPECT_EQ(0U, difference.value) << "Only 1 pointer can enter or leave at a time"; |
| 106 | return pointerId; |
| 107 | } |
| 108 | |
| 109 | static int32_t resolveAction(const std::vector<Position>& lastPositions, |
| 110 | const std::vector<Position>& currentPositions, |
| 111 | const std::vector<Position>& nextPositions) { |
| 112 | BitSet32 pointers = getValidPointers(currentPositions); |
| 113 | const uint32_t pointerCount = pointers.count(); |
| 114 | |
| 115 | BitSet32 lastPointers = getValidPointers(lastPositions); |
| 116 | const uint32_t lastPointerCount = lastPointers.count(); |
| 117 | if (lastPointerCount < pointerCount) { |
| 118 | // A new pointer is down |
| 119 | uint32_t pointerId = getChangingPointerId(pointers, lastPointers); |
| 120 | return AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 121 | (pointerId << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
| 122 | } |
| 123 | |
| 124 | BitSet32 nextPointers = getValidPointers(nextPositions); |
| 125 | const uint32_t nextPointerCount = nextPointers.count(); |
| 126 | if (pointerCount > nextPointerCount) { |
| 127 | // An existing pointer is leaving |
| 128 | uint32_t pointerId = getChangingPointerId(pointers, nextPointers); |
| 129 | return AMOTION_EVENT_ACTION_POINTER_UP | |
| 130 | (pointerId << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
| 131 | } |
| 132 | |
| 133 | return AMOTION_EVENT_ACTION_MOVE; |
| 134 | } |
| 135 | |
| 136 | static std::vector<MotionEvent> createMotionEventStream( |
| 137 | const std::vector<MotionEventEntry>& motions) { |
| 138 | if (motions.empty()) { |
| 139 | ADD_FAILURE() << "Need at least 1 sample to create a MotionEvent. Received empty vector."; |
| 140 | } |
| 141 | |
| 142 | std::vector<MotionEvent> events; |
| 143 | for (size_t i = 0; i < motions.size(); i++) { |
| 144 | const MotionEventEntry& entry = motions[i]; |
| 145 | BitSet32 pointers = getValidPointers(entry.positions); |
| 146 | const uint32_t pointerCount = pointers.count(); |
| 147 | |
| 148 | int32_t action; |
| 149 | if (i == 0) { |
| 150 | action = AMOTION_EVENT_ACTION_DOWN; |
| 151 | EXPECT_EQ(1U, pointerCount) << "First event should only have 1 pointer"; |
| 152 | } else if (i == motions.size() - 1) { |
| 153 | EXPECT_EQ(1U, pointerCount) << "Last event should only have 1 pointer"; |
| 154 | action = AMOTION_EVENT_ACTION_UP; |
| 155 | } else { |
| 156 | const MotionEventEntry& previousEntry = motions[i-1]; |
| 157 | const MotionEventEntry& nextEntry = motions[i+1]; |
| 158 | action = resolveAction(previousEntry.positions, entry.positions, nextEntry.positions); |
| 159 | } |
| 160 | |
| 161 | PointerCoords coords[pointerCount]; |
| 162 | PointerProperties properties[pointerCount]; |
| 163 | uint32_t pointerIndex = 0; |
| 164 | while(!pointers.isEmpty()) { |
| 165 | uint32_t pointerId = pointers.clearFirstMarkedBit(); |
| 166 | |
| 167 | coords[pointerIndex].clear(); |
| 168 | // We are treating column positions as pointerId |
| 169 | EXPECT_TRUE(entry.positions[pointerId].isValid()) << |
| 170 | "The entry at pointerId must be valid"; |
| 171 | coords[pointerIndex].setAxisValue(AMOTION_EVENT_AXIS_X, entry.positions[pointerId].x); |
| 172 | coords[pointerIndex].setAxisValue(AMOTION_EVENT_AXIS_Y, entry.positions[pointerId].y); |
| 173 | |
| 174 | properties[pointerIndex].id = pointerId; |
| 175 | properties[pointerIndex].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 176 | pointerIndex++; |
| 177 | } |
| 178 | EXPECT_EQ(pointerIndex, pointerCount); |
| 179 | |
| 180 | MotionEvent event; |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 181 | ui::Transform identityTransform; |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 182 | event.initialize(InputEvent::nextId(), 0 /*deviceId*/, AINPUT_SOURCE_TOUCHSCREEN, |
| 183 | DISPLAY_ID, INVALID_HMAC, action, 0 /*actionButton*/, 0 /*flags*/, |
| 184 | AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, 0 /*buttonState*/, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 185 | MotionClassification::NONE, identityTransform, 0 /*xPrecision*/, |
| 186 | 0 /*yPrecision*/, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 187 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0 /*downTime*/, |
Evan Rosky | 0957669 | 2021-07-01 12:22:09 -0700 | [diff] [blame] | 188 | entry.eventTime.count(), pointerCount, properties, coords); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 189 | |
| 190 | events.emplace_back(event); |
| 191 | } |
| 192 | |
| 193 | return events; |
| 194 | } |
| 195 | |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 196 | static void computeAndCheckVelocity(const VelocityTracker::Strategy strategy, |
| 197 | const std::vector<MotionEventEntry>& motions, int32_t axis, |
| 198 | float targetVelocity) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 199 | VelocityTracker vt(strategy); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 200 | float Vx, Vy; |
| 201 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 202 | std::vector<MotionEvent> events = createMotionEventStream(motions); |
| 203 | for (MotionEvent event : events) { |
| 204 | vt.addMovement(&event); |
| 205 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 206 | |
| 207 | vt.getVelocity(DEFAULT_POINTER_ID, &Vx, &Vy); |
| 208 | |
| 209 | switch (axis) { |
| 210 | case AMOTION_EVENT_AXIS_X: |
| 211 | checkVelocity(Vx, targetVelocity); |
| 212 | break; |
| 213 | case AMOTION_EVENT_AXIS_Y: |
| 214 | checkVelocity(Vy, targetVelocity); |
| 215 | break; |
| 216 | default: |
| 217 | FAIL() << "Axis must be either AMOTION_EVENT_AXIS_X or AMOTION_EVENT_AXIS_Y"; |
| 218 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 221 | static void computeAndCheckQuadraticEstimate(const std::vector<MotionEventEntry>& motions, |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 222 | const std::array<float, 3>& coefficients) { |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 223 | VelocityTracker vt(VelocityTracker::Strategy::LSQ2); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 224 | std::vector<MotionEvent> events = createMotionEventStream(motions); |
| 225 | for (MotionEvent event : events) { |
| 226 | vt.addMovement(&event); |
| 227 | } |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 228 | VelocityTracker::Estimator estimator; |
| 229 | EXPECT_TRUE(vt.getEstimator(0, &estimator)); |
| 230 | for (size_t i = 0; i< coefficients.size(); i++) { |
| 231 | checkCoefficient(estimator.xCoeff[i], coefficients[i]); |
| 232 | checkCoefficient(estimator.yCoeff[i], coefficients[i]); |
| 233 | } |
| 234 | } |
| 235 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 236 | /* |
| 237 | * ================== VelocityTracker tests generated manually ===================================== |
| 238 | */ |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 239 | TEST_F(VelocityTrackerTest, ThreePointsPositiveVelocityTest) { |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 240 | // Same coordinate is reported 2 times in a row |
| 241 | // It is difficult to determine the correct answer here, but at least the direction |
| 242 | // of the reported velocity should be positive. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 243 | std::vector<MotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 244 | {0ms, {{273, 0}}}, |
| 245 | {12585us, {{293, 0}}}, |
| 246 | {14730us, {{293, 0}}}, |
| 247 | {14730us, {{293, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 248 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 249 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 250 | 1600); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | TEST_F(VelocityTrackerTest, ThreePointsZeroVelocityTest) { |
| 254 | // Same coordinate is reported 3 times in a row |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 255 | std::vector<MotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 256 | {0ms, {{293, 0}}}, |
| 257 | {6132us, {{293, 0}}}, |
| 258 | {11283us, {{293, 0}}}, |
| 259 | {11283us, {{293, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 260 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 261 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 262 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | TEST_F(VelocityTrackerTest, ThreePointsLinearVelocityTest) { |
| 266 | // Fixed velocity at 5 points per 10 milliseconds |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 267 | std::vector<MotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 268 | {0ms, {{0, 0}}}, {10ms, {{5, 0}}}, {20ms, {{10, 0}}}, {20ms, {{10, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 269 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 270 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 500); |
| 271 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 500); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | |
| 275 | /** |
| 276 | * ================== VelocityTracker tests generated by recording real events ===================== |
| 277 | * |
| 278 | * To add a test, record the input coordinates and event times to all calls |
| 279 | * to void VelocityTracker::addMovement(const MotionEvent* event). |
| 280 | * Also record all calls to VelocityTracker::clear(). |
| 281 | * Finally, record the output of VelocityTracker::getVelocity(...) |
| 282 | * This will give you the necessary data to create a new test. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 283 | * |
| 284 | * Another good way to generate this data is to use 'dumpsys input' just after the event has |
| 285 | * occurred. |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 286 | */ |
| 287 | |
| 288 | // --------------- Recorded by hand on swordfish --------------------------------------------------- |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 289 | TEST_F(VelocityTrackerTest, SwordfishFlingDown) { |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 290 | // Recording of a fling on Swordfish that could cause a fling in the wrong direction |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 291 | std::vector<MotionEventEntry> motions = { |
| 292 | { 0ms, {{271, 96}} }, |
| 293 | { 16071042ns, {{269.786346, 106.922775}} }, |
| 294 | { 35648403ns, {{267.983063, 156.660034}} }, |
| 295 | { 52313925ns, {{262.638397, 220.339081}} }, |
| 296 | { 68976522ns, {{266.138824, 331.581116}} }, |
| 297 | { 85639375ns, {{274.79245, 428.113159}} }, |
| 298 | { 96948871ns, {{274.79245, 428.113159}} }, |
| 299 | { 96948871ns, {{274.79245, 428.113159}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 300 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 301 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 302 | 623.577637); |
| 303 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 304 | 5970.7309); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // --------------- Recorded by hand on sailfish, generated by a script ----------------------------- |
| 308 | // For some of these tests, the X-direction velocity checking has been removed, because the lsq2 |
| 309 | // and the impulse VelocityTrackerStrategies did not agree within 20%. |
| 310 | // Since the flings were recorded in the Y-direction, the intentional user action should only |
| 311 | // be relevant for the Y axis. |
| 312 | // There have been also cases where lsq2 and impulse disagreed more than 20% in the Y-direction. |
| 313 | // Those recordings have been discarded because we didn't feel one strategy's interpretation was |
| 314 | // more correct than another's but didn't want to increase the tolerance for the entire test suite. |
| 315 | // |
| 316 | // There are 18 tests total below: 9 in the positive Y direction and 9 in the opposite. |
| 317 | // The recordings were loosely binned into 3 categories - slow, faster, and fast, which roughly |
| 318 | // characterizes the velocity of the finger motion. |
| 319 | // These can be treated approximately as: |
| 320 | // slow - less than 1 page gets scrolled |
| 321 | // faster - more than 1 page gets scrolled, but less than 3 |
| 322 | // fast - entire list is scrolled (fling is done as hard as possible) |
| 323 | |
| 324 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow1) { |
| 325 | // Sailfish - fling up - slow - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 326 | std::vector<MotionEventEntry> motions = { |
| 327 | { 235089067457000ns, {{528.00, 983.00}} }, |
| 328 | { 235089084684000ns, {{527.00, 981.00}} }, |
| 329 | { 235089093349000ns, {{527.00, 977.00}} }, |
| 330 | { 235089095677625ns, {{527.00, 975.93}} }, |
| 331 | { 235089101859000ns, {{527.00, 970.00}} }, |
| 332 | { 235089110378000ns, {{528.00, 960.00}} }, |
| 333 | { 235089112497111ns, {{528.25, 957.51}} }, |
| 334 | { 235089118760000ns, {{531.00, 946.00}} }, |
| 335 | { 235089126686000ns, {{535.00, 931.00}} }, |
| 336 | { 235089129316820ns, {{536.33, 926.02}} }, |
| 337 | { 235089135199000ns, {{540.00, 914.00}} }, |
| 338 | { 235089144297000ns, {{546.00, 896.00}} }, |
| 339 | { 235089146136443ns, {{547.21, 892.36}} }, |
| 340 | { 235089152923000ns, {{553.00, 877.00}} }, |
| 341 | { 235089160784000ns, {{559.00, 851.00}} }, |
| 342 | { 235089162955851ns, {{560.66, 843.82}} }, |
| 343 | { 235089162955851ns, {{560.66, 843.82}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 344 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 345 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 346 | 872.794617); |
| 347 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 348 | 951.698181); |
| 349 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 350 | -3604.819336); |
| 351 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 352 | -3044.966064); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | |
| 356 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow2) { |
| 357 | // Sailfish - fling up - slow - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 358 | std::vector<MotionEventEntry> motions = { |
| 359 | { 235110560704000ns, {{522.00, 1107.00}} }, |
| 360 | { 235110575764000ns, {{522.00, 1107.00}} }, |
| 361 | { 235110584385000ns, {{522.00, 1107.00}} }, |
| 362 | { 235110588421179ns, {{521.52, 1106.52}} }, |
| 363 | { 235110592830000ns, {{521.00, 1106.00}} }, |
| 364 | { 235110601385000ns, {{520.00, 1104.00}} }, |
| 365 | { 235110605088160ns, {{519.14, 1102.27}} }, |
| 366 | { 235110609952000ns, {{518.00, 1100.00}} }, |
| 367 | { 235110618353000ns, {{517.00, 1093.00}} }, |
| 368 | { 235110621755146ns, {{516.60, 1090.17}} }, |
| 369 | { 235110627010000ns, {{517.00, 1081.00}} }, |
| 370 | { 235110634785000ns, {{518.00, 1063.00}} }, |
| 371 | { 235110638422450ns, {{518.87, 1052.58}} }, |
| 372 | { 235110643161000ns, {{520.00, 1039.00}} }, |
| 373 | { 235110651767000ns, {{524.00, 1011.00}} }, |
| 374 | { 235110655089581ns, {{525.54, 1000.19}} }, |
| 375 | { 235110660368000ns, {{530.00, 980.00}} }, |
| 376 | { 235110660368000ns, {{530.00, 980.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 377 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 378 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 379 | -4096.583008); |
| 380 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 381 | -3455.094238); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | |
| 385 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow3) { |
| 386 | // Sailfish - fling up - slow - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 387 | std::vector<MotionEventEntry> motions = { |
| 388 | { 792536237000ns, {{580.00, 1317.00}} }, |
| 389 | { 792541538987ns, {{580.63, 1311.94}} }, |
| 390 | { 792544613000ns, {{581.00, 1309.00}} }, |
| 391 | { 792552301000ns, {{583.00, 1295.00}} }, |
| 392 | { 792558362309ns, {{585.13, 1282.92}} }, |
| 393 | { 792560828000ns, {{586.00, 1278.00}} }, |
| 394 | { 792569446000ns, {{589.00, 1256.00}} }, |
| 395 | { 792575185095ns, {{591.54, 1241.41}} }, |
| 396 | { 792578491000ns, {{593.00, 1233.00}} }, |
| 397 | { 792587044000ns, {{597.00, 1211.00}} }, |
| 398 | { 792592008172ns, {{600.28, 1195.92}} }, |
| 399 | { 792594616000ns, {{602.00, 1188.00}} }, |
| 400 | { 792603129000ns, {{607.00, 1167.00}} }, |
| 401 | { 792608831290ns, {{609.48, 1155.83}} }, |
| 402 | { 792612321000ns, {{611.00, 1149.00}} }, |
| 403 | { 792620768000ns, {{615.00, 1131.00}} }, |
| 404 | { 792625653873ns, {{617.32, 1121.73}} }, |
| 405 | { 792629200000ns, {{619.00, 1115.00}} }, |
| 406 | { 792629200000ns, {{619.00, 1115.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 407 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 408 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 409 | 574.33429); |
| 410 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 411 | 617.40564); |
| 412 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 413 | -2361.982666); |
| 414 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 415 | -2500.055664); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | |
| 419 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster1) { |
| 420 | // Sailfish - fling up - faster - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 421 | std::vector<MotionEventEntry> motions = { |
| 422 | { 235160420675000ns, {{610.00, 1042.00}} }, |
| 423 | { 235160428220000ns, {{609.00, 1026.00}} }, |
| 424 | { 235160436544000ns, {{609.00, 1024.00}} }, |
| 425 | { 235160441852394ns, {{609.64, 1020.82}} }, |
| 426 | { 235160444878000ns, {{610.00, 1019.00}} }, |
| 427 | { 235160452673000ns, {{613.00, 1006.00}} }, |
| 428 | { 235160458519743ns, {{617.18, 992.06}} }, |
| 429 | { 235160461061000ns, {{619.00, 986.00}} }, |
| 430 | { 235160469798000ns, {{627.00, 960.00}} }, |
| 431 | { 235160475186713ns, {{632.22, 943.02}} }, |
| 432 | { 235160478051000ns, {{635.00, 934.00}} }, |
| 433 | { 235160486489000ns, {{644.00, 906.00}} }, |
| 434 | { 235160491853697ns, {{649.56, 890.56}} }, |
| 435 | { 235160495177000ns, {{653.00, 881.00}} }, |
| 436 | { 235160504148000ns, {{662.00, 858.00}} }, |
| 437 | { 235160509231495ns, {{666.81, 845.37}} }, |
| 438 | { 235160512603000ns, {{670.00, 837.00}} }, |
| 439 | { 235160520366000ns, {{679.00, 814.00}} }, |
| 440 | { 235160520366000ns, {{679.00, 814.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 441 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 442 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 443 | 1274.141724); |
| 444 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 445 | 1438.53186); |
| 446 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 447 | -3001.4348); |
| 448 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 449 | -3695.859619); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
| 453 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster2) { |
| 454 | // Sailfish - fling up - faster - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 455 | std::vector<MotionEventEntry> motions = { |
| 456 | { 847153808000ns, {{576.00, 1264.00}} }, |
| 457 | { 847171174000ns, {{576.00, 1262.00}} }, |
| 458 | { 847179640000ns, {{576.00, 1257.00}} }, |
| 459 | { 847185187540ns, {{577.41, 1249.22}} }, |
| 460 | { 847187487000ns, {{578.00, 1246.00}} }, |
| 461 | { 847195710000ns, {{581.00, 1227.00}} }, |
| 462 | { 847202027059ns, {{583.93, 1209.40}} }, |
| 463 | { 847204324000ns, {{585.00, 1203.00}} }, |
| 464 | { 847212672000ns, {{590.00, 1176.00}} }, |
| 465 | { 847218861395ns, {{594.36, 1157.11}} }, |
| 466 | { 847221190000ns, {{596.00, 1150.00}} }, |
| 467 | { 847230484000ns, {{602.00, 1124.00}} }, |
| 468 | { 847235701400ns, {{607.56, 1103.83}} }, |
| 469 | { 847237986000ns, {{610.00, 1095.00}} }, |
| 470 | { 847237986000ns, {{610.00, 1095.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 471 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 472 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 473 | -4280.07959); |
| 474 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 475 | -4241.004395); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | |
| 479 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster3) { |
| 480 | // Sailfish - fling up - faster - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 481 | std::vector<MotionEventEntry> motions = { |
| 482 | { 235200532789000ns, {{507.00, 1084.00}} }, |
| 483 | { 235200549221000ns, {{507.00, 1083.00}} }, |
| 484 | { 235200557841000ns, {{507.00, 1081.00}} }, |
| 485 | { 235200558051189ns, {{507.00, 1080.95}} }, |
| 486 | { 235200566314000ns, {{507.00, 1078.00}} }, |
| 487 | { 235200574876586ns, {{508.97, 1070.12}} }, |
| 488 | { 235200575006000ns, {{509.00, 1070.00}} }, |
| 489 | { 235200582900000ns, {{514.00, 1054.00}} }, |
| 490 | { 235200591276000ns, {{525.00, 1023.00}} }, |
| 491 | { 235200591701829ns, {{525.56, 1021.42}} }, |
| 492 | { 235200600064000ns, {{542.00, 976.00}} }, |
| 493 | { 235200608519000ns, {{563.00, 911.00}} }, |
| 494 | { 235200608527086ns, {{563.02, 910.94}} }, |
| 495 | { 235200616933000ns, {{590.00, 844.00}} }, |
| 496 | { 235200616933000ns, {{590.00, 844.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 497 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 498 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 499 | -8715.686523); |
| 500 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 501 | -7639.026367); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | |
| 505 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast1) { |
| 506 | // Sailfish - fling up - fast - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 507 | std::vector<MotionEventEntry> motions = { |
| 508 | { 920922149000ns, {{561.00, 1412.00}} }, |
| 509 | { 920930185000ns, {{559.00, 1377.00}} }, |
| 510 | { 920930262463ns, {{558.98, 1376.66}} }, |
| 511 | { 920938547000ns, {{559.00, 1371.00}} }, |
| 512 | { 920947096857ns, {{562.91, 1342.68}} }, |
| 513 | { 920947302000ns, {{563.00, 1342.00}} }, |
| 514 | { 920955502000ns, {{577.00, 1272.00}} }, |
| 515 | { 920963931021ns, {{596.87, 1190.54}} }, |
| 516 | { 920963987000ns, {{597.00, 1190.00}} }, |
| 517 | { 920972530000ns, {{631.00, 1093.00}} }, |
| 518 | { 920980765511ns, {{671.31, 994.68}} }, |
| 519 | { 920980906000ns, {{672.00, 993.00}} }, |
| 520 | { 920989261000ns, {{715.00, 903.00}} }, |
| 521 | { 920989261000ns, {{715.00, 903.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 522 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 523 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 524 | 5670.329102); |
| 525 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 526 | 5991.866699); |
| 527 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 528 | -13021.101562); |
| 529 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 530 | -15093.995117); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | |
| 534 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast2) { |
| 535 | // Sailfish - fling up - fast - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 536 | std::vector<MotionEventEntry> motions = { |
| 537 | { 235247153233000ns, {{518.00, 1168.00}} }, |
| 538 | { 235247170452000ns, {{517.00, 1167.00}} }, |
| 539 | { 235247178908000ns, {{515.00, 1159.00}} }, |
| 540 | { 235247179556213ns, {{514.85, 1158.39}} }, |
| 541 | { 235247186821000ns, {{515.00, 1125.00}} }, |
| 542 | { 235247195265000ns, {{521.00, 1051.00}} }, |
| 543 | { 235247196389476ns, {{521.80, 1041.15}} }, |
| 544 | { 235247203649000ns, {{538.00, 932.00}} }, |
| 545 | { 235247212253000ns, {{571.00, 794.00}} }, |
| 546 | { 235247213222491ns, {{574.72, 778.45}} }, |
| 547 | { 235247220736000ns, {{620.00, 641.00}} }, |
| 548 | { 235247220736000ns, {{620.00, 641.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 549 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 550 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 551 | -20286.958984); |
| 552 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 553 | -20494.587891); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | |
| 557 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast3) { |
| 558 | // Sailfish - fling up - fast - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 559 | std::vector<MotionEventEntry> motions = { |
| 560 | { 235302568736000ns, {{529.00, 1167.00}} }, |
| 561 | { 235302576644000ns, {{523.00, 1140.00}} }, |
| 562 | { 235302579395063ns, {{520.91, 1130.61}} }, |
| 563 | { 235302585140000ns, {{522.00, 1130.00}} }, |
| 564 | { 235302593615000ns, {{527.00, 1065.00}} }, |
| 565 | { 235302596207444ns, {{528.53, 1045.12}} }, |
| 566 | { 235302602102000ns, {{559.00, 872.00}} }, |
| 567 | { 235302610545000ns, {{652.00, 605.00}} }, |
| 568 | { 235302613019881ns, {{679.26, 526.73}} }, |
| 569 | { 235302613019881ns, {{679.26, 526.73}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 570 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 571 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 572 | -39295.941406); |
| 573 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 574 | -36461.421875); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | |
| 578 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow1) { |
| 579 | // Sailfish - fling down - slow - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 580 | std::vector<MotionEventEntry> motions = { |
| 581 | { 235655749552755ns, {{582.00, 432.49}} }, |
| 582 | { 235655750638000ns, {{582.00, 433.00}} }, |
| 583 | { 235655758865000ns, {{582.00, 440.00}} }, |
| 584 | { 235655766221523ns, {{581.16, 448.43}} }, |
| 585 | { 235655767594000ns, {{581.00, 450.00}} }, |
| 586 | { 235655776044000ns, {{580.00, 462.00}} }, |
| 587 | { 235655782890696ns, {{579.18, 474.35}} }, |
| 588 | { 235655784360000ns, {{579.00, 477.00}} }, |
| 589 | { 235655792795000ns, {{578.00, 496.00}} }, |
| 590 | { 235655799559531ns, {{576.27, 515.04}} }, |
| 591 | { 235655800612000ns, {{576.00, 518.00}} }, |
| 592 | { 235655809535000ns, {{574.00, 542.00}} }, |
| 593 | { 235655816988015ns, {{572.17, 564.86}} }, |
| 594 | { 235655817685000ns, {{572.00, 567.00}} }, |
| 595 | { 235655825981000ns, {{569.00, 595.00}} }, |
| 596 | { 235655833808653ns, {{566.26, 620.60}} }, |
| 597 | { 235655834541000ns, {{566.00, 623.00}} }, |
| 598 | { 235655842893000ns, {{563.00, 649.00}} }, |
| 599 | { 235655842893000ns, {{563.00, 649.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 600 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 601 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 602 | -419.749695); |
| 603 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 604 | -398.303894); |
| 605 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 606 | 3309.016357); |
| 607 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 608 | 3969.099854); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | |
| 612 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow2) { |
| 613 | // Sailfish - fling down - slow - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 614 | std::vector<MotionEventEntry> motions = { |
| 615 | { 235671152083370ns, {{485.24, 558.28}} }, |
| 616 | { 235671154126000ns, {{485.00, 559.00}} }, |
| 617 | { 235671162497000ns, {{484.00, 566.00}} }, |
| 618 | { 235671168750511ns, {{483.27, 573.29}} }, |
| 619 | { 235671171071000ns, {{483.00, 576.00}} }, |
| 620 | { 235671179390000ns, {{482.00, 588.00}} }, |
| 621 | { 235671185417210ns, {{481.31, 598.98}} }, |
| 622 | { 235671188173000ns, {{481.00, 604.00}} }, |
| 623 | { 235671196371000ns, {{480.00, 624.00}} }, |
| 624 | { 235671202084196ns, {{479.27, 639.98}} }, |
| 625 | { 235671204235000ns, {{479.00, 646.00}} }, |
| 626 | { 235671212554000ns, {{478.00, 673.00}} }, |
| 627 | { 235671219471011ns, {{476.39, 697.12}} }, |
| 628 | { 235671221159000ns, {{476.00, 703.00}} }, |
| 629 | { 235671229592000ns, {{474.00, 734.00}} }, |
| 630 | { 235671236281462ns, {{472.43, 758.38}} }, |
| 631 | { 235671238098000ns, {{472.00, 765.00}} }, |
| 632 | { 235671246532000ns, {{470.00, 799.00}} }, |
| 633 | { 235671246532000ns, {{470.00, 799.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 634 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 635 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 636 | -262.80426); |
| 637 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 638 | -243.665344); |
| 639 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 640 | 4215.682129); |
| 641 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 642 | 4587.986816); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | |
| 646 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow3) { |
| 647 | // Sailfish - fling down - slow - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 648 | std::vector<MotionEventEntry> motions = { |
| 649 | { 170983201000ns, {{557.00, 533.00}} }, |
| 650 | { 171000668000ns, {{556.00, 534.00}} }, |
| 651 | { 171007359750ns, {{554.73, 535.27}} }, |
| 652 | { 171011197000ns, {{554.00, 536.00}} }, |
| 653 | { 171017660000ns, {{552.00, 540.00}} }, |
| 654 | { 171024201831ns, {{549.97, 544.73}} }, |
| 655 | { 171027333000ns, {{549.00, 547.00}} }, |
| 656 | { 171034603000ns, {{545.00, 557.00}} }, |
| 657 | { 171041043371ns, {{541.98, 567.55}} }, |
| 658 | { 171043147000ns, {{541.00, 571.00}} }, |
| 659 | { 171051052000ns, {{536.00, 586.00}} }, |
| 660 | { 171051052000ns, {{536.00, 586.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 661 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 662 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 663 | -723.413513); |
| 664 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 665 | -651.038452); |
| 666 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 667 | 2091.502441); |
| 668 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 669 | 1934.517456); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | |
| 673 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster1) { |
| 674 | // Sailfish - fling down - faster - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 675 | std::vector<MotionEventEntry> motions = { |
| 676 | { 235695280333000ns, {{558.00, 451.00}} }, |
| 677 | { 235695283971237ns, {{558.43, 454.45}} }, |
| 678 | { 235695289038000ns, {{559.00, 462.00}} }, |
| 679 | { 235695297388000ns, {{561.00, 478.00}} }, |
| 680 | { 235695300638465ns, {{561.83, 486.25}} }, |
| 681 | { 235695305265000ns, {{563.00, 498.00}} }, |
| 682 | { 235695313591000ns, {{564.00, 521.00}} }, |
| 683 | { 235695317305492ns, {{564.43, 532.68}} }, |
| 684 | { 235695322181000ns, {{565.00, 548.00}} }, |
| 685 | { 235695330709000ns, {{565.00, 577.00}} }, |
| 686 | { 235695333972227ns, {{565.00, 588.10}} }, |
| 687 | { 235695339250000ns, {{565.00, 609.00}} }, |
| 688 | { 235695347839000ns, {{565.00, 642.00}} }, |
| 689 | { 235695351313257ns, {{565.00, 656.18}} }, |
| 690 | { 235695356412000ns, {{565.00, 677.00}} }, |
| 691 | { 235695364899000ns, {{563.00, 710.00}} }, |
| 692 | { 235695368118682ns, {{562.24, 722.52}} }, |
| 693 | { 235695373403000ns, {{564.00, 744.00}} }, |
| 694 | { 235695373403000ns, {{564.00, 744.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 695 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 696 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 697 | 4254.639648); |
| 698 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 699 | 4698.415039); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | |
| 703 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster2) { |
| 704 | // Sailfish - fling down - faster - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 705 | std::vector<MotionEventEntry> motions = { |
| 706 | { 235709624766000ns, {{535.00, 579.00}} }, |
| 707 | { 235709642256000ns, {{534.00, 580.00}} }, |
| 708 | { 235709643350278ns, {{533.94, 580.06}} }, |
| 709 | { 235709650760000ns, {{532.00, 584.00}} }, |
| 710 | { 235709658615000ns, {{530.00, 593.00}} }, |
| 711 | { 235709660170495ns, {{529.60, 594.78}} }, |
| 712 | { 235709667095000ns, {{527.00, 606.00}} }, |
| 713 | { 235709675616000ns, {{524.00, 628.00}} }, |
| 714 | { 235709676983261ns, {{523.52, 631.53}} }, |
| 715 | { 235709684289000ns, {{521.00, 652.00}} }, |
| 716 | { 235709692763000ns, {{518.00, 682.00}} }, |
| 717 | { 235709693804993ns, {{517.63, 685.69}} }, |
| 718 | { 235709701438000ns, {{515.00, 709.00}} }, |
| 719 | { 235709709830000ns, {{512.00, 739.00}} }, |
| 720 | { 235709710626776ns, {{511.72, 741.85}} }, |
| 721 | { 235709710626776ns, {{511.72, 741.85}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 722 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 723 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 724 | -430.440247); |
| 725 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 726 | -447.600311); |
| 727 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 728 | 3953.859375); |
| 729 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 730 | 4316.155273); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | |
| 734 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster3) { |
| 735 | // Sailfish - fling down - faster - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 736 | std::vector<MotionEventEntry> motions = { |
| 737 | { 235727628927000ns, {{540.00, 440.00}} }, |
| 738 | { 235727636810000ns, {{537.00, 454.00}} }, |
| 739 | { 235727646176000ns, {{536.00, 454.00}} }, |
| 740 | { 235727653586628ns, {{535.12, 456.65}} }, |
| 741 | { 235727654557000ns, {{535.00, 457.00}} }, |
| 742 | { 235727663024000ns, {{534.00, 465.00}} }, |
| 743 | { 235727670410103ns, {{533.04, 479.45}} }, |
| 744 | { 235727670691000ns, {{533.00, 480.00}} }, |
| 745 | { 235727679255000ns, {{531.00, 501.00}} }, |
| 746 | { 235727687233704ns, {{529.09, 526.73}} }, |
| 747 | { 235727687628000ns, {{529.00, 528.00}} }, |
| 748 | { 235727696113000ns, {{526.00, 558.00}} }, |
| 749 | { 235727704057546ns, {{523.18, 588.98}} }, |
| 750 | { 235727704576000ns, {{523.00, 591.00}} }, |
| 751 | { 235727713099000ns, {{520.00, 626.00}} }, |
| 752 | { 235727720880776ns, {{516.33, 655.36}} }, |
| 753 | { 235727721580000ns, {{516.00, 658.00}} }, |
| 754 | { 235727721580000ns, {{516.00, 658.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 755 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 756 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 757 | 4484.617676); |
| 758 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 759 | 4927.92627); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | |
| 763 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast1) { |
| 764 | // Sailfish - fling down - fast - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 765 | std::vector<MotionEventEntry> motions = { |
| 766 | { 235762352849000ns, {{467.00, 286.00}} }, |
| 767 | { 235762360250000ns, {{443.00, 344.00}} }, |
| 768 | { 235762362787412ns, {{434.77, 363.89}} }, |
| 769 | { 235762368807000ns, {{438.00, 359.00}} }, |
| 770 | { 235762377220000ns, {{425.00, 423.00}} }, |
| 771 | { 235762379608561ns, {{421.31, 441.17}} }, |
| 772 | { 235762385698000ns, {{412.00, 528.00}} }, |
| 773 | { 235762394133000ns, {{406.00, 648.00}} }, |
| 774 | { 235762396429369ns, {{404.37, 680.67}} }, |
| 775 | { 235762396429369ns, {{404.37, 680.67}} }, //ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 776 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 777 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 778 | 14227.0224); |
| 779 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 780 | 16064.685547); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | |
| 784 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast2) { |
| 785 | // Sailfish - fling down - fast - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 786 | std::vector<MotionEventEntry> motions = { |
| 787 | { 235772487188000ns, {{576.00, 204.00}} }, |
| 788 | { 235772495159000ns, {{553.00, 236.00}} }, |
| 789 | { 235772503568000ns, {{551.00, 240.00}} }, |
| 790 | { 235772508192247ns, {{545.55, 254.17}} }, |
| 791 | { 235772512051000ns, {{541.00, 266.00}} }, |
| 792 | { 235772520794000ns, {{520.00, 337.00}} }, |
| 793 | { 235772525015263ns, {{508.92, 394.43}} }, |
| 794 | { 235772529174000ns, {{498.00, 451.00}} }, |
| 795 | { 235772537635000ns, {{484.00, 589.00}} }, |
| 796 | { 235772537635000ns, {{484.00, 589.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 797 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 798 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 799 | 18660.048828); |
| 800 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 801 | 16918.439453); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | |
| 805 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast3) { |
| 806 | // Sailfish - fling down - fast - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 807 | std::vector<MotionEventEntry> motions = { |
| 808 | { 507650295000ns, {{628.00, 233.00}} }, |
| 809 | { 507658234000ns, {{605.00, 269.00}} }, |
| 810 | { 507666784000ns, {{601.00, 274.00}} }, |
| 811 | { 507669660483ns, {{599.65, 275.68}} }, |
| 812 | { 507675427000ns, {{582.00, 308.00}} }, |
| 813 | { 507683740000ns, {{541.00, 404.00}} }, |
| 814 | { 507686506238ns, {{527.36, 435.95}} }, |
| 815 | { 507692220000ns, {{487.00, 581.00}} }, |
| 816 | { 507700707000ns, {{454.00, 792.00}} }, |
| 817 | { 507703352649ns, {{443.71, 857.77}} }, |
| 818 | { 507703352649ns, {{443.71, 857.77}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 819 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 820 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 821 | -4111.8173); |
| 822 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 823 | -6388.48877); |
| 824 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 825 | 29765.908203); |
| 826 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 827 | 28354.796875); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 828 | } |
| 829 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 830 | /** |
| 831 | * ================== Multiple pointers ============================================================ |
| 832 | * |
| 833 | * Three fingers quickly tap the screen. Since this is a tap, the velocities should be zero. |
| 834 | * If the events with POINTER_UP or POINTER_DOWN are not handled correctly (these should not be |
| 835 | * part of the fitted data), this can cause large velocity values to be reported instead. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 836 | */ |
Siarhei Vishniakou | 346ac6a | 2019-04-10 09:58:05 -0700 | [diff] [blame] | 837 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_ThreeFingerTap) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 838 | std::vector<MotionEventEntry> motions = { |
| 839 | { 0us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} }, |
| 840 | { 10800us, {{1063, 1128}, {682, 1318}, {NAN, NAN}} }, // POINTER_DOWN |
| 841 | { 10800us, {{1063, 1128}, {682, 1318}, {397, 1747}} }, // POINTER_DOWN |
| 842 | { 267300us, {{1063, 1128}, {682, 1318}, {397, 1747}} }, // POINTER_UP |
| 843 | { 267300us, {{1063, 1128}, {NAN, NAN}, {397, 1747}} }, // POINTER_UP |
| 844 | { 272700us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} }, |
| 845 | }; |
| 846 | |
Siarhei Vishniakou | 346ac6a | 2019-04-10 09:58:05 -0700 | [diff] [blame] | 847 | // Velocity should actually be zero, but we expect 0.016 here instead. |
| 848 | // This is close enough to zero, and is likely caused by division by a very small number. |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 849 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, -0.016); |
| 850 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, -0.016); |
| 851 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 852 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, 0); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /** |
| 856 | * ================== Tests for least squares fitting ============================================== |
| 857 | * |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 858 | * Special care must be taken when constructing tests for LeastSquaresVelocityTrackerStrategy |
| 859 | * getEstimator function. In particular: |
| 860 | * - inside the function, time gets converted from nanoseconds to seconds |
| 861 | * before being used in the fit. |
| 862 | * - any values that are older than 100 ms are being discarded. |
| 863 | * - the newest time gets subtracted from all of the other times before being used in the fit. |
| 864 | * So these tests have to be designed with those limitations in mind. |
| 865 | * |
| 866 | * General approach for the tests below: |
| 867 | * We only used timestamps in milliseconds, 0 ms, 1 ms, and 2 ms, to be sure that |
| 868 | * we are well within the HORIZON range. |
| 869 | * When specifying the expected values of the coefficients, we treat the x values as if |
| 870 | * they were in ms. Then, to adjust for the time units, the coefficients get progressively |
| 871 | * multiplied by powers of 1E3. |
| 872 | * For example: |
| 873 | * data: t(ms), x |
| 874 | * 1 ms, 1 |
| 875 | * 2 ms, 4 |
| 876 | * 3 ms, 9 |
| 877 | * The coefficients are (0, 0, 1). |
| 878 | * In the test, we would convert these coefficients to (0*(1E3)^0, 0*(1E3)^1, 1*(1E3)^2). |
| 879 | */ |
| 880 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Constant) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 881 | std::vector<MotionEventEntry> motions = { |
| 882 | { 0ms, {{1, 1}} }, // 0 s |
| 883 | { 1ms, {{1, 1}} }, // 0.001 s |
| 884 | { 2ms, {{1, 1}} }, // 0.002 s |
| 885 | { 2ms, {{1, 1}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 886 | }; |
| 887 | // The data used for the fit will be as follows: |
| 888 | // time(s), position |
| 889 | // -0.002, 1 |
| 890 | // -0.001, 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 891 | // -0.ms, 1 |
| 892 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({1, 0, 0})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | /* |
| 896 | * Straight line y = x :: the constant and quadratic coefficients are zero. |
| 897 | */ |
| 898 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Linear) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 899 | std::vector<MotionEventEntry> motions = { |
| 900 | { 0ms, {{-2, -2}} }, |
| 901 | { 1ms, {{-1, -1}} }, |
| 902 | { 2ms, {{-0, -0}} }, |
| 903 | { 2ms, {{-0, -0}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 904 | }; |
| 905 | // The data used for the fit will be as follows: |
| 906 | // time(s), position |
| 907 | // -0.002, -2 |
| 908 | // -0.001, -1 |
| 909 | // -0.000, 0 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 910 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({0, 1E3, 0})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /* |
| 914 | * Parabola |
| 915 | */ |
| 916 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 917 | std::vector<MotionEventEntry> motions = { |
| 918 | { 0ms, {{1, 1}} }, |
| 919 | { 1ms, {{4, 4}} }, |
| 920 | { 2ms, {{8, 8}} }, |
| 921 | { 2ms, {{8, 8}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 922 | }; |
| 923 | // The data used for the fit will be as follows: |
| 924 | // time(s), position |
| 925 | // -0.002, 1 |
| 926 | // -0.001, 4 |
| 927 | // -0.000, 8 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 928 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({8, 4.5E3, 0.5E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /* |
| 932 | * Parabola |
| 933 | */ |
| 934 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic2) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 935 | std::vector<MotionEventEntry> motions = { |
| 936 | { 0ms, {{1, 1}} }, |
| 937 | { 1ms, {{4, 4}} }, |
| 938 | { 2ms, {{9, 9}} }, |
| 939 | { 2ms, {{9, 9}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 940 | }; |
| 941 | // The data used for the fit will be as follows: |
| 942 | // time(s), position |
| 943 | // -0.002, 1 |
| 944 | // -0.001, 4 |
| 945 | // -0.000, 9 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 946 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({9, 6E3, 1E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /* |
| 950 | * Parabola :: y = x^2 :: the constant and linear coefficients are zero. |
| 951 | */ |
| 952 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic3) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 953 | std::vector<MotionEventEntry> motions = { |
| 954 | { 0ms, {{4, 4}} }, |
| 955 | { 1ms, {{1, 1}} }, |
| 956 | { 2ms, {{0, 0}} }, |
| 957 | { 2ms, {{0, 0}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 958 | }; |
| 959 | // The data used for the fit will be as follows: |
| 960 | // time(s), position |
| 961 | // -0.002, 4 |
| 962 | // -0.001, 1 |
| 963 | // -0.000, 0 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 964 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({0, 0E3, 1E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 965 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 966 | |
| 967 | } // namespace android |