ImmediateInterpreter: Allow finger pairs to be slightly further apart.

We used to require two fingers to be 40mm apart or closer to perform a
two finger gesture (like right click). However, during a test with Ian
Fette, who has big hands, we found him having a lot of trouble right
clicking. This change increases the distance required for a right
click or any other two finger gesture.

We also take part of the log from Ian's test and turn it into a
unittest.

BUG=chromium-os:26945
TEST=unittest

Change-Id: I65d5e1ec43a04174da1fbdafb15cadfa736f7e21
diff --git a/src/immediate_interpreter.cc b/src/immediate_interpreter.cc
index 6e126bd..e821703 100644
--- a/src/immediate_interpreter.cc
+++ b/src/immediate_interpreter.cc
@@ -180,7 +180,7 @@
       palm_edge_min_width_(prop_reg, "Tap Exclusion Border Width", 8.0),
       palm_edge_width_(prop_reg, "Palm Edge Zone Width", 14.0),
       palm_edge_point_speed_(prop_reg, "Palm Edge Zone Min Point Speed", 100.0),
-      palm_min_distance_(prop_reg, "Palm Min Distance", 40.0),
+      palm_min_distance_(prop_reg, "Palm Min Distance", 50.0),
       wiggle_max_dist_(prop_reg, "Wiggle Max Distance", 4.0),
       wiggle_suppress_timeout_(prop_reg, "Wiggle Timeout", 0.075),
       wiggle_button_down_timeout_(prop_reg, "Wiggle Button Down Timeout", 0.75),
@@ -196,7 +196,7 @@
       thumb_eval_timeout_(prop_reg, "Thumb Evaluation Timeout", 0.06),
       two_finger_close_distance_thresh_(prop_reg,
                                         "Two Finger Close Distance Thresh",
-                                        40.0),
+                                        50.0),
       two_finger_scroll_distance_thresh_(prop_reg,
                                          "Two Finger Scroll Distance Thresh",
                                          2.0),
diff --git a/src/immediate_interpreter_unittest.cc b/src/immediate_interpreter_unittest.cc
index d6d4272..95dd906 100644
--- a/src/immediate_interpreter_unittest.cc
+++ b/src/immediate_interpreter_unittest.cc
@@ -1471,6 +1471,163 @@
   }
 }
 
