Merge "Eliminate redundant time parameter from gesture detection code" into jb-mr1-dev
diff --git a/dictionaries/en_whitelist.xml b/dictionaries/en_whitelist.xml
index f112077..e11935f 100644
--- a/dictionaries/en_whitelist.xml
+++ b/dictionaries/en_whitelist.xml
@@ -19,13 +19,13 @@
 -->
 <shortcuts>
  <entry shortcut="ill">
-  <target replacement="I\'ll" priority="whitelist" />
+  <target replacement="I'll" priority="whitelist" />
  </entry>
  <entry shortcut="acomodate">
   <target replacement="accommodate" priority="whitelist" />
  </entry>
  <entry shortcut="aint">
-  <target replacement="ain\'t" priority="whitelist" />
+  <target replacement="ain't" priority="whitelist" />
  </entry>
  <entry shortcut="alot">
   <target replacement="a lot" priority="whitelist" />
@@ -34,7 +34,7 @@
   <target replacement="and the" priority="whitelist" />
  </entry>
  <entry shortcut="arent">
-  <target replacement="aren\'t" priority="whitelist" />
+  <target replacement="aren't" priority="whitelist" />
  </entry>
  <entry shortcut="bern">
   <target replacement="been" priority="whitelist" />
@@ -49,13 +49,13 @@
   <target replacement="can" priority="whitelist" />
  </entry>
  <entry shortcut="cant">
-  <target replacement="can\'t" priority="whitelist" />
+  <target replacement="can't" priority="whitelist" />
  </entry>
  <entry shortcut="dame">
   <target replacement="same" priority="whitelist" />
  </entry>
  <entry shortcut="didint">
-  <target replacement="didn\'t" priority="whitelist" />
+  <target replacement="didn't" priority="whitelist" />
  </entry>
  <entry shortcut="dormer">
   <target replacement="former" priority="whitelist" />
@@ -82,13 +82,13 @@
   <target replacement="too" priority="whitelist" />
  </entry>
  <entry shortcut="hed">
-  <target replacement="he\'d" priority="whitelist" />
+  <target replacement="he'd" priority="whitelist" />
  </entry>
  <entry shortcut="hel">
-  <target replacement="he\'ll" priority="whitelist" />
+  <target replacement="he'll" priority="whitelist" />
  </entry>
  <entry shortcut="heres">
-  <target replacement="here\'s" priority="whitelist" />
+  <target replacement="here's" priority="whitelist" />
  </entry>
  <entry shortcut="hew">
   <target replacement="new" priority="whitelist" />
@@ -97,19 +97,19 @@
   <target replacement="how" priority="whitelist" />
  </entry>
  <entry shortcut="hoes">
-  <target replacement="how\'s" priority="whitelist" />
+  <target replacement="how's" priority="whitelist" />
  </entry>
  <entry shortcut="howd">
-  <target replacement="how\'d" priority="whitelist" />
+  <target replacement="how'd" priority="whitelist" />
  </entry>
  <entry shortcut="howll">
-  <target replacement="how\'ll" priority="whitelist" />
+  <target replacement="how'll" priority="whitelist" />
  </entry>
  <entry shortcut="hows">
-  <target replacement="how\'s" priority="whitelist" />
+  <target replacement="how's" priority="whitelist" />
  </entry>
  <entry shortcut="howve">
-  <target replacement="how\'ve" priority="whitelist" />
+  <target replacement="how've" priority="whitelist" />
  </entry>
  <entry shortcut="hum">
   <target replacement="him" priority="whitelist" />
@@ -121,25 +121,25 @@
   <target replacement="its" priority="whitelist" />
  </entry>
  <entry shortcut="il">
-  <target replacement="I\'ll" priority="whitelist" />
+  <target replacement="I'll" priority="whitelist" />
  </entry>
  <entry shortcut="im">
