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

Commit b77da615 authored by Jozef BABJAK's avatar Jozef BABJAK Committed by Steve Kondik
Browse files

Implementing more robust equality check.

Because of rounding in floating point operations, direct equality
check is not reliable. This implements robust method evaluating
distance of two numbers and comparing it to small enough constant.

Change-Id: I2d71bd0ad6524c015676f0c57c6070eede968709
parent 1ed0b587
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import static android.gesture.GestureConstants.*;
 */
public final class GestureUtils {
  
    /** Delta used for floating point equality checks. */
    private static final float FP_EQUALITY_DELTA = 1e-8f;
    private static final float SCALING_THRESHOLD = 0.26f;
    private static final float NONUNIFORM_SCALE = (float) Math.sqrt(2);
    
@@ -548,7 +550,7 @@ public final class GestureUtils {
        float rightside = (float) Math.sqrt(Math.pow(value, 2) - b);
        float lambda1 = -value + rightside;
        float lambda2 = -value - rightside;
        if (lambda1 == lambda2) {
        if (Math.abs(lambda1 - lambda2) < FP_EQUALITY_DELTA) {
            targetVector[0] = 0;
            targetVector[1] = 0;
        } else {