ImmediateInterpreter: properly scroll, point

This fixes 2 bugs that were found with the activity log/replay
(yay!). We need to increase the pressure difference threshold between
thumb and finger, as two fingers were accidentally being classified as
a finger + thumb.

Also, due to a mistaken dy computation, we were failing to classify
fingers as resting thumbs that were in the bottom zone.

BUG=chromium-os:21735
TEST=unittest; tested on device

Change-Id: Ia0e307480b2df8f3ff960eba1a931c1079c6113a
diff --git a/src/immediate_interpreter.cc b/src/immediate_interpreter.cc
index 83d515b..2f444f3 100644
--- a/src/immediate_interpreter.cc
+++ b/src/immediate_interpreter.cc
@@ -138,7 +138,7 @@
       evaluation_timeout_(prop_reg, "Evaluation Timeout", 0.2),
       two_finger_pressure_diff_thresh_(prop_reg,
                                        "Two Finger Pressure Diff Thresh",
-                                       27.0),
+                                       32.0),
       two_finger_close_distance_thresh_(prop_reg,
                                         "Two Finger Close Distance Thresh",
                                         40.0),
@@ -362,7 +362,7 @@
   if (pdiff > two_finger_pressure_diff_thresh_.val_)
     return false;
   float xdist = fabsf(finger1.position_x - finger2.position_x);
-  float ydist = fabsf(finger1.position_x - finger2.position_x);
+  float ydist = fabsf(finger1.position_y - finger2.position_y);
 
   // Next, make sure distance between fingers isn't too great
   if ((xdist * xdist + ydist * ydist) >
diff --git a/src/immediate_interpreter_unittest.cc b/src/immediate_interpreter_unittest.cc
index 0b4e2c1..5c2b09e 100644
--- a/src/immediate_interpreter_unittest.cc
+++ b/src/immediate_interpreter_unittest.cc
@@ -80,6 +80,71 @@
             ii.SyncInterpret(&hardware_states[4], NULL));
 }
 
+TEST(ImmediateInterpreterTest, MoveUpWithRestingThumbTest) {
+  ImmediateInterpreter ii(NULL);
+  HardwareProperties hwprops = {
+    0,  // left edge
+    0,  // top edge
+    1000,  // right edge
+    1000,  // bottom edge
+    50,  // pixels/TP width
+    50,  // pixels/TP height
+    96,  // screen DPI x
+    96,  // screen DPI y
+    2,  // max fingers
+    5,  // max touch
+    0,  // tripletap
+    0,  // semi-mt
+    1  // is button pad
+  };
+
+  FingerState finger_states[] = {
+    // TM, Tm, WM, Wm, Press, Orientation, X, Y, TrID
+    {0, 0, 0, 0, 10, 0, 500, 999, 1},
+    {0, 0, 0, 0, 10, 0, 500, 950, 2},
+    {0, 0, 0, 0, 10, 0, 500, 999, 1},
+    {0, 0, 0, 0, 10, 0, 500, 940, 2},
+    {0, 0, 0, 0, 10, 0, 500, 999, 1},
+    {0, 0, 0, 0, 10, 0, 500, 930, 2}
+  };
+  HardwareState hardware_states[] = {
+    // time, buttons down, finger count, finger states pointer
+    { 200000, 0, 2, 2, &finger_states[0] },
+    { 210000, 0, 2, 2, &finger_states[2] },
+    { 220000, 0, 2, 2, &finger_states[4] },
+    { 230000, 0, 0, 0, NULL },
+    { 240000, 0, 0, 0, NULL }
+  };
+
+  // Should fail w/o hardware props set
+  EXPECT_EQ(NULL, ii.SyncInterpret(&hardware_states[0], NULL));
+
+  ii.SetHardwareProperties(hwprops);
+
+  EXPECT_EQ(NULL, ii.SyncInterpret(&hardware_states[0], NULL));
+
+  Gesture* gs = ii.SyncInterpret(&hardware_states[1], NULL);
+  ASSERT_NE(reinterpret_cast<Gesture*>(NULL), gs);
+  EXPECT_EQ(kGestureTypeMove, gs->type);
+  EXPECT_EQ(0, gs->details.move.dx);
+  EXPECT_EQ(-10, gs->details.move.dy);
+  EXPECT_EQ(200000, gs->start_time);
+  EXPECT_EQ(210000, gs->end_time);
+
+  gs = ii.SyncInterpret(&hardware_states[2], NULL);
+  EXPECT_NE(reinterpret_cast<Gesture*>(NULL), gs);
+  EXPECT_EQ(kGestureTypeMove, gs->type);
+  EXPECT_EQ(0, gs->details.move.dx);
+  EXPECT_EQ(-10, gs->details.move.dy);
+  EXPECT_EQ(210000, gs->start_time);
+  EXPECT_EQ(220000, gs->end_time);
+
+  EXPECT_EQ(reinterpret_cast<Gesture*>(NULL),
+            ii.SyncInterpret(&hardware_states[3], NULL));
+  EXPECT_EQ(reinterpret_cast<Gesture*>(NULL),
+            ii.SyncInterpret(&hardware_states[4], NULL));
+}
+
 TEST(ImmediateInterpreterTest, ScrollUpTest) {
   ImmediateInterpreter ii(NULL);
   HardwareProperties hwprops = {
@@ -100,14 +165,14 @@
 
   FingerState finger_states[] = {
     // TM, Tm, WM, Wm, Press, Orientation, X, Y, TrID
-    {0, 0, 0, 0, 1, 0, 400, 900, 1},
-    {0, 0, 0, 0, 1, 0, 405, 900, 2},
+    {0, 0, 0, 0, 24, 0, 400, 900, 1},
+    {0, 0, 0, 0, 52, 0, 405, 900, 2},
 
-    {0, 0, 0, 0, 1, 0, 400, 800, 1},
-    {0, 0, 0, 0, 1, 0, 405, 800, 2},
+    {0, 0, 0, 0, 24, 0, 400, 800, 1},
+    {0, 0, 0, 0, 52, 0, 405, 800, 2},
 
-    {0, 0, 0, 0, 1, 0, 400, 700, 1},
-    {0, 0, 0, 0, 1, 0, 405, 700, 2},
+    {0, 0, 0, 0, 24, 0, 400, 700, 1},
+    {0, 0, 0, 0, 52, 0, 405, 700, 2},
   };
   HardwareState hardware_states[] = {
     // time, buttons, finger count, touch count, finger states pointer