Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7262ab6b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "MotionEvent: Round coordinates to a precision of 0.001"

parents 771ba1e0 0909dc1c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -818,6 +818,8 @@ public:
                                               const PointerCoords&);
    static PointerCoords calculateTransformedCoords(uint32_t source, const ui::Transform&,
                                                    const PointerCoords&);
    // The rounding precision for transformed motion events.
    static constexpr float ROUNDING_PRECISION = 0.001f;

protected:
    int32_t mAction;
+17 −4
Original line number Diff line number Diff line
@@ -137,10 +137,23 @@ int32_t IdGenerator::nextId() const {

// --- InputEvent ---

// Due to precision limitations when working with floating points, transforming - namely
// scaling - floating points can lead to minute errors. We round transformed values to approximately
// three decimal places so that values like 0.99997 show up as 1.0.
inline float roundTransformedCoords(float val) {
    // Use a power to two to approximate three decimal places to potentially reduce some cycles.
    // This should be at least as precise as MotionEvent::ROUNDING_PRECISION.
    return std::round(val * 1024.f) / 1024.f;
}

inline vec2 roundTransformedCoords(vec2 p) {
    return {roundTransformedCoords(p.x), roundTransformedCoords(p.y)};
}

vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy) {
    const vec2 transformedXy = transform.transform(xy);
    const vec2 transformedOrigin = transform.transform(0, 0);
    return transformedXy - transformedOrigin;
    return roundTransformedCoords(transformedXy - transformedOrigin);
}

const char* inputEventTypeToString(int32_t type) {
@@ -548,12 +561,12 @@ int MotionEvent::getSurfaceRotation() const {

float MotionEvent::getXCursorPosition() const {
    vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition());
    return vals.x;
    return roundTransformedCoords(vals.x);
}

float MotionEvent::getYCursorPosition() const {
    vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition());
    return vals.y;
    return roundTransformedCoords(vals.y);
}

void MotionEvent::setCursorPosition(float x, float y) {
@@ -875,7 +888,7 @@ std::string MotionEvent::actionToString(int32_t action) {
static inline vec2 calculateTransformedXYUnchecked(uint32_t source, const ui::Transform& transform,
                                                   const vec2& xy) {
    return shouldDisregardOffset(source) ? transformWithoutTranslation(transform, xy)
                                         : transform.transform(xy);
                                         : roundTransformedCoords(transform.transform(xy));
}

vec2 MotionEvent::calculateTransformedXY(uint32_t source, const ui::Transform& transform,
+192 −126

File changed.

Preview size limit exceeded, changes collapsed.

+12 −8

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4

File changed.

Preview size limit exceeded, changes collapsed.