summaryrefslogtreecommitdiff
path: root/libs/input/VelocityControl.cpp
diff options
context:
space:
mode:
author Sam Dubey <dubeyshubham@google.com> 2022-09-09 05:09:34 +0000
committer Sam Dubey <dubeyshubham@google.com> 2022-09-09 05:09:34 +0000
commit86f72a3882ab4994dfbb410ebebc9ab3a75b8b16 (patch)
tree05c5c6a2f9ddb7db510ecde9e43c383810f8e912 /libs/input/VelocityControl.cpp
parent37acf6e3b7ff4b30567eb3210560db3d73c20a58 (diff)
Revert "Make VelocityTracker 1D"
Revert "Conform to 1D VelocityTracker" Revert submission 19762050-generic_vt Reason for revert: b/245842062 Reverted Changes: I181af7a03:Make VelocityTracker 1D Ib0be0fc38:Conform to 1D VelocityTracker Change-Id: Ife5675e4abdf154eb6466f687e52b6a427860d26
Diffstat (limited to 'libs/input/VelocityControl.cpp')
-rw-r--r--libs/input/VelocityControl.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/libs/input/VelocityControl.cpp b/libs/input/VelocityControl.cpp
index e2bfb508e1..6e991e98bb 100644
--- a/libs/input/VelocityControl.cpp
+++ b/libs/input/VelocityControl.cpp
@@ -44,8 +44,8 @@ void VelocityControl::setParameters(const VelocityControlParameters& parameters)
void VelocityControl::reset() {
mLastMovementTime = LLONG_MIN;
- mRawPositionX = 0;
- mRawPositionY = 0;
+ mRawPosition.x = 0;
+ mRawPosition.y = 0;
mVelocityTracker.clear();
}
@@ -61,20 +61,17 @@ void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) {
mLastMovementTime = eventTime;
if (deltaX) {
- mRawPositionX += *deltaX;
+ mRawPosition.x += *deltaX;
}
if (deltaY) {
- mRawPositionY += *deltaY;
+ mRawPosition.y += *deltaY;
}
- mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)),
- {{AMOTION_EVENT_AXIS_X, {mRawPositionX}},
- {AMOTION_EVENT_AXIS_Y, {mRawPositionY}}});
+ mVelocityTracker.addMovement(eventTime, BitSet32(BitSet32::valueForBit(0)), {mRawPosition});
- std::optional<float> vx = mVelocityTracker.getVelocity(AMOTION_EVENT_AXIS_X, 0);
- std::optional<float> vy = mVelocityTracker.getVelocity(AMOTION_EVENT_AXIS_Y, 0);
+ float vx, vy;
float scale = mParameters.scale;
- if (vx && vy) {
- float speed = hypotf(*vx, *vy) * scale;
+ if (mVelocityTracker.getVelocity(0, &vx, &vy)) {
+ float speed = hypotf(vx, vy) * scale;
if (speed >= mParameters.highThreshold) {
// Apply full acceleration above the high speed threshold.
scale *= mParameters.acceleration;
@@ -88,9 +85,10 @@ void VelocityControl::move(nsecs_t eventTime, float* deltaX, float* deltaY) {
if (DEBUG_ACCELERATION) {
ALOGD("VelocityControl(%0.3f, %0.3f, %0.3f, %0.3f): "
- "vx=%0.3f, vy=%0.3f, speed=%0.3f, accel=%0.3f",
- mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold,
- mParameters.acceleration, *vx, *vy, speed, scale / mParameters.scale);
+ "vx=%0.3f, vy=%0.3f, speed=%0.3f, accel=%0.3f",
+ mParameters.scale, mParameters.lowThreshold, mParameters.highThreshold,
+ mParameters.acceleration,
+ vx, vy, speed, scale / mParameters.scale);
}
} else {