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