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