Merge "Remove unused local variable"
diff --git a/native/src/proximity_info.cpp b/native/src/proximity_info.cpp
index 547d5e8..4c21c2e 100644
--- a/native/src/proximity_info.cpp
+++ b/native/src/proximity_info.cpp
@@ -114,6 +114,51 @@
         mPrimaryInputWord[i] = getPrimaryCharAt(i);
     }
     mPrimaryInputWord[inputLength] = 0;
+    for (int i = 0; i < mInputLength; ++i) {
+        mSweetSpotTypes[i] = calculateSweetSpotType(i);
+    }
+}
+
+inline float square(const float x) { return x * x; }
+
+ProximityInfo::SweetSpotType ProximityInfo::calculateSweetSpotType(int index) const {
+    if (KEY_COUNT == 0 || !mInputXCoordinates || !mInputYCoordinates) {
+        // We do not have the coordinate data
+        return UNKNOWN;
+    }
+    const int currentChar = getPrimaryCharAt(index);
+    const unsigned short baseLowerC = Dictionary::toBaseLowerCase(currentChar);
+    if (baseLowerC > MAX_CHAR_CODE) {
+        return UNKNOWN;
+    }
+    const int keyIndex = mCodeToKeyIndex[baseLowerC];
+    if (keyIndex < 0) {
+        return UNKNOWN;
+    }
+    const float radius = mSweetSpotRadii[keyIndex];
+    if (radius <= 0.0) {
+        // When there are no calibration data for a key,
+        // the radius of the key is assigned to zero.
+        return UNKNOWN;
+    }
+    const float squaredRadius = square(radius);
+    const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(keyIndex, index);
+    if (squaredDistance <= squaredRadius) {
+        return IN_SWEET_SPOT;
+    }
+    if (squaredDistance <= square(NEUTRAL_AREA_RADIUS_RATIO) * squaredRadius) {
+        return IN_NEUTRAL_AREA;
+    }
+    return OUT_OF_NEUTRAL_AREA;
+}
+
+float ProximityInfo::calculateSquaredDistanceFromSweetSpotCenter(
+        int keyIndex, int inputIndex) const {
+    const float sweetSpotCenterX = mSweetSpotCenterXs[keyIndex];
+    const float sweetSpotCenterY = mSweetSpotCenterYs[keyIndex];
+    const float inputX = (float)mInputXCoordinates[inputIndex];
+    const float inputY = (float)mInputYCoordinates[inputIndex];
+    return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
 }
 
 inline const int* ProximityInfo::getProximityCharsAt(const int index) const {
@@ -169,8 +214,7 @@
     // that means the user typed that same char for this pos.
     if (firstChar == baseLowerC || firstChar == c) {
         if (CALIBRATE_SCORE_BY_TOUCH_COORDINATES) {
-            const SweetSpotType result = calculateSweetSpotType(index, baseLowerC);
-            switch (result) {
+            switch (mSweetSpotTypes[index]) {
             case UNKNOWN:
                 return EQUIVALENT_CHAR_NORMAL;
             case IN_SWEET_SPOT:
@@ -207,38 +251,6 @@
     return UNRELATED_CHAR;
 }
 
-inline float square(const float x) { return x * x; }
-
-ProximityInfo::SweetSpotType ProximityInfo::calculateSweetSpotType(
-        int index, unsigned short baseLowerC) const {
-    if (KEY_COUNT == 0 || !mInputXCoordinates || !mInputYCoordinates
-            || baseLowerC > MAX_CHAR_CODE) {
-        return UNKNOWN;
-    }
-    const int keyIndex = mCodeToKeyIndex[baseLowerC];
-    if (keyIndex < 0) {
-        return UNKNOWN;
-    }
-    const float sweetSpotRadius = mSweetSpotRadii[keyIndex];
-    if (sweetSpotRadius <= 0.0) {
-        return UNKNOWN;
-    }
-    const float sweetSpotCenterX = mSweetSpotCenterXs[keyIndex];
-    const float sweetSpotCenterY = mSweetSpotCenterYs[keyIndex];
-    const float inputX = (float)mInputXCoordinates[index];
-    const float inputY = (float)mInputYCoordinates[index];
-    const float squaredDistance =
-            square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
-    const float squaredSweetSpotRadius = square(sweetSpotRadius);
-    if (squaredDistance <= squaredSweetSpotRadius) {
-        return IN_SWEET_SPOT;
-    }
-    if (squaredDistance <= square(NEUTRAL_AREA_RADIUS_RATIO) * squaredSweetSpotRadius) {
-        return IN_NEUTRAL_AREA;
-    }
-    return OUT_OF_NEUTRAL_AREA;
-}
-
 bool ProximityInfo::sameAsTyped(const unsigned short *word, int length) const {
     if (length != mInputLength) {
         return false;
diff --git a/native/src/proximity_info.h b/native/src/proximity_info.h
index a705d0c..421ca0e 100644
--- a/native/src/proximity_info.h
+++ b/native/src/proximity_info.h
@@ -81,7 +81,9 @@
 
     int getStartIndexFromCoordinates(const int x, const int y) const;
     void initializeCodeToKeyIndex();
-    SweetSpotType calculateSweetSpotType(int index, unsigned short baseLowerC) const;
+    SweetSpotType calculateSweetSpotType(int index) const;
+    float calculateSquaredDistanceFromSweetSpotCenter(int keyIndex, int inputIndex) const;
+
     const int MAX_PROXIMITY_CHARS_SIZE;
     const int KEYBOARD_WIDTH;
     const int KEYBOARD_HEIGHT;
@@ -102,6 +104,7 @@
     float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
     float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
     float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
+    SweetSpotType mSweetSpotTypes[MAX_WORD_LENGTH_INTERNAL];
     int mInputLength;
     unsigned short mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL];
     int mCodeToKeyIndex[MAX_CHAR_CODE + 1];