Merge "Fix bimanual gesture preview trail" into jb-mr1-dev
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp
index 92cfd1a..15a7131 100644
--- a/native/jni/src/correction.cpp
+++ b/native/jni/src/correction.cpp
@@ -55,7 +55,7 @@
             }
             AKLOGI("[ %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d ]",
                     c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10]);
-            (void)c;
+            (void)c; // To suppress compiler warning
         }
     }
 }
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index c62b9b3..8c3174c 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -224,7 +224,7 @@
 bool ProximityInfoState::isPrevLocalMin(const NearKeysDistanceMap *const currentNearKeysDistances,
         const NearKeysDistanceMap *const prevNearKeysDistances,
         const NearKeysDistanceMap *const prevPrevNearKeysDistances) const {
-    static const float MARGIN = 0.05f;
+    static const float MARGIN = 0.01f;
 
     for (NearKeysDistanceMap::const_iterator it = prevNearKeysDistances->begin();
         it != prevNearKeysDistances->end(); ++it) {
@@ -245,16 +245,19 @@
         const NearKeysDistanceMap *const prevNearKeysDistances,
         const NearKeysDistanceMap *const prevPrevNearKeysDistances) const {
     static const float BASE_SAMPLE_RATE_SCALE = 0.1f;
-    static const float SAVE_DISTANCE_SCALE = 14.0f;
+    static const float SAVE_DISTANCE_SCALE = 20.0f;
     static const float SAVE_DISTANCE_SCORE = 2.0f;
-    static const float SKIP_DISTANCE_SCALE = 1.5f;
+    static const float SKIP_DISTANCE_SCALE = 2.5f;
     static const float SKIP_DISTANCE_SCORE = -1.0f;
-    static const float CHECK_LOCALMIN_DISTANCE_THRESHOLD_SCALE = 3.5f;
+    static const float CHECK_LOCALMIN_DISTANCE_THRESHOLD_SCALE = 4.0f;
     static const float CHECK_LOCALMIN_DISTANCE_SCORE = -1.0f;
-    static const float STRAIGHT_ANGLE_THRESHOLD = M_PI_F / 32.0f;
+    static const float STRAIGHT_ANGLE_THRESHOLD = M_PI_F / 36.0f;
     static const float STRAIGHT_SKIP_DISTANCE_THRESHOLD_SCALE = 5.0f;
     static const float STRAIGHT_SKIP_NEAREST_DISTANCE_THRESHOLD = 0.5f;
     static const float STRAIGHT_SKIP_SCORE = -1.0f;
+    static const float CORNER_ANGLE_THRESHOLD = M_PI_F / 2.0f;
+    static const float CORNER_CHECK_DISTANCE_THRESHOLD_SCALE = 2.7f;
+    static const float CORNER_SCORE = 1.0f;
 
     const std::size_t size = mInputXs.size();
     if (size <= 1) {
@@ -276,20 +279,26 @@
     }
     // Location
     if (distPrev < baseSampleRate * CHECK_LOCALMIN_DISTANCE_THRESHOLD_SCALE) {
-        if (!isPrevLocalMin(currentNearKeysDistances, currentNearKeysDistances,
+        if (!isPrevLocalMin(currentNearKeysDistances, prevNearKeysDistances,
             prevPrevNearKeysDistances)) {
             score += CHECK_LOCALMIN_DISTANCE_SCORE;
         }
     }
     // Angle
+    const float angle1 = getAngle(x, y, mInputXs.back(), mInputYs.back());
+    const float angle2 = getAngle(mInputXs.back(), mInputYs.back(),
+            mInputXs[size - 2], mInputYs[size - 2]);
+    const float angleDiff = getAngleDiff(angle1, angle2);
+    // Skip straight
     if (nearest > STRAIGHT_SKIP_NEAREST_DISTANCE_THRESHOLD
-            && distPrev < baseSampleRate * STRAIGHT_SKIP_DISTANCE_THRESHOLD_SCALE) {
-        const float angle1 = getAngle(x, y, mInputXs.back(), mInputYs.back());
-        const float angle2 = getAngle(mInputXs.back(), mInputYs.back(),
-                mInputXs[size - 2], mInputYs[size - 2]);
-        if (getAngleDiff(angle1, angle2) < STRAIGHT_ANGLE_THRESHOLD) {
-            score += STRAIGHT_SKIP_SCORE;
-        }
+            && distPrev < baseSampleRate * STRAIGHT_SKIP_DISTANCE_THRESHOLD_SCALE
+            && angleDiff < STRAIGHT_ANGLE_THRESHOLD) {
+        score += STRAIGHT_SKIP_SCORE;
+    }
+    // Save corner
+    if (distPrev > baseSampleRate * CORNER_CHECK_DISTANCE_THRESHOLD_SCALE
+            && angleDiff > CORNER_ANGLE_THRESHOLD) {
+        score += CORNER_SCORE;
     }
     return score;
 }
@@ -447,9 +456,9 @@
 
 float ProximityInfoState::getAveragePointDuration() const {
     if (mInputSize == 0) {
-        return 0;
+        return 0.0f;
     }
-    return (mTimes[mInputSize - 1] - mTimes[0]) / static_cast<float>(mInputSize);
+    return static_cast<float>(mTimes[mInputSize - 1] - mTimes[0]) / static_cast<float>(mInputSize);
 }
 
 } // namespace latinime
diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp
index cf806c1..6eaff48 100644
--- a/native/jni/src/unigram_dictionary.cpp
+++ b/native/jni/src/unigram_dictionary.cpp
@@ -225,7 +225,7 @@
             short unsigned int *w = outWords + j * MAX_WORD_LENGTH;
             char s[MAX_WORD_LENGTH];
             for (int i = 0; i <= MAX_WORD_LENGTH; i++) s[i] = w[i];
-            (void)s;
+            (void)s; // To suppress compiler warning
             AKLOGI("%s %i", s, frequencies[j]);
         }
     }