+struct BigHandsRightClickInputAndExpectations {
+  HardwareState hs;
+  unsigned out_buttons_down;
+  unsigned out_buttons_up;
+  FingerState fs[2];
+};
+
+// This was recorded from Ian Fette, who had trouble right-clicking.
+// This test plays back part of his log to ensure that it generates a
+// right click.
+TEST(ImmediateInterpreterTest, BigHandsRightClickTest) {
+  HardwareProperties hwprops = {
+    0,  // left edge
+    0,  // top edge
+    106.666672,  // right edge
+    68.000000,  // bottom edge
+    1,  // pixels/TP width
+    1,  // pixels/TP height
+    25.4,  // screen DPI x
+    25.4,  // screen DPI y
+    15,  // max fingers
+    5,  // max touch
+    0,  // t5r2
+    0,  // semi-mt
+    true  // is button pad
+  };
+  BigHandsRightClickInputAndExpectations records[] = {
+    { { 1329527921.327647, 0, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 50.013428, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 41.862095, 0, 57.458694, 43.700001, 131 } } },
+    { { 1329527921.344421, 0, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 50.301102, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.007469, 0, 57.479977, 43.700001, 131 } } },
+    { { 1329527921.361196, 1, 2, 2, NULL }, GESTURES_BUTTON_RIGHT, 0,
+      { { 0, 0, 0, 0, 50.608433, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.065464, 0, 57.494164, 43.700001, 131 } } },
+    { { 1329527921.372364, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 50.840954, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.071739, 0, 57.507217, 43.700001, 131 } } },
+    { { 1329527921.383517, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 51.047310, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.054974, 0, 57.527523, 43.700001, 131 } } },
+    { { 1329527921.394680, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 51.355824, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.066948, 0, 57.550964, 43.700001, 131 } } },
+    { { 1329527921.405842, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 51.791901, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.188736, 0, 57.569374, 43.700001, 131 } } },
+    { { 1329527921.416791, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 52.264156, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.424179, 0, 57.586361, 43.700001, 131 } } },
+    { { 1329527921.427937, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 52.725105, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.676739, 0, 57.609421, 43.700001, 131 } } },
+    { { 1329527921.439094, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 53.191925, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 42.868217, 0, 57.640007, 43.700001, 131 } } },
+    { { 1329527921.461392, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 53.602665, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.016544, 0, 57.676689, 43.700001, 131 } } },
+    { { 1329527921.483690, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 53.879429, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.208221, 0, 57.711613, 43.700001, 131 } } },
+    { { 1329527921.511815, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 54.059937, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.467258, 0, 57.736385, 43.700001, 131 } } },
+    { { 1329527921.539940, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 54.253189, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.717934, 0, 57.750286, 43.700001, 131 } } },
+    { { 1329527921.556732, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 54.500740, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.863792, 0, 57.758759, 43.700001, 131 } } },
+    { { 1329527921.573523, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 54.737640, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.825844, 0, 57.771137, 43.700001, 131 } } },
+    { { 1329527921.584697, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 54.906223, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.654804, 0, 57.790218, 43.700001, 131 } } },
+    { { 1329527921.595872, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.001118, 0, 20.250002, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.542431, 0, 57.809731, 43.700001, 131 } } },
+    { { 1329527921.618320, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.039989, 0, 20.252811, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.585777, 0, 57.824154, 43.700001, 131 } } },
+    { { 1329527921.640768, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.045246, 0, 20.264456, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.715435, 0, 57.832584, 43.700001, 131 } } },
+    { { 1329527921.691161, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.068935, 0, 20.285036, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.845741, 0, 57.836266, 43.700001, 131 } } },
+    { { 1329527921.741554, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.195026, 0, 20.306564, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.941154, 0, 57.836994, 43.700001, 131 } } },
+    { { 1329527921.758389, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.430550, 0, 20.322674, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.962692, 0, 57.836308, 43.700001, 131 } } },
+    { { 1329527921.775225, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.681423, 0, 20.332201, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.846741, 0, 57.835224, 43.700001, 131 } } },
+    { { 1329527921.786418, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.803486, 0, 20.336439, 59.400002, 130 },
+        { 0, 0, 0, 0, 43.604134, 0, 57.834267, 43.700001, 131 } } },
+    { { 1329527921.803205, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.738258, 0, 20.337351, 59.396629, 130 },
+        { 0, 0, 0, 0, 43.340977, 0, 57.833622, 43.700001, 131 } } },
+    { { 1329527921.819993, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.647045, 0, 20.336643, 59.382656, 130 },
+        { 0, 0, 0, 0, 43.140343, 0, 57.833279, 43.700001, 131 } } },
+    { { 1329527921.831121, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.670898, 0, 20.335459, 59.357960, 130 },
+        { 0, 0, 0, 0, 43.019653, 0, 57.827530, 43.700001, 131 } } },
+    { { 1329527921.842232, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.769543, 0, 20.334396, 59.332127, 130 },
+        { 0, 0, 0, 0, 42.964531, 0, 57.807049, 43.700001, 131 } } },
+    { { 1329527921.853342, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.872444, 0, 20.333672, 59.312794, 130 },
+        { 0, 0, 0, 0, 42.951347, 0, 57.771957, 43.700001, 131 } } },
+    { { 1329527921.864522, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.949341, 0, 20.333281, 59.301361, 130 },
+        { 0, 0, 0, 0, 42.959034, 0, 57.729061, 43.700001, 131 } } },
+    { { 1329527921.875702, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.994751, 0, 20.333134, 59.296276, 130 },
+        { 0, 0, 0, 0, 42.973259, 0, 57.683277, 43.700001, 131 } } },
+    { { 1329527921.886840, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 56.014912, 0, 20.333128, 59.295181, 130 },
+        { 0, 0, 0, 0, 42.918892, 0, 57.640221, 43.700001, 131 } } },
+    { { 1329527921.898031, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.951756, 0, 20.333181, 59.296028, 130 },
+        { 0, 0, 0, 0, 42.715969, 0, 57.601479, 43.700001, 131 } } },
+    { { 1329527921.909149, 1, 2, 2, NULL }, 0, 0,
+      { { 0, 0, 0, 0, 55.736336, 0, 20.333244, 59.297451, 130 },
+        { 0, 0, 0, 0, 42.304108, 0, 57.563725, 43.700001, 131 } } },
+    { { 1329527921.920301, 0, 2, 2, NULL }, 0, GESTURES_BUTTON_RIGHT,
+      { { 0, 0, 0, 0, 55.448730, 0, 20.333294, 59.298725, 130 },
+        { 0, 0, 0, 0, 41.444939, 0, 57.525326, 43.700001, 131 } } }
+  };
+  ImmediateInterpreter ii(NULL);
+  ii.SetHardwareProperties(hwprops);
+  for (size_t i = 0; i < arraysize(records); i++) {
+    // Make the hwstate point to the fingers
+    HardwareState* hs = &records[i].hs;
+    hs->fingers = records[i].fs;
+    Gesture* gs_out = ii.SyncInterpret(hs, NULL);
+    if (!gs_out || gs_out->type != kGestureTypeButtonsChange) {
+      // We got no output buttons gesture. Make sure we expected that
+      EXPECT_EQ(0, records[i].out_buttons_down);
+      EXPECT_EQ(0, records[i].out_buttons_up);
+    } else if (gs_out) {
+      // We got a buttons gesture
+      EXPECT_EQ(gs_out->details.buttons.down, records[i].out_buttons_down);
+      EXPECT_EQ(gs_out->details.buttons.up, records[i].out_buttons_up);
+    } else {
+      ADD_FAILURE();  // This should be unreachable
+    }
+  }
+}
+
 TEST(ImmediateInterpreterTest, ChangeTimeoutTest) {
   ImmediateInterpreter ii(NULL);
   HardwareProperties hwprops = {