-  <target replacement="I\'m" priority="whitelist" />
+  <target replacement="I'm" priority="whitelist" />
  </entry>
  <entry shortcut="inteh">
   <target replacement="in the" priority="whitelist" />
  </entry>
  <entry shortcut="itd">
-  <target replacement="it\'d" priority="whitelist" />
+  <target replacement="it'd" priority="whitelist" />
  </entry>
  <entry shortcut="itsa">
-  <target replacement="it\'s a" priority="whitelist" />
+  <target replacement="it's a" priority="whitelist" />
  </entry>
  <entry shortcut="lets">
-  <target replacement="let\'s" priority="whitelist" />
+  <target replacement="let's" priority="whitelist" />
  </entry>
  <entry shortcut="maam">
-  <target replacement="ma\'am" priority="whitelist" />
+  <target replacement="ma'am" priority="whitelist" />
  </entry>
  <entry shortcut="manu">
   <target replacement="many" priority="whitelist" />
@@ -196,10 +196,10 @@
   <target replacement="took" priority="whitelist" />
  </entry>
  <entry shortcut="shel">
-  <target replacement="she\'ll" priority="whitelist" />
+  <target replacement="she'll" priority="whitelist" />
  </entry>
  <entry shortcut="shouldent">
-  <target replacement="shouldn\'t" priority="whitelist" />
+  <target replacement="shouldn't" priority="whitelist" />
  </entry>
  <entry shortcut="sill">
   <target replacement="will" priority="whitelist" />
@@ -208,7 +208,7 @@
   <target replacement="down" priority="whitelist" />
  </entry>
  <entry shortcut="thatd">
-  <target replacement="that\'d" priority="whitelist" />
+  <target replacement="that'd" priority="whitelist" />
  </entry>
  <entry shortcut="tine">
   <target replacement="time" priority="whitelist" />
@@ -238,60 +238,60 @@
   <target replacement="weird" priority="whitelist" />
  </entry>
  <entry shortcut="wel">
-  <target replacement="we\'ll" priority="whitelist" />
+  <target replacement="we'll" priority="whitelist" />
  </entry>
  <entry shortcut="wer">
-  <target replacement="we\'re" priority="whitelist" />
+  <target replacement="we're" priority="whitelist" />
  </entry>
  <entry shortcut="whatd">
-  <target replacement="what\'d" priority="whitelist" />
+  <target replacement="what'd" priority="whitelist" />
  </entry>
  <entry shortcut="whatm">
-  <target replacement="what\'m" priority="whitelist" />
+  <target replacement="what'm" priority="whitelist" />
  </entry>
  <entry shortcut="whatre">
-  <target replacement="what\'re" priority="whitelist" />
+  <target replacement="what're" priority="whitelist" />
  </entry>
  <entry shortcut="whats">
-  <target replacement="what\'s" priority="whitelist" />
+  <target replacement="what's" priority="whitelist" />
  </entry>
  <entry shortcut="whens">
-  <target replacement="when\'s" priority="whitelist" />
+  <target replacement="when's" priority="whitelist" />
  </entry>
  <entry shortcut="whered">
-  <target replacement="where\'d" priority="whitelist" />
+  <target replacement="where'd" priority="whitelist" />
  </entry>
  <entry shortcut="wherell">
-  <target replacement="where\'ll" priority="whitelist" />
+  <target replacement="where'll" priority="whitelist" />
  </entry>
  <entry shortcut="wheres">
-  <target replacement="where\'s" priority="whitelist" />
+  <target replacement="where's" priority="whitelist" />
  </entry>
  <entry shortcut="wholl">
-  <target replacement="who\'ll" priority="whitelist" />
+  <target replacement="who'll" priority="whitelist" />
  </entry>
  <entry shortcut="whove">
-  <target replacement="who\'ve" priority="whitelist" />
+  <target replacement="who've" priority="whitelist" />
  </entry>
  <entry shortcut="whyd">
