Clean up constructors

And, use C++ style casts and use float math functions rather than double ones to save memory space.

Also, stop using FloatMath and NativeUtils as standard Math methods are faster now.
See http://code.google.com/p/android/issues/detail?id=36199 and https://android-review.googlesource.com/40700

multi-project commit with I4259fb5ab8a15ac5760a7f04fc8f4c860529f04a

Change-Id: I0b81cff8c91769f7559a59b9528c75a5aabb4211
diff --git a/native/jni/src/bigram_dictionary.cpp b/native/jni/src/bigram_dictionary.cpp
index 2201711..df1ebc0 100644
--- a/native/jni/src/bigram_dictionary.cpp
+++ b/native/jni/src/bigram_dictionary.cpp
@@ -60,14 +60,15 @@
         AKLOGI("Bigram: InsertAt -> %d MAX_PREDICTIONS: %d", insertAt, MAX_PREDICTIONS);
     }
     if (insertAt < MAX_PREDICTIONS) {
-        memmove((char*) bigramFreq + (insertAt + 1) * sizeof(bigramFreq[0]),
-               (char*) bigramFreq + insertAt * sizeof(bigramFreq[0]),
-               (MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0]));
+        memmove(reinterpret_cast<char *>(bigramFreq) + (insertAt + 1) * sizeof(bigramFreq[0]),
+                reinterpret_cast<char *>(bigramFreq) + insertAt * sizeof(bigramFreq[0]),
+                (MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0]));
         bigramFreq[insertAt] = frequency;
         outputTypes[insertAt] = Dictionary::KIND_PREDICTION;
-        memmove((char*) bigramChars + (insertAt + 1) * MAX_WORD_LENGTH * sizeof(short),
-               (char*) bigramChars + (insertAt    ) * MAX_WORD_LENGTH * sizeof(short),
-               (MAX_PREDICTIONS - insertAt - 1) * sizeof(short) * MAX_WORD_LENGTH);
+        memmove(reinterpret_cast<char *>(bigramChars)
+                + (insertAt + 1) * MAX_WORD_LENGTH * sizeof(short),
+                reinterpret_cast<char *>(bigramChars) + insertAt * MAX_WORD_LENGTH * sizeof(short),
+                (MAX_PREDICTIONS - insertAt - 1) * sizeof(short) * MAX_WORD_LENGTH);
         unsigned short *dest = bigramChars + (insertAt    ) * MAX_WORD_LENGTH;
         while (length--) {
             *dest++ = *word++;
diff --git a/native/jni/src/char_utils.cpp b/native/jni/src/char_utils.cpp
index 45d49b0..fc0a059 100644
--- a/native/jni/src/char_utils.cpp
+++ b/native/jni/src/char_utils.cpp
@@ -885,16 +885,17 @@
 };
 
 static int compare_pair_capital(const void *a, const void *b) {
-    return (int)(*(unsigned short *)a)
-            - (int)((struct LatinCapitalSmallPair*)b)->capital;
+    return static_cast<int>(*reinterpret_cast<const unsigned short *>(a))
+            - static_cast<int>(
+                    (reinterpret_cast<const struct LatinCapitalSmallPair *>(b))->capital);
 }
 
 unsigned short latin_tolower(unsigned short c) {
     struct LatinCapitalSmallPair *p =
-            (struct LatinCapitalSmallPair *)bsearch(&c, SORTED_CHAR_MAP,
+            reinterpret_cast<struct LatinCapitalSmallPair *>(bsearch(&c, SORTED_CHAR_MAP,
                     sizeof(SORTED_CHAR_MAP) / sizeof(SORTED_CHAR_MAP[0]),
                     sizeof(SORTED_CHAR_MAP[0]),
-                    compare_pair_capital);
+                    compare_pair_capital));
     return p ? p->small : c;
 }
 } // namespace latinime
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp
index b18b35e..e1f9db9 100644
--- a/native/jni/src/correction.cpp
+++ b/native/jni/src/correction.cpp
@@ -1092,7 +1092,7 @@
 // In dictionary.cpp, getSuggestion() method,
 // suggestion scores are computed using the below formula.
 // original score
-//  := pow(mTypedLetterMultiplier (this is defined 2),
+//  := powf(mTypedLetterMultiplier (this is defined 2),
 //         (the number of matched characters between typed word and suggested word))
 //     * (individual word's score which defined in the unigram dictionary,
 //         and this score is defined in range [0, 255].)
