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 | |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 19 | #include <math.h> |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 20 | #include <array> |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 21 | #include <chrono> |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 22 | #include <limits> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 23 | |
| 24 | #include <android-base/stringprintf.h> |
chaviw | 09c8d2d | 2020-08-24 15:48:26 -0700 | [diff] [blame] | 25 | #include <attestation/HmacKeyManager.h> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 26 | #include <gtest/gtest.h> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 27 | #include <gui/constants.h> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 28 | #include <input/VelocityTracker.h> |
| 29 | |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 30 | using std::literals::chrono_literals::operator""ms; |
| 31 | using std::literals::chrono_literals::operator""ns; |
| 32 | using std::literals::chrono_literals::operator""us; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 33 | using android::base::StringPrintf; |
| 34 | |
| 35 | namespace android { |
| 36 | |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 37 | constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; // default display id |
| 38 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 39 | constexpr int32_t DEFAULT_POINTER_ID = 0; // pointer ID used for manually defined tests |
| 40 | |
| 41 | // velocity must be in the range (1-tol)*EV <= velocity <= (1+tol)*EV |
| 42 | // here EV = expected value, tol = VELOCITY_TOLERANCE |
| 43 | constexpr float VELOCITY_TOLERANCE = 0.2; |
| 44 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 45 | // estimate coefficients must be within 0.001% of the target value |
| 46 | constexpr float COEFFICIENT_TOLERANCE = 0.00001; |
| 47 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 48 | // --- VelocityTrackerTest --- |
| 49 | class VelocityTrackerTest : public testing::Test { }; |
| 50 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Similar to EXPECT_NEAR, but ensures that the difference between the two float values |
| 53 | * is at most a certain fraction of the target value. |
| 54 | * If fraction is zero, require exact match. |
| 55 | */ |
| 56 | static void EXPECT_NEAR_BY_FRACTION(float actual, float target, float fraction) { |
| 57 | float tolerance = fabsf(target * fraction); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 58 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 59 | if (target == 0 && fraction != 0) { |
| 60 | // If target is zero, this would force actual == target, which is too harsh. |
| 61 | // Relax this requirement a little. The value is determined empirically from the |
| 62 | // coefficients computed by the quadratic least squares algorithms. |
| 63 | tolerance = 1E-6; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 64 | } |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 65 | EXPECT_NEAR(actual, target, tolerance); |
| 66 | } |
| 67 | |
| 68 | static void checkVelocity(float Vactual, float Vtarget) { |
| 69 | EXPECT_NEAR_BY_FRACTION(Vactual, Vtarget, VELOCITY_TOLERANCE); |
| 70 | } |
| 71 | |
| 72 | static void checkCoefficient(float actual, float target) { |
| 73 | EXPECT_NEAR_BY_FRACTION(actual, target, COEFFICIENT_TOLERANCE); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 76 | struct Position { |
Siarhei Vishniakou | 01ca486 | 2019-03-06 13:22:13 -0800 | [diff] [blame] | 77 | float x; |
| 78 | float y; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * If both values are NAN, then this is considered to be an empty entry (no pointer data). |
| 82 | * If only one of the values is NAN, this is still a valid entry, |
| 83 | * because we may only care about a single axis. |
| 84 | */ |
| 85 | bool isValid() const { |
| 86 | return !(isnan(x) && isnan(y)); |
| 87 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 90 | struct PlanarMotionEventEntry { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 91 | std::chrono::nanoseconds eventTime; |
| 92 | std::vector<Position> positions; |
| 93 | }; |
| 94 | |
| 95 | static BitSet32 getValidPointers(const std::vector<Position>& positions) { |
| 96 | BitSet32 pointers; |
| 97 | for (size_t i = 0; i < positions.size(); i++) { |
| 98 | if (positions[i].isValid()) { |
| 99 | pointers.markBit(i); |
| 100 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 101 | } |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 102 | return pointers; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 105 | static uint32_t getChangingPointerId(BitSet32 pointers, BitSet32 otherPointers) { |
| 106 | BitSet32 difference(pointers.value ^ otherPointers.value); |
| 107 | uint32_t pointerId = difference.clearFirstMarkedBit(); |
| 108 | EXPECT_EQ(0U, difference.value) << "Only 1 pointer can enter or leave at a time"; |
| 109 | return pointerId; |
| 110 | } |
| 111 | |
| 112 | static int32_t resolveAction(const std::vector<Position>& lastPositions, |
| 113 | const std::vector<Position>& currentPositions, |
| 114 | const std::vector<Position>& nextPositions) { |
| 115 | BitSet32 pointers = getValidPointers(currentPositions); |
| 116 | const uint32_t pointerCount = pointers.count(); |
| 117 | |
| 118 | BitSet32 lastPointers = getValidPointers(lastPositions); |
| 119 | const uint32_t lastPointerCount = lastPointers.count(); |
| 120 | if (lastPointerCount < pointerCount) { |
| 121 | // A new pointer is down |
| 122 | uint32_t pointerId = getChangingPointerId(pointers, lastPointers); |
| 123 | return AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 124 | (pointerId << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
| 125 | } |
| 126 | |
| 127 | BitSet32 nextPointers = getValidPointers(nextPositions); |
| 128 | const uint32_t nextPointerCount = nextPointers.count(); |
| 129 | if (pointerCount > nextPointerCount) { |
| 130 | // An existing pointer is leaving |
| 131 | uint32_t pointerId = getChangingPointerId(pointers, nextPointers); |
| 132 | return AMOTION_EVENT_ACTION_POINTER_UP | |
| 133 | (pointerId << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
| 134 | } |
| 135 | |
| 136 | return AMOTION_EVENT_ACTION_MOVE; |
| 137 | } |
| 138 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 139 | static std::vector<MotionEvent> createAxisScrollMotionEventStream( |
| 140 | const std::vector<std::pair<std::chrono::nanoseconds, float>>& motions) { |
| 141 | std::vector<MotionEvent> events; |
| 142 | for (const auto& [timeStamp, value] : motions) { |
| 143 | EXPECT_TRUE(!isnan(value)) << "The entry at pointerId must be valid"; |
| 144 | |
| 145 | PointerCoords coords[1]; |
| 146 | coords[0].setAxisValue(AMOTION_EVENT_AXIS_SCROLL, value); |
| 147 | |
| 148 | PointerProperties properties[1]; |
| 149 | properties[0].id = DEFAULT_POINTER_ID; |
| 150 | |
| 151 | MotionEvent event; |
| 152 | ui::Transform identityTransform; |
| 153 | event.initialize(InputEvent::nextId(), 5 /*deviceId*/, AINPUT_SOURCE_ROTARY_ENCODER, |
| 154 | ADISPLAY_ID_NONE, INVALID_HMAC, AMOTION_EVENT_ACTION_SCROLL, |
| 155 | 0 /*actionButton*/, 0 /*flags*/, AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, |
| 156 | 0 /*buttonState*/, MotionClassification::NONE, identityTransform, |
| 157 | 0 /*xPrecision*/, 0 /*yPrecision*/, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 158 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0 /*downTime*/, |
| 159 | timeStamp.count(), 1 /*pointerCount*/, properties, coords); |
| 160 | |
| 161 | events.emplace_back(event); |
| 162 | } |
| 163 | |
| 164 | return events; |
| 165 | } |
| 166 | |
| 167 | static std::vector<MotionEvent> createTouchMotionEventStream( |
| 168 | const std::vector<PlanarMotionEventEntry>& motions) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 169 | if (motions.empty()) { |
| 170 | ADD_FAILURE() << "Need at least 1 sample to create a MotionEvent. Received empty vector."; |
| 171 | } |
| 172 | |
| 173 | std::vector<MotionEvent> events; |
| 174 | for (size_t i = 0; i < motions.size(); i++) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 175 | const PlanarMotionEventEntry& entry = motions[i]; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 176 | BitSet32 pointers = getValidPointers(entry.positions); |
| 177 | const uint32_t pointerCount = pointers.count(); |
| 178 | |
| 179 | int32_t action; |
| 180 | if (i == 0) { |
| 181 | action = AMOTION_EVENT_ACTION_DOWN; |
| 182 | EXPECT_EQ(1U, pointerCount) << "First event should only have 1 pointer"; |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 183 | } else if ((i == motions.size() - 1) && pointerCount == 1) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 184 | action = AMOTION_EVENT_ACTION_UP; |
| 185 | } else { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 186 | const PlanarMotionEventEntry& previousEntry = motions[i-1]; |
| 187 | const PlanarMotionEventEntry& nextEntry = motions[i+1]; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 188 | action = resolveAction(previousEntry.positions, entry.positions, nextEntry.positions); |
| 189 | } |
| 190 | |
| 191 | PointerCoords coords[pointerCount]; |
| 192 | PointerProperties properties[pointerCount]; |
| 193 | uint32_t pointerIndex = 0; |
| 194 | while(!pointers.isEmpty()) { |
| 195 | uint32_t pointerId = pointers.clearFirstMarkedBit(); |
| 196 | |
| 197 | coords[pointerIndex].clear(); |
| 198 | // We are treating column positions as pointerId |
| 199 | EXPECT_TRUE(entry.positions[pointerId].isValid()) << |
| 200 | "The entry at pointerId must be valid"; |
| 201 | coords[pointerIndex].setAxisValue(AMOTION_EVENT_AXIS_X, entry.positions[pointerId].x); |
| 202 | coords[pointerIndex].setAxisValue(AMOTION_EVENT_AXIS_Y, entry.positions[pointerId].y); |
| 203 | |
| 204 | properties[pointerIndex].id = pointerId; |
| 205 | properties[pointerIndex].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 206 | pointerIndex++; |
| 207 | } |
| 208 | EXPECT_EQ(pointerIndex, pointerCount); |
| 209 | |
| 210 | MotionEvent event; |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 211 | ui::Transform identityTransform; |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 212 | event.initialize(InputEvent::nextId(), 0 /*deviceId*/, AINPUT_SOURCE_TOUCHSCREEN, |
| 213 | DISPLAY_ID, INVALID_HMAC, action, 0 /*actionButton*/, 0 /*flags*/, |
| 214 | AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, 0 /*buttonState*/, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 215 | MotionClassification::NONE, identityTransform, 0 /*xPrecision*/, |
| 216 | 0 /*yPrecision*/, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 217 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0 /*downTime*/, |
Evan Rosky | 0957669 | 2021-07-01 12:22:09 -0700 | [diff] [blame] | 218 | entry.eventTime.count(), pointerCount, properties, coords); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 219 | |
| 220 | events.emplace_back(event); |
| 221 | } |
| 222 | |
| 223 | return events; |
| 224 | } |
| 225 | |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 226 | static void computeAndCheckVelocity(const VelocityTracker::Strategy strategy, |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 227 | const std::vector<PlanarMotionEventEntry>& motions, |
| 228 | int32_t axis, float targetVelocity, |
| 229 | uint32_t pointerId = DEFAULT_POINTER_ID) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 230 | VelocityTracker vt(strategy); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 231 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 232 | std::vector<MotionEvent> events = createTouchMotionEventStream(motions); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 233 | for (MotionEvent event : events) { |
| 234 | vt.addMovement(&event); |
| 235 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 236 | |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 237 | checkVelocity(vt.getVelocity(axis, pointerId).value_or(0), targetVelocity); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 238 | } |
| 239 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 240 | static void computeAndCheckAxisScrollVelocity( |
| 241 | const VelocityTracker::Strategy strategy, |
| 242 | const std::vector<std::pair<std::chrono::nanoseconds, float>>& motions, |
| 243 | std::optional<float> targetVelocity) { |
| 244 | VelocityTracker vt(strategy); |
| 245 | |
| 246 | std::vector<MotionEvent> events = createAxisScrollMotionEventStream(motions); |
| 247 | for (const MotionEvent& event : events) { |
| 248 | vt.addMovement(&event); |
| 249 | } |
| 250 | |
| 251 | std::optional<float> velocity = vt.getVelocity(AMOTION_EVENT_AXIS_SCROLL, DEFAULT_POINTER_ID); |
| 252 | if (velocity && !targetVelocity) { |
| 253 | FAIL() << "Expected no velocity, but found " << *velocity; |
| 254 | } |
| 255 | if (!velocity && targetVelocity) { |
| 256 | FAIL() << "Expected velocity, but found no velocity"; |
| 257 | } |
| 258 | if (velocity) { |
| 259 | checkVelocity(*velocity, *targetVelocity); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | static void computeAndCheckQuadraticEstimate(const std::vector<PlanarMotionEventEntry>& motions, |
| 264 | const std::array<float, 3>& coefficients) { |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 265 | VelocityTracker vt(VelocityTracker::Strategy::LSQ2); |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 266 | std::vector<MotionEvent> events = createTouchMotionEventStream(motions); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 267 | for (MotionEvent event : events) { |
| 268 | vt.addMovement(&event); |
| 269 | } |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 270 | VelocityTracker::Estimator estimatorX; |
| 271 | VelocityTracker::Estimator estimatorY; |
| 272 | EXPECT_TRUE(vt.getEstimator(AMOTION_EVENT_AXIS_X, 0, &estimatorX)); |
| 273 | EXPECT_TRUE(vt.getEstimator(AMOTION_EVENT_AXIS_Y, 0, &estimatorY)); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 274 | for (size_t i = 0; i< coefficients.size(); i++) { |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 275 | checkCoefficient(estimatorX.coeff[i], coefficients[i]); |
| 276 | checkCoefficient(estimatorY.coeff[i], coefficients[i]); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 280 | /* |
| 281 | * ================== VelocityTracker tests generated manually ===================================== |
| 282 | */ |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 283 | TEST_F(VelocityTrackerTest, TestComputedVelocity) { |
| 284 | VelocityTracker::ComputedVelocity computedVelocity; |
| 285 | |
| 286 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, 0 /*id*/, 200 /*velocity*/); |
| 287 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, 26U /*id*/, 400 /*velocity*/); |
| 288 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, 27U /*id*/, 650 /*velocity*/); |
| 289 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID, 750 /*velocity*/); |
| 290 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, 0 /*id*/, 1000 /*velocity*/); |
| 291 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, 26U /*id*/, 2000 /*velocity*/); |
| 292 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, 27U /*id*/, 3000 /*velocity*/); |
| 293 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, MAX_POINTER_ID, 4000 /*velocity*/); |
| 294 | |
| 295 | // Check the axes/indices with velocity. |
| 296 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, 0U /*id*/)), 200); |
| 297 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, 26U /*id*/)), 400); |
| 298 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, 27U /*id*/)), 650); |
| 299 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID)), 750); |
| 300 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, 0U /*id*/)), 1000); |
| 301 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, 26U /*id*/)), 2000); |
| 302 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, 27U /*id*/)), 3000); |
| 303 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, MAX_POINTER_ID)), 4000); |
| 304 | for (uint32_t id = 0; id <= MAX_POINTER_ID; id++) { |
| 305 | // Since no data was added for AXIS_SCROLL, expect empty value for the axis for any id. |
| 306 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_SCROLL, id)) |
| 307 | << "Empty scroll data expected at id=" << id; |
| 308 | if (id == 0 || id == 26U || id == 27U || id == MAX_POINTER_ID) { |
| 309 | // Already checked above; continue. |
| 310 | continue; |
| 311 | } |
| 312 | // No data was added to X/Y for this id, expect empty value. |
| 313 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, id)) |
| 314 | << "Empty X data expected at id=" << id; |
| 315 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, id)) |
| 316 | << "Empty Y data expected at id=" << id; |
| 317 | } |
| 318 | // Out-of-bounds ids should given empty values. |
| 319 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, -1)); |
| 320 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID + 1)); |
| 321 | } |
| 322 | |
| 323 | TEST_F(VelocityTrackerTest, TestGetComputedVelocity) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 324 | std::vector<PlanarMotionEventEntry> motions = { |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 325 | {235089067457000ns, {{528.00, 0}}}, {235089084684000ns, {{527.00, 0}}}, |
| 326 | {235089093349000ns, {{527.00, 0}}}, {235089095677625ns, {{527.00, 0}}}, |
| 327 | {235089101859000ns, {{527.00, 0}}}, {235089110378000ns, {{528.00, 0}}}, |
| 328 | {235089112497111ns, {{528.25, 0}}}, {235089118760000ns, {{531.00, 0}}}, |
| 329 | {235089126686000ns, {{535.00, 0}}}, {235089129316820ns, {{536.33, 0}}}, |
| 330 | {235089135199000ns, {{540.00, 0}}}, {235089144297000ns, {{546.00, 0}}}, |
| 331 | {235089146136443ns, {{547.21, 0}}}, {235089152923000ns, {{553.00, 0}}}, |
| 332 | {235089160784000ns, {{559.00, 0}}}, {235089162955851ns, {{560.66, 0}}}, |
| 333 | {235089162955851ns, {{560.66, 0}}}, // ACTION_UP |
| 334 | }; |
| 335 | VelocityTracker vt(VelocityTracker::Strategy::IMPULSE); |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 336 | std::vector<MotionEvent> events = createTouchMotionEventStream(motions); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 337 | for (const MotionEvent& event : events) { |
| 338 | vt.addMovement(&event); |
| 339 | } |
| 340 | |
| 341 | float maxFloat = std::numeric_limits<float>::max(); |
| 342 | VelocityTracker::ComputedVelocity computedVelocity; |
| 343 | computedVelocity = vt.getComputedVelocity(1000 /* units */, maxFloat); |
| 344 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), |
| 345 | 764.345703); |
| 346 | |
| 347 | // Expect X velocity to be scaled with respective to provided units. |
| 348 | computedVelocity = vt.getComputedVelocity(1000000 /* units */, maxFloat); |
| 349 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), |
| 350 | 764345.703); |
| 351 | |
| 352 | // Expect X velocity to be clamped by provided max velocity. |
| 353 | computedVelocity = vt.getComputedVelocity(1000000 /* units */, 1000); |
| 354 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), 1000); |
| 355 | |
| 356 | // All 0 data for Y; expect 0 velocity. |
| 357 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, DEFAULT_POINTER_ID)), 0); |
| 358 | |
| 359 | // No data for scroll-axis; expect empty velocity. |
| 360 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_SCROLL, DEFAULT_POINTER_ID)); |
| 361 | } |
| 362 | |
Yeabkal Wubshit | 47ff708 | 2022-09-10 23:09:15 -0700 | [diff] [blame] | 363 | TEST_F(VelocityTrackerTest, TestApiInteractionsWithNoMotionEvents) { |
| 364 | VelocityTracker vt(VelocityTracker::Strategy::DEFAULT); |
| 365 | |
| 366 | EXPECT_FALSE(vt.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)); |
| 367 | |
| 368 | VelocityTracker::Estimator estimator; |
| 369 | EXPECT_FALSE(vt.getEstimator(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID, &estimator)); |
| 370 | |
| 371 | VelocityTracker::ComputedVelocity computedVelocity = vt.getComputedVelocity(1000, 1000); |
| 372 | for (uint32_t id = 0; id <= MAX_POINTER_ID; id++) { |
| 373 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, id)); |
| 374 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, id)); |
| 375 | } |
| 376 | |
| 377 | EXPECT_EQ(-1, vt.getActivePointerId()); |
| 378 | |
| 379 | // Make sure that the clearing functions execute without an issue. |
| 380 | vt.clearPointers(BitSet32(7U)); |
| 381 | vt.clear(); |
| 382 | } |
| 383 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 384 | TEST_F(VelocityTrackerTest, ThreePointsPositiveVelocityTest) { |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 385 | // Same coordinate is reported 2 times in a row |
| 386 | // It is difficult to determine the correct answer here, but at least the direction |
| 387 | // of the reported velocity should be positive. |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 388 | std::vector<PlanarMotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 389 | {0ms, {{273, 0}}}, |
| 390 | {12585us, {{293, 0}}}, |
| 391 | {14730us, {{293, 0}}}, |
| 392 | {14730us, {{293, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 393 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 394 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 395 | 1600); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | TEST_F(VelocityTrackerTest, ThreePointsZeroVelocityTest) { |
| 399 | // Same coordinate is reported 3 times in a row |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 400 | std::vector<PlanarMotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 401 | {0ms, {{293, 0}}}, |
| 402 | {6132us, {{293, 0}}}, |
| 403 | {11283us, {{293, 0}}}, |
| 404 | {11283us, {{293, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 405 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 406 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 407 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | TEST_F(VelocityTrackerTest, ThreePointsLinearVelocityTest) { |
| 411 | // Fixed velocity at 5 points per 10 milliseconds |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 412 | std::vector<PlanarMotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 413 | {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] | 414 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 415 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 500); |
| 416 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 500); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | |
| 420 | /** |
| 421 | * ================== VelocityTracker tests generated by recording real events ===================== |
| 422 | * |
| 423 | * To add a test, record the input coordinates and event times to all calls |
| 424 | * to void VelocityTracker::addMovement(const MotionEvent* event). |
| 425 | * Also record all calls to VelocityTracker::clear(). |
| 426 | * Finally, record the output of VelocityTracker::getVelocity(...) |
| 427 | * This will give you the necessary data to create a new test. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 428 | * |
| 429 | * Another good way to generate this data is to use 'dumpsys input' just after the event has |
| 430 | * occurred. |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 431 | */ |
| 432 | |
| 433 | // --------------- Recorded by hand on swordfish --------------------------------------------------- |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 434 | TEST_F(VelocityTrackerTest, SwordfishFlingDown) { |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 435 | // Recording of a fling on Swordfish that could cause a fling in the wrong direction |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 436 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 437 | { 0ms, {{271, 96}} }, |
| 438 | { 16071042ns, {{269.786346, 106.922775}} }, |
| 439 | { 35648403ns, {{267.983063, 156.660034}} }, |
| 440 | { 52313925ns, {{262.638397, 220.339081}} }, |
| 441 | { 68976522ns, {{266.138824, 331.581116}} }, |
| 442 | { 85639375ns, {{274.79245, 428.113159}} }, |
| 443 | { 96948871ns, {{274.79245, 428.113159}} }, |
| 444 | { 96948871ns, {{274.79245, 428.113159}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 445 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 446 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 447 | 623.577637); |
| 448 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 449 | 5970.7309); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | // --------------- Recorded by hand on sailfish, generated by a script ----------------------------- |
| 453 | // For some of these tests, the X-direction velocity checking has been removed, because the lsq2 |
| 454 | // and the impulse VelocityTrackerStrategies did not agree within 20%. |
| 455 | // Since the flings were recorded in the Y-direction, the intentional user action should only |
| 456 | // be relevant for the Y axis. |
| 457 | // There have been also cases where lsq2 and impulse disagreed more than 20% in the Y-direction. |
| 458 | // Those recordings have been discarded because we didn't feel one strategy's interpretation was |
| 459 | // more correct than another's but didn't want to increase the tolerance for the entire test suite. |
| 460 | // |
| 461 | // There are 18 tests total below: 9 in the positive Y direction and 9 in the opposite. |
| 462 | // The recordings were loosely binned into 3 categories - slow, faster, and fast, which roughly |
| 463 | // characterizes the velocity of the finger motion. |
| 464 | // These can be treated approximately as: |
| 465 | // slow - less than 1 page gets scrolled |
| 466 | // faster - more than 1 page gets scrolled, but less than 3 |
| 467 | // fast - entire list is scrolled (fling is done as hard as possible) |
| 468 | |
| 469 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow1) { |
| 470 | // Sailfish - fling up - slow - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 471 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 472 | { 235089067457000ns, {{528.00, 983.00}} }, |
| 473 | { 235089084684000ns, {{527.00, 981.00}} }, |
| 474 | { 235089093349000ns, {{527.00, 977.00}} }, |
| 475 | { 235089095677625ns, {{527.00, 975.93}} }, |
| 476 | { 235089101859000ns, {{527.00, 970.00}} }, |
| 477 | { 235089110378000ns, {{528.00, 960.00}} }, |
| 478 | { 235089112497111ns, {{528.25, 957.51}} }, |
| 479 | { 235089118760000ns, {{531.00, 946.00}} }, |
| 480 | { 235089126686000ns, {{535.00, 931.00}} }, |
| 481 | { 235089129316820ns, {{536.33, 926.02}} }, |
| 482 | { 235089135199000ns, {{540.00, 914.00}} }, |
| 483 | { 235089144297000ns, {{546.00, 896.00}} }, |
| 484 | { 235089146136443ns, {{547.21, 892.36}} }, |
| 485 | { 235089152923000ns, {{553.00, 877.00}} }, |
| 486 | { 235089160784000ns, {{559.00, 851.00}} }, |
| 487 | { 235089162955851ns, {{560.66, 843.82}} }, |
| 488 | { 235089162955851ns, {{560.66, 843.82}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 489 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 490 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
Siarhei Vishniakou | e37bcec | 2021-09-28 14:24:32 -0700 | [diff] [blame] | 491 | 764.345703); |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 492 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 493 | 951.698181); |
| 494 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 495 | -3604.819336); |
| 496 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 497 | -3044.966064); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | |
| 501 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow2) { |
| 502 | // Sailfish - fling up - slow - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 503 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 504 | { 235110560704000ns, {{522.00, 1107.00}} }, |
| 505 | { 235110575764000ns, {{522.00, 1107.00}} }, |
| 506 | { 235110584385000ns, {{522.00, 1107.00}} }, |
| 507 | { 235110588421179ns, {{521.52, 1106.52}} }, |
| 508 | { 235110592830000ns, {{521.00, 1106.00}} }, |
| 509 | { 235110601385000ns, {{520.00, 1104.00}} }, |
| 510 | { 235110605088160ns, {{519.14, 1102.27}} }, |
| 511 | { 235110609952000ns, {{518.00, 1100.00}} }, |
| 512 | { 235110618353000ns, {{517.00, 1093.00}} }, |
| 513 | { 235110621755146ns, {{516.60, 1090.17}} }, |
| 514 | { 235110627010000ns, {{517.00, 1081.00}} }, |
| 515 | { 235110634785000ns, {{518.00, 1063.00}} }, |
| 516 | { 235110638422450ns, {{518.87, 1052.58}} }, |
| 517 | { 235110643161000ns, {{520.00, 1039.00}} }, |
| 518 | { 235110651767000ns, {{524.00, 1011.00}} }, |
| 519 | { 235110655089581ns, {{525.54, 1000.19}} }, |
| 520 | { 235110660368000ns, {{530.00, 980.00}} }, |
| 521 | { 235110660368000ns, {{530.00, 980.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_Y, |
| 524 | -4096.583008); |
| 525 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 526 | -3455.094238); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | |
| 530 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow3) { |
| 531 | // Sailfish - fling up - slow - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 532 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 533 | { 792536237000ns, {{580.00, 1317.00}} }, |
| 534 | { 792541538987ns, {{580.63, 1311.94}} }, |
| 535 | { 792544613000ns, {{581.00, 1309.00}} }, |
| 536 | { 792552301000ns, {{583.00, 1295.00}} }, |
| 537 | { 792558362309ns, {{585.13, 1282.92}} }, |
| 538 | { 792560828000ns, {{586.00, 1278.00}} }, |
| 539 | { 792569446000ns, {{589.00, 1256.00}} }, |
| 540 | { 792575185095ns, {{591.54, 1241.41}} }, |
| 541 | { 792578491000ns, {{593.00, 1233.00}} }, |
| 542 | { 792587044000ns, {{597.00, 1211.00}} }, |
| 543 | { 792592008172ns, {{600.28, 1195.92}} }, |
| 544 | { 792594616000ns, {{602.00, 1188.00}} }, |
| 545 | { 792603129000ns, {{607.00, 1167.00}} }, |
| 546 | { 792608831290ns, {{609.48, 1155.83}} }, |
| 547 | { 792612321000ns, {{611.00, 1149.00}} }, |
| 548 | { 792620768000ns, {{615.00, 1131.00}} }, |
| 549 | { 792625653873ns, {{617.32, 1121.73}} }, |
| 550 | { 792629200000ns, {{619.00, 1115.00}} }, |
| 551 | { 792629200000ns, {{619.00, 1115.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 552 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 553 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 554 | 574.33429); |
| 555 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 556 | 617.40564); |
| 557 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 558 | -2361.982666); |
| 559 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 560 | -2500.055664); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | |
| 564 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster1) { |
| 565 | // Sailfish - fling up - faster - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 566 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 567 | { 235160420675000ns, {{610.00, 1042.00}} }, |
| 568 | { 235160428220000ns, {{609.00, 1026.00}} }, |
| 569 | { 235160436544000ns, {{609.00, 1024.00}} }, |
| 570 | { 235160441852394ns, {{609.64, 1020.82}} }, |
| 571 | { 235160444878000ns, {{610.00, 1019.00}} }, |
| 572 | { 235160452673000ns, {{613.00, 1006.00}} }, |
| 573 | { 235160458519743ns, {{617.18, 992.06}} }, |
| 574 | { 235160461061000ns, {{619.00, 986.00}} }, |
| 575 | { 235160469798000ns, {{627.00, 960.00}} }, |
| 576 | { 235160475186713ns, {{632.22, 943.02}} }, |
| 577 | { 235160478051000ns, {{635.00, 934.00}} }, |
| 578 | { 235160486489000ns, {{644.00, 906.00}} }, |
| 579 | { 235160491853697ns, {{649.56, 890.56}} }, |
| 580 | { 235160495177000ns, {{653.00, 881.00}} }, |
| 581 | { 235160504148000ns, {{662.00, 858.00}} }, |
| 582 | { 235160509231495ns, {{666.81, 845.37}} }, |
| 583 | { 235160512603000ns, {{670.00, 837.00}} }, |
| 584 | { 235160520366000ns, {{679.00, 814.00}} }, |
| 585 | { 235160520366000ns, {{679.00, 814.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 586 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 587 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 588 | 1274.141724); |
| 589 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 590 | 1438.53186); |
| 591 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 592 | -3001.4348); |
| 593 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 594 | -3695.859619); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | |
| 598 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster2) { |
| 599 | // Sailfish - fling up - faster - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 600 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 601 | { 847153808000ns, {{576.00, 1264.00}} }, |
| 602 | { 847171174000ns, {{576.00, 1262.00}} }, |
| 603 | { 847179640000ns, {{576.00, 1257.00}} }, |
| 604 | { 847185187540ns, {{577.41, 1249.22}} }, |
| 605 | { 847187487000ns, {{578.00, 1246.00}} }, |
| 606 | { 847195710000ns, {{581.00, 1227.00}} }, |
| 607 | { 847202027059ns, {{583.93, 1209.40}} }, |
| 608 | { 847204324000ns, {{585.00, 1203.00}} }, |
| 609 | { 847212672000ns, {{590.00, 1176.00}} }, |
| 610 | { 847218861395ns, {{594.36, 1157.11}} }, |
| 611 | { 847221190000ns, {{596.00, 1150.00}} }, |
| 612 | { 847230484000ns, {{602.00, 1124.00}} }, |
| 613 | { 847235701400ns, {{607.56, 1103.83}} }, |
| 614 | { 847237986000ns, {{610.00, 1095.00}} }, |
| 615 | { 847237986000ns, {{610.00, 1095.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 616 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 617 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 618 | -4280.07959); |
| 619 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 620 | -4241.004395); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | |
| 624 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster3) { |
| 625 | // Sailfish - fling up - faster - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 626 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 627 | { 235200532789000ns, {{507.00, 1084.00}} }, |
| 628 | { 235200549221000ns, {{507.00, 1083.00}} }, |
| 629 | { 235200557841000ns, {{507.00, 1081.00}} }, |
| 630 | { 235200558051189ns, {{507.00, 1080.95}} }, |
| 631 | { 235200566314000ns, {{507.00, 1078.00}} }, |
| 632 | { 235200574876586ns, {{508.97, 1070.12}} }, |
| 633 | { 235200575006000ns, {{509.00, 1070.00}} }, |
| 634 | { 235200582900000ns, {{514.00, 1054.00}} }, |
| 635 | { 235200591276000ns, {{525.00, 1023.00}} }, |
| 636 | { 235200591701829ns, {{525.56, 1021.42}} }, |
| 637 | { 235200600064000ns, {{542.00, 976.00}} }, |
| 638 | { 235200608519000ns, {{563.00, 911.00}} }, |
| 639 | { 235200608527086ns, {{563.02, 910.94}} }, |
| 640 | { 235200616933000ns, {{590.00, 844.00}} }, |
| 641 | { 235200616933000ns, {{590.00, 844.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 642 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 643 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 644 | -8715.686523); |
| 645 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 646 | -7639.026367); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
| 650 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast1) { |
| 651 | // Sailfish - fling up - fast - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 652 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 653 | { 920922149000ns, {{561.00, 1412.00}} }, |
| 654 | { 920930185000ns, {{559.00, 1377.00}} }, |
| 655 | { 920930262463ns, {{558.98, 1376.66}} }, |
| 656 | { 920938547000ns, {{559.00, 1371.00}} }, |
| 657 | { 920947096857ns, {{562.91, 1342.68}} }, |
| 658 | { 920947302000ns, {{563.00, 1342.00}} }, |
| 659 | { 920955502000ns, {{577.00, 1272.00}} }, |
| 660 | { 920963931021ns, {{596.87, 1190.54}} }, |
| 661 | { 920963987000ns, {{597.00, 1190.00}} }, |
| 662 | { 920972530000ns, {{631.00, 1093.00}} }, |
| 663 | { 920980765511ns, {{671.31, 994.68}} }, |
| 664 | { 920980906000ns, {{672.00, 993.00}} }, |
| 665 | { 920989261000ns, {{715.00, 903.00}} }, |
| 666 | { 920989261000ns, {{715.00, 903.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 667 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 668 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 669 | 5670.329102); |
| 670 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 671 | 5991.866699); |
| 672 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 673 | -13021.101562); |
| 674 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 675 | -15093.995117); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | |
| 679 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast2) { |
| 680 | // Sailfish - fling up - fast - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 681 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 682 | { 235247153233000ns, {{518.00, 1168.00}} }, |
| 683 | { 235247170452000ns, {{517.00, 1167.00}} }, |
| 684 | { 235247178908000ns, {{515.00, 1159.00}} }, |
| 685 | { 235247179556213ns, {{514.85, 1158.39}} }, |
| 686 | { 235247186821000ns, {{515.00, 1125.00}} }, |
| 687 | { 235247195265000ns, {{521.00, 1051.00}} }, |
| 688 | { 235247196389476ns, {{521.80, 1041.15}} }, |
| 689 | { 235247203649000ns, {{538.00, 932.00}} }, |
| 690 | { 235247212253000ns, {{571.00, 794.00}} }, |
| 691 | { 235247213222491ns, {{574.72, 778.45}} }, |
| 692 | { 235247220736000ns, {{620.00, 641.00}} }, |
| 693 | { 235247220736000ns, {{620.00, 641.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 694 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 695 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 696 | -20286.958984); |
| 697 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 698 | -20494.587891); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | |
| 702 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast3) { |
| 703 | // Sailfish - fling up - fast - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 704 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 705 | { 235302568736000ns, {{529.00, 1167.00}} }, |
| 706 | { 235302576644000ns, {{523.00, 1140.00}} }, |
| 707 | { 235302579395063ns, {{520.91, 1130.61}} }, |
| 708 | { 235302585140000ns, {{522.00, 1130.00}} }, |
| 709 | { 235302593615000ns, {{527.00, 1065.00}} }, |
| 710 | { 235302596207444ns, {{528.53, 1045.12}} }, |
| 711 | { 235302602102000ns, {{559.00, 872.00}} }, |
| 712 | { 235302610545000ns, {{652.00, 605.00}} }, |
| 713 | { 235302613019881ns, {{679.26, 526.73}} }, |
| 714 | { 235302613019881ns, {{679.26, 526.73}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 715 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 716 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 717 | -39295.941406); |
| 718 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 719 | -36461.421875); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | |
| 723 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow1) { |
| 724 | // Sailfish - fling down - slow - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 725 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 726 | { 235655749552755ns, {{582.00, 432.49}} }, |
| 727 | { 235655750638000ns, {{582.00, 433.00}} }, |
| 728 | { 235655758865000ns, {{582.00, 440.00}} }, |
| 729 | { 235655766221523ns, {{581.16, 448.43}} }, |
| 730 | { 235655767594000ns, {{581.00, 450.00}} }, |
| 731 | { 235655776044000ns, {{580.00, 462.00}} }, |
| 732 | { 235655782890696ns, {{579.18, 474.35}} }, |
| 733 | { 235655784360000ns, {{579.00, 477.00}} }, |
| 734 | { 235655792795000ns, {{578.00, 496.00}} }, |
| 735 | { 235655799559531ns, {{576.27, 515.04}} }, |
| 736 | { 235655800612000ns, {{576.00, 518.00}} }, |
| 737 | { 235655809535000ns, {{574.00, 542.00}} }, |
| 738 | { 235655816988015ns, {{572.17, 564.86}} }, |
| 739 | { 235655817685000ns, {{572.00, 567.00}} }, |
| 740 | { 235655825981000ns, {{569.00, 595.00}} }, |
| 741 | { 235655833808653ns, {{566.26, 620.60}} }, |
| 742 | { 235655834541000ns, {{566.00, 623.00}} }, |
| 743 | { 235655842893000ns, {{563.00, 649.00}} }, |
| 744 | { 235655842893000ns, {{563.00, 649.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 745 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 746 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 747 | -419.749695); |
| 748 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 749 | -398.303894); |
| 750 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 751 | 3309.016357); |
| 752 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 753 | 3969.099854); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | |
| 757 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow2) { |
| 758 | // Sailfish - fling down - slow - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 759 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 760 | { 235671152083370ns, {{485.24, 558.28}} }, |
| 761 | { 235671154126000ns, {{485.00, 559.00}} }, |
| 762 | { 235671162497000ns, {{484.00, 566.00}} }, |
| 763 | { 235671168750511ns, {{483.27, 573.29}} }, |
| 764 | { 235671171071000ns, {{483.00, 576.00}} }, |
| 765 | { 235671179390000ns, {{482.00, 588.00}} }, |
| 766 | { 235671185417210ns, {{481.31, 598.98}} }, |
| 767 | { 235671188173000ns, {{481.00, 604.00}} }, |
| 768 | { 235671196371000ns, {{480.00, 624.00}} }, |
| 769 | { 235671202084196ns, {{479.27, 639.98}} }, |
| 770 | { 235671204235000ns, {{479.00, 646.00}} }, |
| 771 | { 235671212554000ns, {{478.00, 673.00}} }, |
| 772 | { 235671219471011ns, {{476.39, 697.12}} }, |
| 773 | { 235671221159000ns, {{476.00, 703.00}} }, |
| 774 | { 235671229592000ns, {{474.00, 734.00}} }, |
| 775 | { 235671236281462ns, {{472.43, 758.38}} }, |
| 776 | { 235671238098000ns, {{472.00, 765.00}} }, |
| 777 | { 235671246532000ns, {{470.00, 799.00}} }, |
| 778 | { 235671246532000ns, {{470.00, 799.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 779 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 780 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 781 | -262.80426); |
| 782 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 783 | -243.665344); |
| 784 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 785 | 4215.682129); |
| 786 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 787 | 4587.986816); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | |
| 791 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow3) { |
| 792 | // Sailfish - fling down - slow - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 793 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 794 | { 170983201000ns, {{557.00, 533.00}} }, |
| 795 | { 171000668000ns, {{556.00, 534.00}} }, |
| 796 | { 171007359750ns, {{554.73, 535.27}} }, |
| 797 | { 171011197000ns, {{554.00, 536.00}} }, |
| 798 | { 171017660000ns, {{552.00, 540.00}} }, |
| 799 | { 171024201831ns, {{549.97, 544.73}} }, |
| 800 | { 171027333000ns, {{549.00, 547.00}} }, |
| 801 | { 171034603000ns, {{545.00, 557.00}} }, |
| 802 | { 171041043371ns, {{541.98, 567.55}} }, |
| 803 | { 171043147000ns, {{541.00, 571.00}} }, |
| 804 | { 171051052000ns, {{536.00, 586.00}} }, |
| 805 | { 171051052000ns, {{536.00, 586.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 806 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 807 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 808 | -723.413513); |
| 809 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 810 | -651.038452); |
| 811 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 812 | 2091.502441); |
| 813 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 814 | 1934.517456); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | |
| 818 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster1) { |
| 819 | // Sailfish - fling down - faster - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 820 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 821 | { 235695280333000ns, {{558.00, 451.00}} }, |
| 822 | { 235695283971237ns, {{558.43, 454.45}} }, |
| 823 | { 235695289038000ns, {{559.00, 462.00}} }, |
| 824 | { 235695297388000ns, {{561.00, 478.00}} }, |
| 825 | { 235695300638465ns, {{561.83, 486.25}} }, |
| 826 | { 235695305265000ns, {{563.00, 498.00}} }, |
| 827 | { 235695313591000ns, {{564.00, 521.00}} }, |
| 828 | { 235695317305492ns, {{564.43, 532.68}} }, |
| 829 | { 235695322181000ns, {{565.00, 548.00}} }, |
| 830 | { 235695330709000ns, {{565.00, 577.00}} }, |
| 831 | { 235695333972227ns, {{565.00, 588.10}} }, |
| 832 | { 235695339250000ns, {{565.00, 609.00}} }, |
| 833 | { 235695347839000ns, {{565.00, 642.00}} }, |
| 834 | { 235695351313257ns, {{565.00, 656.18}} }, |
| 835 | { 235695356412000ns, {{565.00, 677.00}} }, |
| 836 | { 235695364899000ns, {{563.00, 710.00}} }, |
| 837 | { 235695368118682ns, {{562.24, 722.52}} }, |
| 838 | { 235695373403000ns, {{564.00, 744.00}} }, |
| 839 | { 235695373403000ns, {{564.00, 744.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 840 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 841 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 842 | 4254.639648); |
| 843 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 844 | 4698.415039); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | |
| 848 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster2) { |
| 849 | // Sailfish - fling down - faster - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 850 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 851 | { 235709624766000ns, {{535.00, 579.00}} }, |
| 852 | { 235709642256000ns, {{534.00, 580.00}} }, |
| 853 | { 235709643350278ns, {{533.94, 580.06}} }, |
| 854 | { 235709650760000ns, {{532.00, 584.00}} }, |
| 855 | { 235709658615000ns, {{530.00, 593.00}} }, |
| 856 | { 235709660170495ns, {{529.60, 594.78}} }, |
| 857 | { 235709667095000ns, {{527.00, 606.00}} }, |
| 858 | { 235709675616000ns, {{524.00, 628.00}} }, |
| 859 | { 235709676983261ns, {{523.52, 631.53}} }, |
| 860 | { 235709684289000ns, {{521.00, 652.00}} }, |
| 861 | { 235709692763000ns, {{518.00, 682.00}} }, |
| 862 | { 235709693804993ns, {{517.63, 685.69}} }, |
| 863 | { 235709701438000ns, {{515.00, 709.00}} }, |
| 864 | { 235709709830000ns, {{512.00, 739.00}} }, |
| 865 | { 235709710626776ns, {{511.72, 741.85}} }, |
| 866 | { 235709710626776ns, {{511.72, 741.85}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 867 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 868 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 869 | -430.440247); |
| 870 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 871 | -447.600311); |
| 872 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 873 | 3953.859375); |
| 874 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 875 | 4316.155273); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | |
| 879 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster3) { |
| 880 | // Sailfish - fling down - faster - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 881 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 882 | { 235727628927000ns, {{540.00, 440.00}} }, |
| 883 | { 235727636810000ns, {{537.00, 454.00}} }, |
| 884 | { 235727646176000ns, {{536.00, 454.00}} }, |
| 885 | { 235727653586628ns, {{535.12, 456.65}} }, |
| 886 | { 235727654557000ns, {{535.00, 457.00}} }, |
| 887 | { 235727663024000ns, {{534.00, 465.00}} }, |
| 888 | { 235727670410103ns, {{533.04, 479.45}} }, |
| 889 | { 235727670691000ns, {{533.00, 480.00}} }, |
| 890 | { 235727679255000ns, {{531.00, 501.00}} }, |
| 891 | { 235727687233704ns, {{529.09, 526.73}} }, |
| 892 | { 235727687628000ns, {{529.00, 528.00}} }, |
| 893 | { 235727696113000ns, {{526.00, 558.00}} }, |
| 894 | { 235727704057546ns, {{523.18, 588.98}} }, |
| 895 | { 235727704576000ns, {{523.00, 591.00}} }, |
| 896 | { 235727713099000ns, {{520.00, 626.00}} }, |
| 897 | { 235727720880776ns, {{516.33, 655.36}} }, |
| 898 | { 235727721580000ns, {{516.00, 658.00}} }, |
| 899 | { 235727721580000ns, {{516.00, 658.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 900 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 901 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 902 | 4484.617676); |
| 903 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 904 | 4927.92627); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | |
| 908 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast1) { |
| 909 | // Sailfish - fling down - fast - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 910 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 911 | { 235762352849000ns, {{467.00, 286.00}} }, |
| 912 | { 235762360250000ns, {{443.00, 344.00}} }, |
| 913 | { 235762362787412ns, {{434.77, 363.89}} }, |
| 914 | { 235762368807000ns, {{438.00, 359.00}} }, |
| 915 | { 235762377220000ns, {{425.00, 423.00}} }, |
| 916 | { 235762379608561ns, {{421.31, 441.17}} }, |
| 917 | { 235762385698000ns, {{412.00, 528.00}} }, |
| 918 | { 235762394133000ns, {{406.00, 648.00}} }, |
| 919 | { 235762396429369ns, {{404.37, 680.67}} }, |
| 920 | { 235762396429369ns, {{404.37, 680.67}} }, //ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 921 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 922 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 923 | 14227.0224); |
| 924 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 925 | 16064.685547); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | |
| 929 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast2) { |
| 930 | // Sailfish - fling down - fast - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 931 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 932 | { 235772487188000ns, {{576.00, 204.00}} }, |
| 933 | { 235772495159000ns, {{553.00, 236.00}} }, |
| 934 | { 235772503568000ns, {{551.00, 240.00}} }, |
| 935 | { 235772508192247ns, {{545.55, 254.17}} }, |
| 936 | { 235772512051000ns, {{541.00, 266.00}} }, |
| 937 | { 235772520794000ns, {{520.00, 337.00}} }, |
| 938 | { 235772525015263ns, {{508.92, 394.43}} }, |
| 939 | { 235772529174000ns, {{498.00, 451.00}} }, |
| 940 | { 235772537635000ns, {{484.00, 589.00}} }, |
| 941 | { 235772537635000ns, {{484.00, 589.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 942 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 943 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 944 | 18660.048828); |
| 945 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 946 | 16918.439453); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | |
| 950 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast3) { |
| 951 | // Sailfish - fling down - fast - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 952 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 953 | { 507650295000ns, {{628.00, 233.00}} }, |
| 954 | { 507658234000ns, {{605.00, 269.00}} }, |
| 955 | { 507666784000ns, {{601.00, 274.00}} }, |
| 956 | { 507669660483ns, {{599.65, 275.68}} }, |
| 957 | { 507675427000ns, {{582.00, 308.00}} }, |
| 958 | { 507683740000ns, {{541.00, 404.00}} }, |
| 959 | { 507686506238ns, {{527.36, 435.95}} }, |
| 960 | { 507692220000ns, {{487.00, 581.00}} }, |
| 961 | { 507700707000ns, {{454.00, 792.00}} }, |
| 962 | { 507703352649ns, {{443.71, 857.77}} }, |
| 963 | { 507703352649ns, {{443.71, 857.77}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 964 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 965 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 966 | -4111.8173); |
| 967 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 968 | -6388.48877); |
| 969 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 970 | 29765.908203); |
| 971 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 972 | 28354.796875); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 973 | } |
| 974 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 975 | /** |
| 976 | * ================== Multiple pointers ============================================================ |
| 977 | * |
| 978 | * Three fingers quickly tap the screen. Since this is a tap, the velocities should be zero. |
| 979 | * If the events with POINTER_UP or POINTER_DOWN are not handled correctly (these should not be |
| 980 | * 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] | 981 | */ |
Siarhei Vishniakou | 346ac6a | 2019-04-10 09:58:05 -0700 | [diff] [blame] | 982 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_ThreeFingerTap) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 983 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 984 | { 0us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} }, |
| 985 | { 10800us, {{1063, 1128}, {682, 1318}, {NAN, NAN}} }, // POINTER_DOWN |
| 986 | { 10800us, {{1063, 1128}, {682, 1318}, {397, 1747}} }, // POINTER_DOWN |
| 987 | { 267300us, {{1063, 1128}, {682, 1318}, {397, 1747}} }, // POINTER_UP |
| 988 | { 267300us, {{1063, 1128}, {NAN, NAN}, {397, 1747}} }, // POINTER_UP |
| 989 | { 272700us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} }, |
| 990 | }; |
| 991 | |
Siarhei Vishniakou | 346ac6a | 2019-04-10 09:58:05 -0700 | [diff] [blame] | 992 | // Velocity should actually be zero, but we expect 0.016 here instead. |
| 993 | // This is close enough to zero, and is likely caused by division by a very small number. |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 994 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0); |
| 995 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, 0); |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 996 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 997 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, 0); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /** |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1001 | * ================= Pointer liftoff =============================================================== |
| 1002 | */ |
| 1003 | |
| 1004 | /** |
| 1005 | * The last movement of a pointer is always ACTION_POINTER_UP or ACTION_UP. If there's a short delay |
| 1006 | * between the last ACTION_MOVE and the next ACTION_POINTER_UP or ACTION_UP, velocity should not be |
| 1007 | * affected by the liftoff. |
| 1008 | */ |
| 1009 | TEST_F(VelocityTrackerTest, ShortDelayBeforeActionUp) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1010 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1011 | {0ms, {{10, 0}}}, {10ms, {{20, 0}}}, {20ms, {{30, 0}}}, {30ms, {{30, 0}}}, // ACTION_UP |
| 1012 | }; |
| 1013 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 1014 | 1000); |
| 1015 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 1000); |
| 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * The last movement of a single pointer is ACTION_UP. If there's a long delay between the last |
| 1020 | * ACTION_MOVE and the final ACTION_UP, velocity should be reported as zero because the pointer |
| 1021 | * should be assumed to have stopped. |
| 1022 | */ |
| 1023 | TEST_F(VelocityTrackerTest, LongDelayBeforeActionUp) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1024 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1025 | {0ms, {{10, 0}}}, |
| 1026 | {10ms, {{20, 0}}}, |
| 1027 | {20ms, {{30, 0}}}, |
| 1028 | {3000ms, {{30, 0}}}, // ACTION_UP |
| 1029 | }; |
| 1030 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 1031 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0); |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * The last movement of a pointer is always ACTION_POINTER_UP or ACTION_UP. If there's a long delay |
| 1036 | * before ACTION_POINTER_UP event, the movement should be assumed to have stopped. |
| 1037 | * The final velocity should be reported as zero for all pointers. |
| 1038 | */ |
| 1039 | TEST_F(VelocityTrackerTest, LongDelayBeforeActionPointerUp) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1040 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1041 | {0ms, {{10, 0}}}, |
| 1042 | {10ms, {{20, 0}, {100, 0}}}, |
| 1043 | {20ms, {{30, 0}, {200, 0}}}, |
| 1044 | {30ms, {{30, 0}, {300, 0}}}, |
| 1045 | {40ms, {{30, 0}, {400, 0}}}, |
| 1046 | {3000ms, {{30, 0}}}, // ACTION_POINTER_UP |
| 1047 | }; |
| 1048 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0, |
| 1049 | /*pointerId*/ 0); |
| 1050 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0, |
| 1051 | /*pointerId*/ 0); |
| 1052 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0, |
| 1053 | /*pointerId*/ 1); |
| 1054 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0, |
| 1055 | /*pointerId*/ 1); |
| 1056 | } |
| 1057 | |
| 1058 | /** |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1059 | * ================== Tests for least squares fitting ============================================== |
| 1060 | * |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1061 | * Special care must be taken when constructing tests for LeastSquaresVelocityTrackerStrategy |
| 1062 | * getEstimator function. In particular: |
| 1063 | * - inside the function, time gets converted from nanoseconds to seconds |
| 1064 | * before being used in the fit. |
| 1065 | * - any values that are older than 100 ms are being discarded. |
| 1066 | * - the newest time gets subtracted from all of the other times before being used in the fit. |
| 1067 | * So these tests have to be designed with those limitations in mind. |
| 1068 | * |
| 1069 | * General approach for the tests below: |
| 1070 | * We only used timestamps in milliseconds, 0 ms, 1 ms, and 2 ms, to be sure that |
| 1071 | * we are well within the HORIZON range. |
| 1072 | * When specifying the expected values of the coefficients, we treat the x values as if |
| 1073 | * they were in ms. Then, to adjust for the time units, the coefficients get progressively |
| 1074 | * multiplied by powers of 1E3. |
| 1075 | * For example: |
| 1076 | * data: t(ms), x |
| 1077 | * 1 ms, 1 |
| 1078 | * 2 ms, 4 |
| 1079 | * 3 ms, 9 |
| 1080 | * The coefficients are (0, 0, 1). |
| 1081 | * In the test, we would convert these coefficients to (0*(1E3)^0, 0*(1E3)^1, 1*(1E3)^2). |
| 1082 | */ |
| 1083 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Constant) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1084 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1085 | { 0ms, {{1, 1}} }, // 0 s |
| 1086 | { 1ms, {{1, 1}} }, // 0.001 s |
| 1087 | { 2ms, {{1, 1}} }, // 0.002 s |
| 1088 | { 2ms, {{1, 1}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1089 | }; |
| 1090 | // The data used for the fit will be as follows: |
| 1091 | // time(s), position |
| 1092 | // -0.002, 1 |
| 1093 | // -0.001, 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1094 | // -0.ms, 1 |
| 1095 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({1, 0, 0})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | /* |
| 1099 | * Straight line y = x :: the constant and quadratic coefficients are zero. |
| 1100 | */ |
| 1101 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Linear) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1102 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1103 | { 0ms, {{-2, -2}} }, |
| 1104 | { 1ms, {{-1, -1}} }, |
| 1105 | { 2ms, {{-0, -0}} }, |
| 1106 | { 2ms, {{-0, -0}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1107 | }; |
| 1108 | // The data used for the fit will be as follows: |
| 1109 | // time(s), position |
| 1110 | // -0.002, -2 |
| 1111 | // -0.001, -1 |
| 1112 | // -0.000, 0 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1113 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({0, 1E3, 0})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /* |
| 1117 | * Parabola |
| 1118 | */ |
| 1119 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1120 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1121 | { 0ms, {{1, 1}} }, |
| 1122 | { 1ms, {{4, 4}} }, |
| 1123 | { 2ms, {{8, 8}} }, |
| 1124 | { 2ms, {{8, 8}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1125 | }; |
| 1126 | // The data used for the fit will be as follows: |
| 1127 | // time(s), position |
| 1128 | // -0.002, 1 |
| 1129 | // -0.001, 4 |
| 1130 | // -0.000, 8 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1131 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({8, 4.5E3, 0.5E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | /* |
| 1135 | * Parabola |
| 1136 | */ |
| 1137 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic2) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1138 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1139 | { 0ms, {{1, 1}} }, |
| 1140 | { 1ms, {{4, 4}} }, |
| 1141 | { 2ms, {{9, 9}} }, |
| 1142 | { 2ms, {{9, 9}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1143 | }; |
| 1144 | // The data used for the fit will be as follows: |
| 1145 | // time(s), position |
| 1146 | // -0.002, 1 |
| 1147 | // -0.001, 4 |
| 1148 | // -0.000, 9 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1149 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({9, 6E3, 1E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | /* |
| 1153 | * Parabola :: y = x^2 :: the constant and linear coefficients are zero. |
| 1154 | */ |
| 1155 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic3) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1156 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1157 | { 0ms, {{4, 4}} }, |
| 1158 | { 1ms, {{1, 1}} }, |
| 1159 | { 2ms, {{0, 0}} }, |
| 1160 | { 2ms, {{0, 0}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1161 | }; |
| 1162 | // The data used for the fit will be as follows: |
| 1163 | // time(s), position |
| 1164 | // -0.002, 4 |
| 1165 | // -0.001, 1 |
| 1166 | // -0.000, 0 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1167 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({0, 0E3, 1E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1168 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1169 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1170 | // Recorded by hand on sailfish, but only the diffs are taken to test cumulative axis velocity. |
| 1171 | TEST_F(VelocityTrackerTest, AxisScrollVelocity) { |
| 1172 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1173 | {235089067457000ns, 0.00}, {235089084684000ns, -1.00}, {235089093349000ns, 0.00}, |
| 1174 | {235089095677625ns, 0.00}, {235089101859000ns, 0.00}, {235089110378000ns, 0.00}, |
| 1175 | {235089112497111ns, 0.25}, {235089118760000ns, 1.75}, {235089126686000ns, 4.00}, |
| 1176 | {235089129316820ns, 1.33}, {235089135199000ns, 3.67}, {235089144297000ns, 6.00}, |
| 1177 | {235089146136443ns, 1.21}, {235089152923000ns, 5.79}, {235089160784000ns, 6.00}, |
| 1178 | {235089162955851ns, 1.66}, |
| 1179 | }; |
| 1180 | |
| 1181 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {764.345703}); |
| 1182 | } |
| 1183 | |
| 1184 | // --------------- Recorded by hand on a Wear OS device using a rotating side button --------------- |
| 1185 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_ScrollDown) { |
| 1186 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1187 | {224598065152ns, -0.050100}, {224621871104ns, -0.133600}, {224645464064ns, -0.551100}, |
| 1188 | {224669171712ns, -0.801600}, {224687063040ns, -1.035400}, {224706691072ns, -0.484300}, |
| 1189 | {224738213888ns, -0.334000}, {224754401280ns, -0.083500}, |
| 1190 | }; |
| 1191 | |
| 1192 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {-27.86}); |
| 1193 | } |
| 1194 | |
| 1195 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_ScrollUp) { |
| 1196 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1197 | {269606010880ns, 0.050100}, {269626064896ns, 0.217100}, {269641973760ns, 0.267200}, |
| 1198 | {269658079232ns, 0.267200}, {269674217472ns, 0.267200}, {269690683392ns, 0.367400}, |
| 1199 | {269706133504ns, 0.551100}, {269722173440ns, 0.501000}, |
| 1200 | }; |
| 1201 | |
| 1202 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {31.92}); |
| 1203 | } |
| 1204 | |
| 1205 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_ScrollDown_ThenUp_ThenDown) { |
| 1206 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1207 | {2580534001664ns, -0.033400}, {2580549992448ns, -0.133600}, |
| 1208 | {2580566769664ns, -0.250500}, {2580581974016ns, -0.183700}, |
| 1209 | {2580597964800ns, -0.267200}, {2580613955584ns, -0.551100}, |
| 1210 | {2580635189248ns, -0.601200}, {2580661927936ns, -0.450900}, |
| 1211 | {2580683161600ns, -0.417500}, {2580705705984ns, -0.150300}, |
| 1212 | {2580722745344ns, -0.016700}, {2580786446336ns, 0.050100}, |
| 1213 | {2580801912832ns, 0.150300}, {2580822360064ns, 0.300600}, |
| 1214 | {2580838088704ns, 0.300600}, {2580854341632ns, 0.400800}, |
| 1215 | {2580869808128ns, 0.517700}, {2580886061056ns, 0.501000}, |
| 1216 | {2580905984000ns, 0.350700}, {2580921974784ns, 0.350700}, |
| 1217 | {2580937965568ns, 0.066800}, {2580974665728ns, 0.016700}, |
| 1218 | {2581034434560ns, -0.066800}, {2581049901056ns, -0.116900}, |
| 1219 | {2581070610432ns, -0.317300}, {2581086076928ns, -0.200400}, |
| 1220 | {2581101805568ns, -0.233800}, {2581118058496ns, -0.417500}, |
| 1221 | {2581134049280ns, -0.417500}, {2581150040064ns, -0.367400}, |
| 1222 | {2581166030848ns, -0.267200}, {2581181759488ns, -0.150300}, |
| 1223 | {2581199847424ns, -0.066800}, |
| 1224 | }; |
| 1225 | |
| 1226 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {-9.73}); |
| 1227 | } |
| 1228 | |
| 1229 | // ------------------------------- Hand generated test cases --------------------------------------- |
| 1230 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_SimilarDifferentialValues) { |
| 1231 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {{1ns, 2.12}, {3ns, 2.12}, |
| 1232 | {7ns, 2.12}, {8ns, 2.12}, |
| 1233 | {15ns, 2.12}, {18ns, 2.12}}; |
| 1234 | |
| 1235 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {1690236059.86}); |
| 1236 | } |
| 1237 | |
| 1238 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_OnlyTwoValues) { |
| 1239 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {{1ms, 5}, {2ms, 10}}; |
| 1240 | |
| 1241 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {10000}); |
| 1242 | } |
| 1243 | |
| 1244 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_ConstantVelocity) { |
| 1245 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {{1ms, 20}, {2ms, 20}, |
| 1246 | {3ms, 20}, {4ms, 20}, |
| 1247 | {5ms, 20}, {6ms, 20}}; |
| 1248 | |
| 1249 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {20000}); |
| 1250 | } |
| 1251 | |
| 1252 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_NoMotion) { |
| 1253 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {{1ns, 0}, {2ns, 0}, |
| 1254 | {3ns, 0}, {4ns, 0}, |
| 1255 | {5ns, 0}, {6ns, 0}}; |
| 1256 | |
| 1257 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {0}); |
| 1258 | } |
| 1259 | |
| 1260 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_NoData) { |
| 1261 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {}; |
| 1262 | |
| 1263 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, std::nullopt); |
| 1264 | } |
| 1265 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1266 | } // namespace android |