satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 17 | #include <assert.h> |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | #include <string.h> |
| 20 | |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 21 | #define LOG_TAG "LatinIME: proximity_info.cpp" |
| 22 | |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 23 | #include "dictionary.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 24 | #include "proximity_info.h" |
| 25 | |
| 26 | namespace latinime { |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 27 | |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 28 | inline void copyOrFillZero(void *to, const void *from, size_t size) { |
| 29 | if (from) { |
| 30 | memcpy(to, from, size); |
| 31 | } else { |
| 32 | memset(to, 0, size); |
| 33 | } |
| 34 | } |
| 35 | |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 36 | ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboardWidth, |
| 37 | const int keyboardHeight, const int gridWidth, const int gridHeight, |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 38 | const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates, |
| 39 | const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights, |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 40 | const int32_t *keyCharCodes, const float *sweetSpotCenterXs, const float *sweetSpotCenterYs, |
| 41 | const float *sweetSpotRadii) |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 42 | : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth), |
| 43 | KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight), |
| 44 | CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth), |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 45 | CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight), |
Yusuke Nojima | 258bfe6 | 2011-09-28 12:59:43 +0900 | [diff] [blame] | 46 | KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)), |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 47 | HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates |
| 48 | && keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs |
| 49 | && sweetSpotCenterYs && sweetSpotRadii), |
| 50 | mInputXCoordinates(NULL), mInputYCoordinates(NULL), |
| 51 | mTouchPositionCorrectionEnabled(false) { |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 52 | const int len = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE; |
| 53 | mProximityCharsArray = new uint32_t[len]; |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 54 | mNormalizedSquaredDistances = new int[len]; |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 55 | if (DEBUG_PROXIMITY_INFO) { |
| 56 | LOGI("Create proximity info array %d", len); |
| 57 | } |
| 58 | memcpy(mProximityCharsArray, proximityCharsArray, len * sizeof(mProximityCharsArray[0])); |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 59 | for (int i = 0; i < len; ++i) { |
| 60 | mNormalizedSquaredDistances[i] = NOT_A_DISTANCE; |
| 61 | } |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 62 | |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 63 | copyOrFillZero(mKeyXCoordinates, keyXCoordinates, KEY_COUNT * sizeof(mKeyXCoordinates[0])); |
| 64 | copyOrFillZero(mKeyYCoordinates, keyYCoordinates, KEY_COUNT * sizeof(mKeyYCoordinates[0])); |
| 65 | copyOrFillZero(mKeyWidths, keyWidths, KEY_COUNT * sizeof(mKeyWidths[0])); |
| 66 | copyOrFillZero(mKeyHeights, keyHeights, KEY_COUNT * sizeof(mKeyHeights[0])); |
| 67 | copyOrFillZero(mKeyCharCodes, keyCharCodes, KEY_COUNT * sizeof(mKeyCharCodes[0])); |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 68 | copyOrFillZero(mSweetSpotCenterXs, sweetSpotCenterXs, |
| 69 | KEY_COUNT * sizeof(mSweetSpotCenterXs[0])); |
| 70 | copyOrFillZero(mSweetSpotCenterYs, sweetSpotCenterYs, |
| 71 | KEY_COUNT * sizeof(mSweetSpotCenterYs[0])); |
| 72 | copyOrFillZero(mSweetSpotRadii, sweetSpotRadii, KEY_COUNT * sizeof(mSweetSpotRadii[0])); |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 73 | |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 74 | initializeCodeToKeyIndex(); |
| 75 | } |
| 76 | |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 77 | // Build the reversed look up table from the char code to the index in mKeyXCoordinates, |
| 78 | // mKeyYCoordinates, mKeyWidths, mKeyHeights, mKeyCharCodes. |
| 79 | void ProximityInfo::initializeCodeToKeyIndex() { |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 80 | memset(mCodeToKeyIndex, -1, (MAX_CHAR_CODE + 1) * sizeof(mCodeToKeyIndex[0])); |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 81 | for (int i = 0; i < KEY_COUNT; ++i) { |
| 82 | const int code = mKeyCharCodes[i]; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 83 | if (0 <= code && code <= MAX_CHAR_CODE) { |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 84 | mCodeToKeyIndex[code] = i; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 85 | } |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 86 | } |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | ProximityInfo::~ProximityInfo() { |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 90 | delete[] mNormalizedSquaredDistances; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 91 | delete[] mProximityCharsArray; |
| 92 | } |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 93 | |
| 94 | inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y) const { |
satok | 3c4bb77 | 2011-03-04 22:50:19 -0800 | [diff] [blame] | 95 | return ((y / CELL_HEIGHT) * GRID_WIDTH + (x / CELL_WIDTH)) |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 96 | * MAX_PROXIMITY_CHARS_SIZE; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 97 | } |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 98 | |
| 99 | bool ProximityInfo::hasSpaceProximity(const int x, const int y) const { |
| 100 | const int startIndex = getStartIndexFromCoordinates(x, y); |
| 101 | if (DEBUG_PROXIMITY_INFO) { |
| 102 | LOGI("hasSpaceProximity: index %d", startIndex); |
| 103 | } |
| 104 | for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { |
| 105 | if (DEBUG_PROXIMITY_INFO) { |
| 106 | LOGI("Index: %d", mProximityCharsArray[startIndex + i]); |
| 107 | } |
| 108 | if (mProximityCharsArray[startIndex + i] == KEYCODE_SPACE) { |
| 109 | return true; |
| 110 | } |
| 111 | } |
| 112 | return false; |
| 113 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 114 | |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 115 | // TODO: Calculate nearby codes here. |
Yusuke Nojima | 258bfe6 | 2011-09-28 12:59:43 +0900 | [diff] [blame] | 116 | void ProximityInfo::setInputParams(const int* inputCodes, const int inputLength, |
| 117 | const int* xCoordinates, const int* yCoordinates) { |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 118 | mInputCodes = inputCodes; |
Yusuke Nojima | 258bfe6 | 2011-09-28 12:59:43 +0900 | [diff] [blame] | 119 | mInputXCoordinates = xCoordinates; |
| 120 | mInputYCoordinates = yCoordinates; |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 121 | mTouchPositionCorrectionEnabled = |
| 122 | HAS_TOUCH_POSITION_CORRECTION_DATA && xCoordinates && yCoordinates; |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 123 | mInputLength = inputLength; |
satok | 0cedd2b | 2011-08-12 01:05:27 +0900 | [diff] [blame] | 124 | for (int i = 0; i < inputLength; ++i) { |
| 125 | mPrimaryInputWord[i] = getPrimaryCharAt(i); |
| 126 | } |
| 127 | mPrimaryInputWord[inputLength] = 0; |
Yusuke Nojima | c25c7cc | 2011-10-03 16:44:29 +0900 | [diff] [blame] | 128 | for (int i = 0; i < mInputLength; ++i) { |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 129 | const int *proximityChars = getProximityCharsAt(i); |
| 130 | for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE && proximityChars[j] > 0; ++j) { |
| 131 | const int currentChar = proximityChars[j]; |
| 132 | const int keyIndex = getKeyIndex(currentChar); |
| 133 | const float squaredDistance = calculateNormalizedSquaredDistance(keyIndex, i); |
| 134 | if (squaredDistance >= 0.0f) { |
| 135 | mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] = |
| 136 | (int)(squaredDistance * NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR); |
| 137 | } else { |
| 138 | mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] = (j == 0) |
| 139 | ? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO |
| 140 | : PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO; |
| 141 | } |
Yusuke Nojima | e4ba822 | 2011-10-05 14:55:07 +0900 | [diff] [blame] | 142 | } |
Yusuke Nojima | c25c7cc | 2011-10-03 16:44:29 +0900 | [diff] [blame] | 143 | } |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 144 | } |
| 145 | |
Yusuke Nojima | 1671715 | 2011-10-04 17:04:07 +0900 | [diff] [blame] | 146 | inline float square(const float x) { return x * x; } |
| 147 | |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 148 | float ProximityInfo::calculateNormalizedSquaredDistance( |
| 149 | const int keyIndex, const int inputIndex) const { |
Yusuke Nojima | e4ba822 | 2011-10-05 14:55:07 +0900 | [diff] [blame] | 150 | static const float NOT_A_DISTANCE_FLOAT = -1.0f; |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 151 | if (keyIndex == NOT_A_INDEX) { |
Yusuke Nojima | e4ba822 | 2011-10-05 14:55:07 +0900 | [diff] [blame] | 152 | return NOT_A_DISTANCE_FLOAT; |
Yusuke Nojima | c25c7cc | 2011-10-03 16:44:29 +0900 | [diff] [blame] | 153 | } |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 154 | if (!hasSweetSpotData(keyIndex)) { |
Yusuke Nojima | e4ba822 | 2011-10-05 14:55:07 +0900 | [diff] [blame] | 155 | return NOT_A_DISTANCE_FLOAT; |
Yusuke Nojima | 1671715 | 2011-10-04 17:04:07 +0900 | [diff] [blame] | 156 | } |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 157 | const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(keyIndex, inputIndex); |
| 158 | const float squaredRadius = square(mSweetSpotRadii[keyIndex]); |
Yusuke Nojima | e4ba822 | 2011-10-05 14:55:07 +0900 | [diff] [blame] | 159 | return squaredDistance / squaredRadius; |
Yusuke Nojima | 1671715 | 2011-10-04 17:04:07 +0900 | [diff] [blame] | 160 | } |
| 161 | |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 162 | int ProximityInfo::getKeyIndex(const int c) const { |
| 163 | if (KEY_COUNT == 0 || !mInputXCoordinates || !mInputYCoordinates) { |
| 164 | // We do not have the coordinate data |
| 165 | return NOT_A_INDEX; |
| 166 | } |
| 167 | const unsigned short baseLowerC = Dictionary::toBaseLowerCase(c); |
| 168 | if (baseLowerC > MAX_CHAR_CODE) { |
| 169 | return NOT_A_INDEX; |
| 170 | } |
| 171 | return mCodeToKeyIndex[baseLowerC]; |
| 172 | } |
| 173 | |
Yusuke Nojima | c25c7cc | 2011-10-03 16:44:29 +0900 | [diff] [blame] | 174 | float ProximityInfo::calculateSquaredDistanceFromSweetSpotCenter( |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 175 | const int keyIndex, const int inputIndex) const { |
Yusuke Nojima | c25c7cc | 2011-10-03 16:44:29 +0900 | [diff] [blame] | 176 | const float sweetSpotCenterX = mSweetSpotCenterXs[keyIndex]; |
| 177 | const float sweetSpotCenterY = mSweetSpotCenterYs[keyIndex]; |
| 178 | const float inputX = (float)mInputXCoordinates[inputIndex]; |
| 179 | const float inputY = (float)mInputYCoordinates[inputIndex]; |
| 180 | return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY); |
| 181 | } |
| 182 | |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 183 | inline const int* ProximityInfo::getProximityCharsAt(const int index) const { |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 184 | return mInputCodes + (index * MAX_PROXIMITY_CHARS_SIZE); |
| 185 | } |
| 186 | |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 187 | unsigned short ProximityInfo::getPrimaryCharAt(const int index) const { |
| 188 | return getProximityCharsAt(index)[0]; |
| 189 | } |
| 190 | |
satok | 2df3060 | 2011-07-15 13:49:00 +0900 | [diff] [blame] | 191 | inline bool ProximityInfo::existsCharInProximityAt(const int index, const int c) const { |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 192 | const int *chars = getProximityCharsAt(index); |
| 193 | int i = 0; |
| 194 | while (chars[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE) { |
| 195 | if (chars[i++] == c) { |
| 196 | return true; |
| 197 | } |
| 198 | } |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | bool ProximityInfo::existsAdjacentProximityChars(const int index) const { |
| 203 | if (index < 0 || index >= mInputLength) return false; |
| 204 | const int currentChar = getPrimaryCharAt(index); |
| 205 | const int leftIndex = index - 1; |
| 206 | if (leftIndex >= 0 && existsCharInProximityAt(leftIndex, currentChar)) { |
| 207 | return true; |
| 208 | } |
| 209 | const int rightIndex = index + 1; |
| 210 | if (rightIndex < mInputLength && existsCharInProximityAt(rightIndex, currentChar)) { |
| 211 | return true; |
| 212 | } |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | // In the following function, c is the current character of the dictionary word |
| 217 | // currently examined. |
| 218 | // currentChars is an array containing the keys close to the character the |
| 219 | // user actually typed at the same position. We want to see if c is in it: if so, |
| 220 | // then the word contains at that position a character close to what the user |
| 221 | // typed. |
| 222 | // What the user typed is actually the first character of the array. |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 223 | // proximityIndex is a pointer to the variable where getMatchedProximityId returns |
| 224 | // the index of c in the proximity chars of the input index. |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 225 | // Notice : accented characters do not have a proximity list, so they are alone |
| 226 | // in their list. The non-accented version of the character should be considered |
| 227 | // "close", but not the other keys close to the non-accented version. |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 228 | ProximityInfo::ProximityType ProximityInfo::getMatchedProximityId(const int index, |
| 229 | const unsigned short c, const bool checkProximityChars, int *proximityIndex) const { |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 230 | const int *currentChars = getProximityCharsAt(index); |
Yusuke Nojima | 258bfe6 | 2011-09-28 12:59:43 +0900 | [diff] [blame] | 231 | const int firstChar = currentChars[0]; |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 232 | const unsigned short baseLowerC = Dictionary::toBaseLowerCase(c); |
| 233 | |
| 234 | // The first char in the array is what user typed. If it matches right away, |
| 235 | // that means the user typed that same char for this pos. |
Yusuke Nojima | 258bfe6 | 2011-09-28 12:59:43 +0900 | [diff] [blame] | 236 | if (firstChar == baseLowerC || firstChar == c) { |
Yusuke Nojima | e4ba822 | 2011-10-05 14:55:07 +0900 | [diff] [blame] | 237 | return EQUIVALENT_CHAR; |
Yusuke Nojima | 258bfe6 | 2011-09-28 12:59:43 +0900 | [diff] [blame] | 238 | } |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 239 | |
satok | 985312e | 2011-08-05 21:21:01 +0900 | [diff] [blame] | 240 | if (!checkProximityChars) return UNRELATED_CHAR; |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 241 | |
| 242 | // If the non-accented, lowercased version of that first character matches c, |
| 243 | // then we have a non-accented version of the accented character the user |
| 244 | // typed. Treat it as a close char. |
Yusuke Nojima | 258bfe6 | 2011-09-28 12:59:43 +0900 | [diff] [blame] | 245 | if (Dictionary::toBaseLowerCase(firstChar) == baseLowerC) |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 246 | return NEAR_PROXIMITY_CHAR; |
| 247 | |
| 248 | // Not an exact nor an accent-alike match: search the list of close keys |
| 249 | int j = 1; |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 250 | while (j < MAX_PROXIMITY_CHARS_SIZE && currentChars[j] > 0) { |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 251 | const bool matched = (currentChars[j] == baseLowerC || currentChars[j] == c); |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame^] | 252 | if (matched) { |
| 253 | if (proximityIndex) { |
| 254 | *proximityIndex = j; |
| 255 | } |
| 256 | return NEAR_PROXIMITY_CHAR; |
| 257 | } |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 258 | ++j; |
| 259 | } |
| 260 | |
| 261 | // Was not included, signal this as an unrelated character. |
| 262 | return UNRELATED_CHAR; |
| 263 | } |
| 264 | |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 265 | bool ProximityInfo::sameAsTyped(const unsigned short *word, int length) const { |
| 266 | if (length != mInputLength) { |
| 267 | return false; |
| 268 | } |
| 269 | const int *inputCodes = mInputCodes; |
| 270 | while (length--) { |
| 271 | if ((unsigned int) *inputCodes != (unsigned int) *word) { |
| 272 | return false; |
| 273 | } |
| 274 | inputCodes += MAX_PROXIMITY_CHARS_SIZE; |
| 275 | word++; |
| 276 | } |
| 277 | return true; |
| 278 | } |
| 279 | |
Yusuke Nojima | e4ba822 | 2011-10-05 14:55:07 +0900 | [diff] [blame] | 280 | const int ProximityInfo::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2; |
| 281 | const int ProximityInfo::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 282 | const int ProximityInfo::MAX_KEY_COUNT_IN_A_KEYBOARD; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 283 | const int ProximityInfo::MAX_CHAR_CODE; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 284 | |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 285 | } // namespace latinime |