diff options
Diffstat (limited to 'native/src/proximity_info.cpp')
-rw-r--r-- | native/src/proximity_info.cpp | 92 |
1 files changed, 47 insertions, 45 deletions
diff --git a/native/src/proximity_info.cpp b/native/src/proximity_info.cpp index 47f137610..c00c4c20f 100644 --- a/native/src/proximity_info.cpp +++ b/native/src/proximity_info.cpp @@ -129,7 +129,7 @@ bool ProximityInfo::hasSpaceProximity(const int x, const int y) const { return false; } -bool ProximityInfo::isOnKey(const int keyId, const int x, const int y) { +bool ProximityInfo::isOnKey(const int keyId, const int x, const int y) const { if (keyId < 0) return true; // NOT_A_ID is -1, but return whenever < 0 just in case const int left = mKeyXCoordinates[keyId]; const int top = mKeyYCoordinates[keyId]; @@ -138,7 +138,7 @@ bool ProximityInfo::isOnKey(const int keyId, const int x, const int y) { return left < right && top < bottom && x >= left && x < right && y >= top && y < bottom; } -int ProximityInfo::squaredDistanceToEdge(const int keyId, const int x, const int y) { +int ProximityInfo::squaredDistanceToEdge(const int keyId, const int x, const int y) const { if (keyId < 0) return true; // NOT_A_ID is -1, but return whenever < 0 just in case const int left = mKeyXCoordinates[keyId]; const int top = mKeyYCoordinates[keyId]; @@ -152,58 +152,60 @@ int ProximityInfo::squaredDistanceToEdge(const int keyId, const int x, const int } void ProximityInfo::calculateNearbyKeyCodes( - const int x, const int y, const int32_t primaryKey, int *inputCodes) { + const int x, const int y, const int32_t primaryKey, int *inputCodes) const { int insertPos = 0; inputCodes[insertPos++] = primaryKey; const int startIndex = getStartIndexFromCoordinates(x, y); - for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { - const int32_t c = mProximityCharsArray[startIndex + i]; - if (c < KEYCODE_SPACE || c == primaryKey) { - continue; + if (startIndex >= 0) { + for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { + const int32_t c = mProximityCharsArray[startIndex + i]; + if (c < KEYCODE_SPACE || c == primaryKey) { + continue; + } + const int keyIndex = getKeyIndex(c); + const bool onKey = isOnKey(keyIndex, x, y); + const int distance = squaredDistanceToEdge(keyIndex, x, y); + if (onKey || distance < MOST_COMMON_KEY_WIDTH_SQUARE) { + inputCodes[insertPos++] = c; + if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) { + if (DEBUG_DICT) { + assert(false); + } + return; + } + } } - const int keyIndex = getKeyIndex(c); - const bool onKey = isOnKey(keyIndex, x, y); - const int distance = squaredDistanceToEdge(keyIndex, x, y); - if (onKey || distance < MOST_COMMON_KEY_WIDTH_SQUARE) { - inputCodes[insertPos++] = c; + const int additionalProximitySize = + AdditionalProximityChars::getAdditionalCharsSize(&mLocaleStr, primaryKey); + if (additionalProximitySize > 0) { + inputCodes[insertPos++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE; if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) { if (DEBUG_DICT) { assert(false); } return; } - } - } - const int additionalProximitySize = - AdditionalProximityChars::getAdditionalCharsSize(&mLocaleStr, primaryKey); - if (additionalProximitySize > 0) { - inputCodes[insertPos++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE; - if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) { - if (DEBUG_DICT) { - assert(false); - } - return; - } - const int32_t* additionalProximityChars = - AdditionalProximityChars::getAdditionalChars(&mLocaleStr, primaryKey); - for (int j = 0; j < additionalProximitySize; ++j) { - const int32_t ac = additionalProximityChars[j]; - int k = 0; - for (; k < insertPos; ++k) { - if ((int)ac == inputCodes[k]) { - break; + const int32_t* additionalProximityChars = + AdditionalProximityChars::getAdditionalChars(&mLocaleStr, primaryKey); + for (int j = 0; j < additionalProximitySize; ++j) { + const int32_t ac = additionalProximityChars[j]; + int k = 0; + for (; k < insertPos; ++k) { + if ((int)ac == inputCodes[k]) { + break; + } } - } - if (k < insertPos) { - continue; - } - inputCodes[insertPos++] = ac; - if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) { - if (DEBUG_DICT) { - assert(false); + if (k < insertPos) { + continue; + } + inputCodes[insertPos++] = ac; + if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) { + if (DEBUG_DICT) { + assert(false); + } + return; } - return; } } } @@ -219,7 +221,7 @@ void ProximityInfo::setInputParams(const int32_t* inputCodes, const int inputLen MAX_WORD_LENGTH_INTERNAL * MAX_PROXIMITY_CHARS_SIZE * sizeof(mInputCodes[0])); for (int i = 0; i < inputLength; ++i) { - const int32_t primaryKey = inputCodes[i * MAX_PROXIMITY_CHARS_SIZE]; + const int32_t primaryKey = inputCodes[i]; const int x = xCoordinates[i]; const int y = yCoordinates[i]; int *proximities = &mInputCodes[i * MAX_PROXIMITY_CHARS_SIZE]; @@ -304,7 +306,7 @@ inline float square(const float x) { return x * x; } float ProximityInfo::calculateNormalizedSquaredDistance( const int keyIndex, const int inputIndex) const { - if (keyIndex == NOT_A_INDEX) { + if (keyIndex == NOT_AN_INDEX) { return NOT_A_DISTANCE_FLOAT; } if (!hasSweetSpotData(keyIndex)) { @@ -325,11 +327,11 @@ bool ProximityInfo::hasInputCoordinates() const { int ProximityInfo::getKeyIndex(const int c) const { if (KEY_COUNT == 0) { // We do not have the coordinate data - return NOT_A_INDEX; + return NOT_AN_INDEX; } const unsigned short baseLowerC = toBaseLowerCase(c); if (baseLowerC > MAX_CHAR_CODE) { - return NOT_A_INDEX; + return NOT_AN_INDEX; } return mCodeToKeyIndex[baseLowerC]; } |