-  <target replacement="why\'d" priority="whitelist" />
+  <target replacement="why'd" priority="whitelist" />
  </entry>
  <entry shortcut="whyll">
-  <target replacement="why\'ll" priority="whitelist" />
+  <target replacement="why'll" priority="whitelist" />
  </entry>
  <entry shortcut="whys">
-  <target replacement="why\'s" priority="whitelist" />
+  <target replacement="why's" priority="whitelist" />
  </entry>
  <entry shortcut="whyve">
-  <target replacement="why\'ve" priority="whitelist" />
+  <target replacement="why've" priority="whitelist" />
  </entry>
  <entry shortcut="wont">
-  <target replacement="won\'t" priority="whitelist" />
+  <target replacement="won't" priority="whitelist" />
  </entry>
  <entry shortcut="yall">
-  <target replacement="y\'all" priority="whitelist" />
+  <target replacement="y'all" priority="whitelist" />
  </entry>
  <entry shortcut="youd">
-  <target replacement="you\'d" priority="whitelist" />
+  <target replacement="you'd" priority="whitelist" />
  </entry>
 </shortcuts>
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 6969037..7d565a6 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -520,7 +520,7 @@
 
     public void drawGestureTrail(Canvas canvas, Paint paint) {
         if (mInGesture) {
-            mGestureStroke.drawGestureTrail(canvas, paint, mLastX, mLastY);
+            mGestureStroke.drawGestureTrail(canvas, paint);
         }
     }
 
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
index da57b5a..79e977a 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
@@ -144,20 +144,21 @@
         mLastIncrementalBatchSize = size;
     }
 
-    private static float getDistance(final int p1x, final int p1y,
-            final int p2x, final int p2y) {
-        final float dx = p1x - p2x;
-        final float dy = p1y - p2y;
+    private static float getDistance(final int x1, final int y1, final int x2, final int y2) {
+        final float dx = x1 - x2;
+        final float dy = y1 - y2;
         // Note that, in recent versions of Android, FloatMath is actually slower than
         // java.lang.Math due to the way the JIT optimizes java.lang.Math.
         return (float)Math.sqrt(dx * dx + dy * dy);
     }
 
-    private static float getAngle(final int p1x, final int p1y, final int p2x, final int p2y) {
-        final int dx = p1x - p2x;
-        final int dy = p1y - p2y;
+    private static float getAngle(final int x1, final int y1, final int x2, final int y2) {
+        final int dx = x1 - x2;
+        final int dy = y1 - y2;
         if (dx == 0 && dy == 0) return 0;
-        return (float)Math.atan2(dy, dx);
+        // Would it be faster to call atan2f() directly via JNI?  Not sure about what the JIT
+        // does with Math.atan2().
+        return (float)Math.atan2((double)dy, (double)dx);
     }
 
     private static float getAngleDiff(final float a1, final float a2) {
@@ -168,12 +169,12 @@
         return diff;
     }
 
-    public void drawGestureTrail(Canvas canvas, Paint paint, int lastX, int lastY) {
+    public void drawGestureTrail(final Canvas canvas, final Paint paint) {
         // TODO: These paint parameter interpolation should be tunable, possibly introduce an object
         // that implements an interface such as Paint getPaint(int step, int strokePoints)
         final int size = mXCoordinates.getLength();
-        int[] xCoords = mXCoordinates.getPrimitiveArray();
-        int[] yCoords = mYCoordinates.getPrimitiveArray();
+        final int[] xCoords = mXCoordinates.getPrimitiveArray();
+        final int[] yCoords = mYCoordinates.getPrimitiveArray();
         int alpha = Constants.Color.ALPHA_OPAQUE;
         for (int i = size - 1; i > 0 && alpha > 0; i--) {
             paint.setAlpha(alpha);
@@ -181,9 +182,6 @@
                 alpha -= DRAWING_GESTURE_FADE_RATE;
             }
             canvas.drawLine(xCoords[i - 1], yCoords[i - 1], xCoords[i], yCoords[i], paint);
-            if (i == size - 1) {
-                canvas.drawLine(lastX, lastY, xCoords[i], yCoords[i], paint);
-            }
         }
     }
 }
diff --git a/native/jni/src/dictionary.cpp b/native/jni/src/dictionary.cpp
index 75d566c..9e4bd15 100644
--- a/native/jni/src/dictionary.cpp
+++ b/native/jni/src/dictionary.cpp
@@ -47,8 +47,6 @@
             fullWordMultiplier, maxWordLength, maxWords, options);
     mBigramDictionary = new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions);
     mGestureDecoder = new GestureDecoderWrapper(maxWordLength, maxWords);