@@ -1104,11 +1104,11 @@
 //       capitalization, then treat it as if the score was 255.
 //     - If before.length() == after.length()
 //       => multiply by mFullWordMultiplier (this is defined 2))
-// So, maximum original score is pow(2, min(before.length(), after.length())) * 255 * 2 * 1.2
+// So, maximum original score is powf(2, min(before.length(), after.length())) * 255 * 2 * 1.2
 // For historical reasons we ignore the 1.2 modifier (because the measure for a good
 // autocorrection threshold was done at a time when it didn't exist). This doesn't change
 // the result.
-// So, we can normalize original score by dividing pow(2, min(b.l(),a.l())) * 255 * 2.
+// So, we can normalize original score by dividing powf(2, min(b.l(),a.l())) * 255 * 2.
 
 /* static */
 float Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short *before,
@@ -1130,7 +1130,7 @@
     }
 
     const float maxScore = score >= S_INT_MAX ? S_INT_MAX : MAX_INITIAL_SCORE
-            * pow(static_cast<float>(TYPED_LETTER_MULTIPLIER),
+            * powf(static_cast<float>(TYPED_LETTER_MULTIPLIER),
                     static_cast<float>(min(beforeLength, afterLength - spaceCount)))
             * FULL_WORD_MULTIPLIER;
 
diff --git a/native/jni/src/debug.h b/native/jni/src/debug.h
index 2168d66..2432b1f 100644
--- a/native/jni/src/debug.h
+++ b/native/jni/src/debug.h
@@ -58,11 +58,12 @@
 }
 
 static inline void printDebug(const char *tag, int *codes, int codesSize, int MAX_PROXIMITY_CHARS) {
-    unsigned char *buf = (unsigned char*)malloc((1 + codesSize) * sizeof(*buf));
+    unsigned char *buf = reinterpret_cast<unsigned char *>(malloc((1 + codesSize) * sizeof(*buf)));
 
     buf[codesSize] = 0;
-    while (--codesSize >= 0)
-        buf[codesSize] = (unsigned char)codes[codesSize * MAX_PROXIMITY_CHARS];
+    while (--codesSize >= 0) {
+        buf[codesSize] = static_cast<unsigned char>(codes[codesSize * MAX_PROXIMITY_CHARS]);
+    }
     AKLOGI("%s, WORD = %s", tag, buf);
 
     free(buf);
diff --git a/native/jni/src/dictionary.cpp b/native/jni/src/dictionary.cpp
index f3bdb31..75d566c 100644
--- a/native/jni/src/dictionary.cpp
+++ b/native/jni/src/dictionary.cpp
@@ -32,8 +32,8 @@
 Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
         int typedLetterMultiplier, int fullWordMultiplier,
         int maxWordLength, int maxWords, int maxPredictions)
