Address comments from a previous change.
The original change is 00f511d329924824b1961e9472c3a06683fc2216.
Bug: 134788085
Test: atest libinput_tests
Change-Id: I1f3326067f94fe6a09850f4389483e60fa57a8d4
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 3266b07..dc4978b 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -17,7 +17,6 @@
#define LOG_TAG "Input"
//#define LOG_NDEBUG 0
-#include <math.h>
#include <limits.h>
#include <input/Input.h>
@@ -434,7 +433,7 @@
transformPoint(matrix, 0, 0, &originX, &originY);
// Apply the transformation to cursor position.
- if (!isnan(mXCursorPosition) && !isnan(mYCursorPosition)) {
+ if (isValidCursorPosition(mXCursorPosition, mYCursorPosition)) {
float x = mXCursorPosition + oldXOffset;
float y = mYCursorPosition + oldYOffset;
transformPoint(matrix, x, y, &x, &y);
diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp
index ec34f3e..b879de6 100644
--- a/libs/input/tests/InputEvent_test.cpp
+++ b/libs/input/tests/InputEvent_test.cpp
@@ -603,9 +603,13 @@
ASSERT_NEAR(tanf(angle), tanf(event.getOrientation(i)), 0.1);
}
- // Check cursor positions.
- ASSERT_NEAR(sinf(PI_180 * (90 + ROTATION)) * RADIUS, event.getXCursorPosition(), 0.001);
- ASSERT_NEAR(-cosf(PI_180 * (90 + ROTATION)) * RADIUS, event.getYCursorPosition(), 0.001);
+ // Check cursor positions. The original cursor position is at (3 + RADIUS, 2), where the center
+ // of the circle is (3, 2), so the cursor position is to the right of the center of the circle.
+ // The choice of triangular functions in this test defines the angle of rotation clockwise
+ // relative to the y-axis. Therefore the cursor position's angle is 90 degrees. Here we swap the
+ // triangular function so that we don't have to add the 90 degrees.
+ ASSERT_NEAR(cosf(PI_180 * ROTATION) * RADIUS, event.getXCursorPosition(), 0.001);
+ ASSERT_NEAR(sinf(PI_180 * ROTATION) * RADIUS, event.getYCursorPosition(), 0.001);
// Applying the transformation should preserve the raw X and Y of the first point.
ASSERT_NEAR(originalRawX, event.getRawX(0), 0.001);