-    mGestureDecoder->setDict(mUnigramDictionary, mBigramDictionary,
-            mOffsetDict /* dict root */, 0 /* root pos */);
 }
 
 Dictionary::~Dictionary() {
diff --git a/native/jni/src/geometry_utils.h b/native/jni/src/geometry_utils.h
index 168542e..deb0425 100644
--- a/native/jni/src/geometry_utils.h
+++ b/native/jni/src/geometry_utils.h
@@ -28,38 +28,36 @@
 
 namespace latinime {
 
-static inline float sqrf(float x) {
+static inline float squareFloat(float x) {
     return x * x;
 }
 
-static inline float getNormalizedSqrDistanceFloat(int x1, int y1, int x2, int y2, int scale) {
-    return sqrf(static_cast<float>(x1 - x2) / static_cast<float>(scale))
-            + sqrf(static_cast<float>(y1 - y2) / static_cast<float>(scale));
+static inline float getNormalizedSquaredDistanceFloat(float x1, float y1, float x2, float y2,
+        float scale) {
+    return squareFloat((x1 - x2) / scale) + squareFloat((y1 - y2) / scale);
 }
 
-static inline float getDistanceSqrFloat(float x1, float y1, float x2, float y2) {
-    return sqrf(x2 - x1) + sqrf(y2 - y1);
+static inline float getSquaredDistanceFloat(float x1, float y1, float x2, float y2) {
+    return squareFloat(x1 - x2) + squareFloat(y1 - y2);
+}
+
+static inline float getDistanceFloat(float x1, float y1, float x2, float y2) {
+    return hypotf(x1 - x2, y1 - y2);
 }
 
 static inline int getDistanceInt(int x1, int y1, int x2, int y2) {
-    return static_cast<int>(
-            sqrtf(getDistanceSqrFloat(
-                    static_cast<float>(x1), static_cast<float>(y1),
-                    static_cast<float>(x2), static_cast<float>(y2))));
+    return static_cast<int>(getDistanceFloat(static_cast<float>(x1), static_cast<float>(y1),
+            static_cast<float>(x2), static_cast<float>(y2)));
 }
 
 static inline float getAngle(int x1, int y1, int x2, int y2) {
     const int dx = x1 - x2;
     const int dy = y1 - y2;
-    if (dx == 0 && dy == 0) {
-        return 0;
-    }
-    const float dxf = static_cast<float>(dx);
-    const float dyf = static_cast<float>(dy);
-    return atan2f(dyf, dxf);
+    if (dx == 0 && dy == 0) return 0;
+    return atan2f(static_cast<float>(dy), static_cast<float>(dx));
 }
 
-static inline float angleDiff(float a1, float a2) {
+static inline float getAngleDiff(float a1, float a2) {
     const float diff = fabsf(a1 - a2);
     if (diff > M_PI_F) {
         return 2.0f * M_PI_F - diff;
@@ -67,7 +65,7 @@
     return diff;
 }
 
-// static float pointToLineDistanceSqrFloat(
+// static float pointToLineSegSquaredDistanceFloat(
 //         float x, float y, float x1, float y1, float x2, float y2) {
 //     float A = x - x1;
 //     float B = y - y1;
@@ -76,7 +74,7 @@
 //     return fabsf(A * D - C * B) / sqrtf(C * C + D * D);
 // }
 
-static inline float pointToLineSegDistanceSqrFloat(
+static inline float pointToLineSegSquaredDistanceFloat(
         float x, float y, float x1, float y1, float x2, float y2) {
     const float ray1x = x - x1;
     const float ray1y = y - y1;
@@ -84,7 +82,7 @@
     const float ray2y = y2 - y1;
 
     const float dotProduct = ray1x * ray2x + ray1y * ray2y;
-    const float lineLengthSqr = sqrf(ray2x) + sqrf(ray2y);
+    const float lineLengthSqr = squareFloat(ray2x) + squareFloat(ray2y);
     const float projectionLengthSqr = dotProduct / lineLengthSqr;
 
     float projectionX;
@@ -99,7 +97,7 @@
         projectionX = x1 + projectionLengthSqr * ray2x;
         projectionY = y1 + projectionLengthSqr * ray2y;
     }
-    return getDistanceSqrFloat(x, y, projectionX, projectionY);
+    return getSquaredDistanceFloat(x, y, projectionX, projectionY);
 }
 } // namespace latinime
 #endif // LATINIME_GEOMETRY_UTILS_H
diff --git a/native/jni/src/gesture/gesture_decoder_wrapper.h b/native/jni/src/gesture/gesture_decoder_wrapper.h
index 4a26d9c..f8bfe7c 100644
--- a/native/jni/src/gesture/gesture_decoder_wrapper.h
+++ b/native/jni/src/gesture/gesture_decoder_wrapper.h
@@ -48,14 +48,6 @@
                 inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
     }
 
-    void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram,
-            const uint8_t *dictRoot, int rootPos) {
-        if (!mIncrementalDecoderInterface) {
-            return;
-        }
-        mIncrementalDecoderInterface->setDict(dict, bigram, dictRoot, rootPos);
-    }
-
     static void setGestureDecoderFactoryMethod(
             IncrementalDecoderInterface *(*factoryMethod)(int, int)) {
         sGestureDecoderFactoryMethod = factoryMethod;
diff --git a/native/jni/src/gesture/incremental_decoder_interface.h b/native/jni/src/gesture/incremental_decoder_interface.h
index e940344..04f0095 100644
--- a/native/jni/src/gesture/incremental_decoder_interface.h
+++ b/native/jni/src/gesture/incremental_decoder_interface.h
@@ -32,8 +32,6 @@
             int *inputXs, int *inputYs, int *times, int *pointerIds, int *codes,
             int inputSize, int commitPoint, unsigned short *outWords, int *frequencies,
             int *outputIndices, int *outputTypes) = 0;
-    virtual void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram,
-            const uint8_t *dictRoot, int rootPos) = 0;
     IncrementalDecoderInterface() { };
     virtual ~IncrementalDecoderInterface() { };
  private:
diff --git a/native/jni/src/gesture/incremental_decoder_wrapper.h b/native/jni/src/gesture/incremental_decoder_wrapper.h
index f47d539..5cb2ee3 100644
--- a/native/jni/src/gesture/incremental_decoder_wrapper.h
+++ b/native/jni/src/gesture/incremental_decoder_wrapper.h
@@ -48,14 +48,6 @@
                 inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
     }
 
-    void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram,
-            const uint8_t *dictRoot, int rootPos) {
-        if (!mIncrementalDecoderInterface) {
-            return;
-        }
-        mIncrementalDecoderInterface->setDict(dict, bigram, dictRoot, rootPos);
-    }
-
     static void setIncrementalDecoderFactoryMethod(
             IncrementalDecoderInterface *(*factoryMethod)(int, int)) {
         sIncrementalDecoderFactoryMethod = factoryMethod;