-    : mDict((unsigned char*) dict),
-      mOffsetDict(((unsigned char*) dict) + BinaryFormat::getHeaderSize(mDict)),
+    : mDict(reinterpret_cast<unsigned char *>(dict)),
+      mOffsetDict((reinterpret_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
       mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) {
     if (DEBUG_DICT) {
         if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {
diff --git a/native/jni/src/dictionary.h b/native/jni/src/dictionary.h
index b550ba4..3b55e5d 100644
--- a/native/jni/src/dictionary.h
+++ b/native/jni/src/dictionary.h
@@ -55,8 +55,12 @@
 
     int getFrequency(const int32_t *word, int length) const;
     bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const;
-    void *getDict() const { return (void *)mDict; } // required to release dictionary buffer
-    void *getOffsetDict() const { return (void *)mOffsetDict; }
+    void *getDict() const { // required to release dictionary buffer
+        return reinterpret_cast<void *>(const_cast<unsigned char *>(mDict));
+    }
+    void *getOffsetDict() const {
+        return reinterpret_cast<void *>(const_cast<unsigned char *>(mOffsetDict));
+    }
     int getDictSize() const { return mDictSize; }
     int getMmapFd() const { return mMmapFd; }
     int getDictBufAdjust() const { return mDictBufAdjust; }
@@ -87,8 +91,9 @@
 inline int Dictionary::wideStrLen(unsigned short *str) {
     if (!str) return 0;
     unsigned short *end = str;
-    while (*end)
+    while (*end) {
         end++;
+    }
     return end - str;
 }
 } // namespace latinime
diff --git a/native/jni/src/geometry_utils.h b/native/jni/src/geometry_utils.h
index ada889e..65611b9 100644
--- a/native/jni/src/geometry_utils.h
+++ b/native/jni/src/geometry_utils.h
@@ -20,36 +20,43 @@
 #include <cmath>
 
 #define MAX_DISTANCE 10000000
-#define KEY_NUM 27
-#define SPACE_KEY 26
 #define MAX_PATHS 2
 
 #define DEBUG_DECODER false
 
+#define M_PI_F 3.14159265f
+
 namespace latinime {
 
-static inline float sqr(float x) {
+static inline float sqrf(float x) {
     return x * x;
 }
 
-static inline float getNormalizedSqrDistance(int x1, int y1, int x2, int y2, int scale) {
-    return sqr((x1 - x2) * 1.0 / scale) + sqr((y1 - y2) * 1.0 / scale);
+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 int getDistance(int x1, int y1, int x2, int y2) {
-    return (int) sqrt(sqr(x2 - x1) + sqr(y2 - y1));
+static inline float getDistanceSqrFloat(float x1, float y1, float x2, float y2) {
+    return sqrf(x2 - x1) + sqrf(y2 - y1);
 }
 
-static inline float getDistanceSq(float x1, float y1, float x2, float y2) {
-    return sqr(x2 - x1) + sqr(y2 - y1);
+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))));
 }
 
 static inline float getAngle(int x1, int y1, int x2, int y2) {
-    float dx = x1 - x2;
-    float dy = y1 - y2;
-    if (dx == 0 && dy == 0)
+    int dx = x1 - x2;
+    int dy = y1 - y2;
+    if (dx == 0 && dy == 0) {
         return 0;
-    return atan2(dy, dx);
+    }
+    float dxf = static_cast<float>(dx);
+    float dyf = static_cast<float>(dy);
+    return atan2f(dyf, dxf);
 }
 
 static inline float angleDiff(float a1, float a2) {
@@ -57,21 +64,22 @@
     if (diff < 0) {
         diff = -diff;
     }
-    if (diff > M_PI) {
-        return 2 * M_PI - diff;
+    if (diff > M_PI_F) {
+        return 2.0f * M_PI_F - diff;
     }
     return diff;
 }
 
-//static float pointToLineDistanceSq(float x, float y, float x1, float y1, float x2, float y2) {
-//    float A = x - x1;
-//    float B = y - y1;
-//    float C = x2 - x1;
-//    float D = y2 - y1;
-//    return abs(A * D - C * B) / sqrt(C * C + D * D);
-//}
+// static float pointToLineDistanceSqrFloat(
+//         float x, float y, float x1, float y1, float x2, float y2) {
+//     float A = x - x1;
+//     float B = y - y1;
+//     float C = x2 - x1;
+//     float D = y2 - y1;
+//     return abs(A * D - C * B) / sqrt(C * C + D * D);
+// }
 
-static inline float pointToLineSegDistanceSq(
+static inline float pointToLineSegDistanceSqrFloat(
         float x, float y, float x1, float y1, float x2, float y2) {
     float ray1x = x - x1;
     float ray1y = y - y1;
@@ -93,9 +101,7 @@
         projectionX = x1 + projectionLengthSq * ray2x;
         projectionY = y1 + projectionLengthSq * ray2y;
     }
-
-    float dist = getDistanceSq(x, y, projectionX, projectionY);
-    return dist;
+    return getDistanceSqrFloat(x, y, projectionX, projectionY);
 }
 } // namespace latinime
 #endif // LATINIME_INCREMENTAL_GEOMETRY_UTILS_H
diff --git a/native/jni/src/gesture/gesture_decoder_wrapper.h b/native/jni/src/gesture/gesture_decoder_wrapper.h
index 2b9054f..4a26d9c 100644
--- a/native/jni/src/gesture/gesture_decoder_wrapper.h
+++ b/native/jni/src/gesture/gesture_decoder_wrapper.h
@@ -62,7 +62,7 @@
     }
 
  private:
-    DISALLOW_COPY_AND_ASSIGN(GestureDecoderWrapper);
+    DISALLOW_IMPLICIT_CONSTRUCTORS(GestureDecoderWrapper);
     static IncrementalDecoderInterface *getGestureDecoderInstance(int maxWordLength, int maxWords) {
         if (sGestureDecoderFactoryMethod) {
             return sGestureDecoderFactoryMethod(maxWordLength, maxWords);
diff --git a/native/jni/src/gesture/incremental_decoder_interface.h b/native/jni/src/gesture/incremental_decoder_interface.h
index 3951514..e940344 100644
--- a/native/jni/src/gesture/incremental_decoder_interface.h
+++ b/native/jni/src/gesture/incremental_decoder_interface.h
@@ -34,9 +34,10 @@
             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:
-    //DISALLOW_COPY_AND_ASSIGN(IncrementalDecoderInterface);
+    DISALLOW_COPY_AND_ASSIGN(IncrementalDecoderInterface);
 };
 } // namespace latinime
 #endif // LATINIME_INCREMENTAL_DECODER_INTERFACE_H
diff --git a/native/jni/src/gesture/incremental_decoder_wrapper.h b/native/jni/src/gesture/incremental_decoder_wrapper.h
index 477b2cc..f47d539 100644
--- a/native/jni/src/gesture/incremental_decoder_wrapper.h
+++ b/native/jni/src/gesture/incremental_decoder_wrapper.h
@@ -62,7 +62,7 @@
     }
 
  private:
-    DISALLOW_COPY_AND_ASSIGN(IncrementalDecoderWrapper);
+    DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalDecoderWrapper);
     static IncrementalDecoderInterface *getIncrementalDecoderInstance(int maxWordLength,
             int maxWords) {
         if (sIncrementalDecoderFactoryMethod) {
diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp
index 18a0b74..ade78a1 100644
--- a/native/jni/src/proximity_info.cpp
+++ b/native/jni/src/proximity_info.cpp
@@ -248,7 +248,7 @@
     for (int i = 0; i < KEY_COUNT; i++) {
         mKeyKeyDistancesG[i][i] = 0;
         for (int j = i + 1; j < KEY_COUNT; j++) {
-            mKeyKeyDistancesG[i][j] = getDistance(
+            mKeyKeyDistancesG[i][j] = getDistanceInt(
                     mCenterXsG[i], mCenterYsG[i], mCenterXsG[j], mCenterYsG[j]);
             mKeyKeyDistancesG[j][i] = mKeyKeyDistancesG[i][j];
         }
@@ -290,7 +290,7 @@
 void ProximityInfo::getCenters(int *centerXs, int *centerYs, int *codeToKeyIndex,
         int *keyToCodeIndex, int *keyCount, int *keyWidth) const {
     *keyCount = KEY_COUNT;
-    *keyWidth = sqrt(static_cast<float>(MOST_COMMON_KEY_WIDTH_SQUARE));
+    *keyWidth = sqrtf(static_cast<float>(MOST_COMMON_KEY_WIDTH_SQUARE));
 
     for (int i = 0; i < KEY_COUNT; ++i) {
         const int code = mKeyCharCodes[i];
diff --git a/native/jni/src/words_priority_queue.h b/native/jni/src/words_priority_queue.h
index 8a6da1c..e97e16a 100644
--- a/native/jni/src/words_priority_queue.h
+++ b/native/jni/src/words_priority_queue.h
@@ -129,7 +129,7 @@
                 }
             }
             if (maxIndex > 0 && nsMaxSw) {
-                memmove(&swBuffer[1], &swBuffer[0], maxIndex * sizeof(SuggestedWord*));
+                memmove(&swBuffer[1], &swBuffer[0], maxIndex * sizeof(SuggestedWord *));
                 swBuffer[0] = nsMaxSw;
             }
         }
@@ -140,12 +140,13 @@
                 continue;
             }
             const unsigned int wordLength = sw->mWordLength;
-            char *targetAdr = (char*) outputChars + i * MAX_WORD_LENGTH * sizeof(short);
+            char *targetAddress = reinterpret_cast<char *>(outputChars)
+                    + i * MAX_WORD_LENGTH * sizeof(short);
             frequencies[i] = sw->mScore;
             outputTypes[i] = sw->mType;
-            memcpy(targetAdr, sw->mWord, (wordLength) * sizeof(short));
+            memcpy(targetAddress, sw->mWord, (wordLength) * sizeof(short));
             if (wordLength < MAX_WORD_LENGTH) {
-                ((unsigned short*) targetAdr)[wordLength] = 0;
+                reinterpret_cast<unsigned short *>(targetAddress)[wordLength] = 0;
             }
             sw->mUsed = false;
         }