blob: e590740d248a7363d187a4841378ae376a062201 [file] [log] [blame]
satok8fbd5522011-02-22 17:28:55 +09001/*
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 Nojima0e1f6562011-09-21 12:02:47 +090017#include <assert.h>
satok8fbd5522011-02-22 17:28:55 +090018#include <stdio.h>
satok552c3c22012-03-13 16:33:47 +090019#include <string>
satok8fbd5522011-02-22 17:28:55 +090020
satok817e5172011-03-04 06:06:45 -080021#define LOG_TAG "LatinIME: proximity_info.cpp"
22
satok552c3c22012-03-13 16:33:47 +090023#include "additional_proximity_chars.h"
satokd24df432011-07-14 15:43:42 +090024#include "dictionary.h"
satok8fbd5522011-02-22 17:28:55 +090025#include "proximity_info.h"
26
27namespace latinime {
Ken Wakasace9e52a2011-06-18 13:09:55 +090028
Yusuke Nojimade2f8422011-09-27 11:15:18 +090029inline void copyOrFillZero(void *to, const void *from, size_t size) {
30 if (from) {
31 memcpy(to, from, size);
32 } else {
33 memset(to, 0, size);
34 }
35}
36
satok552c3c22012-03-13 16:33:47 +090037ProximityInfo::ProximityInfo(const std::string localeStr, const int maxProximityCharsSize,
38 const int keyboardWidth, const int keyboardHeight, const int gridWidth,
39 const int gridHeight, const int mostCommonKeyWidth,
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090040 const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates,
41 const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights,
Yusuke Nojimaad358352011-09-29 16:44:54 +090042 const int32_t *keyCharCodes, const float *sweetSpotCenterXs, const float *sweetSpotCenterYs,
43 const float *sweetSpotRadii)
satok817e5172011-03-04 06:06:45 -080044 : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth),
45 KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight),
satoka70ee6e2012-03-07 15:12:22 +090046 MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth),
satok817e5172011-03-04 06:06:45 -080047 CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090048 CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight),
Yusuke Nojima258bfe62011-09-28 12:59:43 +090049 KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)),
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +090050 HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates
51 && keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs
52 && sweetSpotCenterYs && sweetSpotRadii),
satok5eec5742012-03-13 18:26:23 +090053 mLocaleStr(localeStr),
Tadashi G. Takaoka0e971482011-10-28 17:02:09 +090054 mInputXCoordinates(0), mInputYCoordinates(0),
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +090055 mTouchPositionCorrectionEnabled(false) {
Jean Chalard8c8ca592011-11-10 12:07:30 +090056 const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
57 mProximityCharsArray = new uint32_t[proximityGridLength];
satok817e5172011-03-04 06:06:45 -080058 if (DEBUG_PROXIMITY_INFO) {
satok9fb6f472012-01-13 18:01:22 +090059 AKLOGI("Create proximity info array %d", proximityGridLength);
satok817e5172011-03-04 06:06:45 -080060 }
Jean Chalard8c8ca592011-11-10 12:07:30 +090061 memcpy(mProximityCharsArray, proximityCharsArray,
62 proximityGridLength * sizeof(mProximityCharsArray[0]));
63 const int normalizedSquaredDistancesLength =
64 MAX_PROXIMITY_CHARS_SIZE * MAX_WORD_LENGTH_INTERNAL;
65 mNormalizedSquaredDistances = new int[normalizedSquaredDistancesLength];
66 for (int i = 0; i < normalizedSquaredDistancesLength; ++i) {
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +090067 mNormalizedSquaredDistances[i] = NOT_A_DISTANCE;
68 }
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090069
Yusuke Nojimade2f8422011-09-27 11:15:18 +090070 copyOrFillZero(mKeyXCoordinates, keyXCoordinates, KEY_COUNT * sizeof(mKeyXCoordinates[0]));
71 copyOrFillZero(mKeyYCoordinates, keyYCoordinates, KEY_COUNT * sizeof(mKeyYCoordinates[0]));
72 copyOrFillZero(mKeyWidths, keyWidths, KEY_COUNT * sizeof(mKeyWidths[0]));
73 copyOrFillZero(mKeyHeights, keyHeights, KEY_COUNT * sizeof(mKeyHeights[0]));
74 copyOrFillZero(mKeyCharCodes, keyCharCodes, KEY_COUNT * sizeof(mKeyCharCodes[0]));
Yusuke Nojimaad358352011-09-29 16:44:54 +090075 copyOrFillZero(mSweetSpotCenterXs, sweetSpotCenterXs,
76 KEY_COUNT * sizeof(mSweetSpotCenterXs[0]));
77 copyOrFillZero(mSweetSpotCenterYs, sweetSpotCenterYs,
78 KEY_COUNT * sizeof(mSweetSpotCenterYs[0]));
79 copyOrFillZero(mSweetSpotRadii, sweetSpotRadii, KEY_COUNT * sizeof(mSweetSpotRadii[0]));
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090080
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090081 initializeCodeToKeyIndex();
82}
83
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090084// Build the reversed look up table from the char code to the index in mKeyXCoordinates,
85// mKeyYCoordinates, mKeyWidths, mKeyHeights, mKeyCharCodes.
86void ProximityInfo::initializeCodeToKeyIndex() {
Yusuke Nojimaad358352011-09-29 16:44:54 +090087 memset(mCodeToKeyIndex, -1, (MAX_CHAR_CODE + 1) * sizeof(mCodeToKeyIndex[0]));
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090088 for (int i = 0; i < KEY_COUNT; ++i) {
89 const int code = mKeyCharCodes[i];
Yusuke Nojimaad358352011-09-29 16:44:54 +090090 if (0 <= code && code <= MAX_CHAR_CODE) {
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090091 mCodeToKeyIndex[code] = i;
Yusuke Nojimaad358352011-09-29 16:44:54 +090092 }
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090093 }
satok8fbd5522011-02-22 17:28:55 +090094}
95
96ProximityInfo::~ProximityInfo() {
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +090097 delete[] mNormalizedSquaredDistances;
satok8fbd5522011-02-22 17:28:55 +090098 delete[] mProximityCharsArray;
99}
satok817e5172011-03-04 06:06:45 -0800100
101inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y) const {
satok3c4bb772011-03-04 22:50:19 -0800102 return ((y / CELL_HEIGHT) * GRID_WIDTH + (x / CELL_WIDTH))
satok817e5172011-03-04 06:06:45 -0800103 * MAX_PROXIMITY_CHARS_SIZE;
satok8fbd5522011-02-22 17:28:55 +0900104}
satok817e5172011-03-04 06:06:45 -0800105
106bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
satok744dab62011-12-15 22:29:05 +0900107 if (x < 0 || y < 0) {
108 if (DEBUG_DICT) {
satok9fb6f472012-01-13 18:01:22 +0900109 AKLOGI("HasSpaceProximity: Illegal coordinates (%d, %d)", x, y);
satok1a6da632011-12-16 23:15:06 +0900110 assert(false);
satok744dab62011-12-15 22:29:05 +0900111 }
112 return false;
113 }
114
satok817e5172011-03-04 06:06:45 -0800115 const int startIndex = getStartIndexFromCoordinates(x, y);
116 if (DEBUG_PROXIMITY_INFO) {
satok9fb6f472012-01-13 18:01:22 +0900117 AKLOGI("hasSpaceProximity: index %d, %d, %d", startIndex, x, y);
satok817e5172011-03-04 06:06:45 -0800118 }
119 for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
120 if (DEBUG_PROXIMITY_INFO) {
satok9fb6f472012-01-13 18:01:22 +0900121 AKLOGI("Index: %d", mProximityCharsArray[startIndex + i]);
satok817e5172011-03-04 06:06:45 -0800122 }
123 if (mProximityCharsArray[startIndex + i] == KEYCODE_SPACE) {
124 return true;
125 }
126 }
127 return false;
128}
Ken Wakasace9e52a2011-06-18 13:09:55 +0900129
satoka70ee6e2012-03-07 15:12:22 +0900130bool ProximityInfo::isOnKey(const int keyId, const int x, const int y) {
131 const int left = mKeyXCoordinates[keyId];
132 const int top = mKeyYCoordinates[keyId];
133 const int right = left + mKeyWidths[keyId] + 1;
134 const int bottom = top + mKeyHeights[keyId];
135 return left < right && top < bottom && x >= left && x < right && y >= top && y < bottom;
136}
137
138int ProximityInfo::squaredDistanceToEdge(const int keyId, const int x, const int y) {
139 const int left = mKeyXCoordinates[keyId];
140 const int top = mKeyYCoordinates[keyId];
141 const int right = left + mKeyWidths[keyId] + 1;
142 const int bottom = top + mKeyHeights[keyId];
143 const int edgeX = x < left ? left : (x > right ? right : x);
144 const int edgeY = y < top ? top : (y > bottom ? bottom : y);
145 const int dx = x - edgeX;
146 const int dy = y - edgeY;
147 return dx * dx + dy * dy;
148}
149
150void ProximityInfo::calculateNearbyKeyCodes(
151 const int x, const int y, const uint32_t primaryKey, int *inputCodes) {
152 int insertPos = 0;
153 inputCodes[insertPos++] = primaryKey;
154 const int startIndex = getStartIndexFromCoordinates(x, y);
155 for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
156 const uint32_t c = mProximityCharsArray[startIndex + i];
157 if (c < KEYCODE_SPACE || c == primaryKey) {
158 continue;
159 }
160 for (int j = 0; j < KEY_COUNT; ++j) {
161 const bool onKey = isOnKey(j, x, y);
162 const int distance = squaredDistanceToEdge(j, x, y);
163 if (onKey || distance < MOST_COMMON_KEY_WIDTH_SQUARE) {
164 inputCodes[insertPos++] = c;
165 }
166 }
167 }
satok5eec5742012-03-13 18:26:23 +0900168 const int existingProximitySize = insertPos;
169 for (int i = 0; i < existingProximitySize; ++i) {
170 const uint32_t c = inputCodes[i];
171 const int additionalProximitySize =
172 AdditionalProximityChars::hasAdditionalChars(&mLocaleStr, c);
173 if (additionalProximitySize <= 0) {
174 continue;
175 }
176 const uint32_t* additionalProximityChars =
177 AdditionalProximityChars::getAdditionalChars(&mLocaleStr, c);
178 for (int j = 0; j < additionalProximitySize; ++j) {
179 const uint32_t ac = additionalProximityChars[j];
180 int k = 0;
181 for (; k < insertPos; ++k) {
182 if ((int)ac == inputCodes[k]) {
183 break;
184 }
185 }
186 if (k < insertPos) {
187 continue;
188 }
189 inputCodes[insertPos++] = ac;
190 }
191 }
satoka70ee6e2012-03-07 15:12:22 +0900192 // TODO: calculate additional chars
193}
194
satok1d7eaf82011-07-13 10:32:02 +0900195// TODO: Calculate nearby codes here.
Yusuke Nojima258bfe62011-09-28 12:59:43 +0900196void ProximityInfo::setInputParams(const int* inputCodes, const int inputLength,
197 const int* xCoordinates, const int* yCoordinates) {
satok1d7eaf82011-07-13 10:32:02 +0900198 mInputCodes = inputCodes;
Yusuke Nojima258bfe62011-09-28 12:59:43 +0900199 mInputXCoordinates = xCoordinates;
200 mInputYCoordinates = yCoordinates;
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900201 mTouchPositionCorrectionEnabled =
202 HAS_TOUCH_POSITION_CORRECTION_DATA && xCoordinates && yCoordinates;
satok1d7eaf82011-07-13 10:32:02 +0900203 mInputLength = inputLength;
satok0cedd2b2011-08-12 01:05:27 +0900204 for (int i = 0; i < inputLength; ++i) {
205 mPrimaryInputWord[i] = getPrimaryCharAt(i);
206 }
207 mPrimaryInputWord[inputLength] = 0;
Yusuke Nojimac25c7cc2011-10-03 16:44:29 +0900208 for (int i = 0; i < mInputLength; ++i) {
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900209 const int *proximityChars = getProximityCharsAt(i);
210 for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE && proximityChars[j] > 0; ++j) {
211 const int currentChar = proximityChars[j];
212 const int keyIndex = getKeyIndex(currentChar);
213 const float squaredDistance = calculateNormalizedSquaredDistance(keyIndex, i);
214 if (squaredDistance >= 0.0f) {
215 mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] =
216 (int)(squaredDistance * NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR);
217 } else {
218 mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] = (j == 0)
219 ? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO
220 : PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO;
221 }
Yusuke Nojimae4ba8222011-10-05 14:55:07 +0900222 }
Yusuke Nojimac25c7cc2011-10-03 16:44:29 +0900223 }
satok1d7eaf82011-07-13 10:32:02 +0900224}
225
Yusuke Nojima16717152011-10-04 17:04:07 +0900226inline float square(const float x) { return x * x; }
227
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900228float ProximityInfo::calculateNormalizedSquaredDistance(
229 const int keyIndex, const int inputIndex) const {
Yusuke Nojimae4ba8222011-10-05 14:55:07 +0900230 static const float NOT_A_DISTANCE_FLOAT = -1.0f;
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900231 if (keyIndex == NOT_A_INDEX) {
Yusuke Nojimae4ba8222011-10-05 14:55:07 +0900232 return NOT_A_DISTANCE_FLOAT;
Yusuke Nojimac25c7cc2011-10-03 16:44:29 +0900233 }
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900234 if (!hasSweetSpotData(keyIndex)) {
Yusuke Nojimae4ba8222011-10-05 14:55:07 +0900235 return NOT_A_DISTANCE_FLOAT;
Yusuke Nojima16717152011-10-04 17:04:07 +0900236 }
Jean Chalard0bfe3592012-01-25 18:11:26 +0900237 if (NOT_A_COORDINATE == mInputXCoordinates[inputIndex]) {
238 return NOT_A_DISTANCE_FLOAT;
239 }
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900240 const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(keyIndex, inputIndex);
241 const float squaredRadius = square(mSweetSpotRadii[keyIndex]);
Yusuke Nojimae4ba8222011-10-05 14:55:07 +0900242 return squaredDistance / squaredRadius;
Yusuke Nojima16717152011-10-04 17:04:07 +0900243}
244
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900245int ProximityInfo::getKeyIndex(const int c) const {
246 if (KEY_COUNT == 0 || !mInputXCoordinates || !mInputYCoordinates) {
247 // We do not have the coordinate data
248 return NOT_A_INDEX;
249 }
Tadashi G. Takaoka6e3cb272011-11-11 14:26:13 +0900250 const unsigned short baseLowerC = toBaseLowerCase(c);
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900251 if (baseLowerC > MAX_CHAR_CODE) {
252 return NOT_A_INDEX;
253 }
254 return mCodeToKeyIndex[baseLowerC];
255}
256
Yusuke Nojimac25c7cc2011-10-03 16:44:29 +0900257float ProximityInfo::calculateSquaredDistanceFromSweetSpotCenter(
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900258 const int keyIndex, const int inputIndex) const {
Yusuke Nojimac25c7cc2011-10-03 16:44:29 +0900259 const float sweetSpotCenterX = mSweetSpotCenterXs[keyIndex];
260 const float sweetSpotCenterY = mSweetSpotCenterYs[keyIndex];
261 const float inputX = (float)mInputXCoordinates[inputIndex];
262 const float inputY = (float)mInputYCoordinates[inputIndex];
263 return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
264}
265
satokd24df432011-07-14 15:43:42 +0900266inline const int* ProximityInfo::getProximityCharsAt(const int index) const {
satok1d7eaf82011-07-13 10:32:02 +0900267 return mInputCodes + (index * MAX_PROXIMITY_CHARS_SIZE);
268}
269
satokd24df432011-07-14 15:43:42 +0900270unsigned short ProximityInfo::getPrimaryCharAt(const int index) const {
271 return getProximityCharsAt(index)[0];
272}
273
satok2df30602011-07-15 13:49:00 +0900274inline bool ProximityInfo::existsCharInProximityAt(const int index, const int c) const {
satokd24df432011-07-14 15:43:42 +0900275 const int *chars = getProximityCharsAt(index);
276 int i = 0;
277 while (chars[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE) {
278 if (chars[i++] == c) {
279 return true;
280 }
281 }
282 return false;
283}
284
285bool ProximityInfo::existsAdjacentProximityChars(const int index) const {
286 if (index < 0 || index >= mInputLength) return false;
287 const int currentChar = getPrimaryCharAt(index);
288 const int leftIndex = index - 1;
289 if (leftIndex >= 0 && existsCharInProximityAt(leftIndex, currentChar)) {
290 return true;
291 }
292 const int rightIndex = index + 1;
293 if (rightIndex < mInputLength && existsCharInProximityAt(rightIndex, currentChar)) {
294 return true;
295 }
296 return false;
297}
298
299// In the following function, c is the current character of the dictionary word
300// currently examined.
301// currentChars is an array containing the keys close to the character the
302// user actually typed at the same position. We want to see if c is in it: if so,
303// then the word contains at that position a character close to what the user
304// typed.
305// What the user typed is actually the first character of the array.
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900306// proximityIndex is a pointer to the variable where getMatchedProximityId returns
307// the index of c in the proximity chars of the input index.
satokd24df432011-07-14 15:43:42 +0900308// Notice : accented characters do not have a proximity list, so they are alone
309// in their list. The non-accented version of the character should be considered
310// "close", but not the other keys close to the non-accented version.
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900311ProximityInfo::ProximityType ProximityInfo::getMatchedProximityId(const int index,
312 const unsigned short c, const bool checkProximityChars, int *proximityIndex) const {
satokd24df432011-07-14 15:43:42 +0900313 const int *currentChars = getProximityCharsAt(index);
Yusuke Nojima258bfe62011-09-28 12:59:43 +0900314 const int firstChar = currentChars[0];
Tadashi G. Takaoka6e3cb272011-11-11 14:26:13 +0900315 const unsigned short baseLowerC = toBaseLowerCase(c);
satokd24df432011-07-14 15:43:42 +0900316
317 // The first char in the array is what user typed. If it matches right away,
318 // that means the user typed that same char for this pos.
Yusuke Nojima258bfe62011-09-28 12:59:43 +0900319 if (firstChar == baseLowerC || firstChar == c) {
Yusuke Nojimae4ba8222011-10-05 14:55:07 +0900320 return EQUIVALENT_CHAR;
Yusuke Nojima258bfe62011-09-28 12:59:43 +0900321 }
satokd24df432011-07-14 15:43:42 +0900322
satok985312e2011-08-05 21:21:01 +0900323 if (!checkProximityChars) return UNRELATED_CHAR;
satokd24df432011-07-14 15:43:42 +0900324
325 // If the non-accented, lowercased version of that first character matches c,
326 // then we have a non-accented version of the accented character the user
327 // typed. Treat it as a close char.
Tadashi G. Takaoka6e3cb272011-11-11 14:26:13 +0900328 if (toBaseLowerCase(firstChar) == baseLowerC)
satokd24df432011-07-14 15:43:42 +0900329 return NEAR_PROXIMITY_CHAR;
330
331 // Not an exact nor an accent-alike match: search the list of close keys
332 int j = 1;
satoke05b3f42012-01-31 17:15:43 +0900333 while (j < MAX_PROXIMITY_CHARS_SIZE
334 && currentChars[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
satokd24df432011-07-14 15:43:42 +0900335 const bool matched = (currentChars[j] == baseLowerC || currentChars[j] == c);
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900336 if (matched) {
337 if (proximityIndex) {
338 *proximityIndex = j;
339 }
340 return NEAR_PROXIMITY_CHAR;
341 }
satokd24df432011-07-14 15:43:42 +0900342 ++j;
343 }
satoke05b3f42012-01-31 17:15:43 +0900344 if (j < MAX_PROXIMITY_CHARS_SIZE
345 && currentChars[j] == ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
346 ++j;
347 while (j < MAX_PROXIMITY_CHARS_SIZE
348 && currentChars[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
349 const bool matched = (currentChars[j] == baseLowerC || currentChars[j] == c);
350 if (matched) {
351 if (proximityIndex) {
352 *proximityIndex = j;
353 }
354 return ADDITIONAL_PROXIMITY_CHAR;
355 }
356 ++j;
357 }
358 }
satokd24df432011-07-14 15:43:42 +0900359
360 // Was not included, signal this as an unrelated character.
361 return UNRELATED_CHAR;
362}
363
satok1d7eaf82011-07-13 10:32:02 +0900364bool ProximityInfo::sameAsTyped(const unsigned short *word, int length) const {
365 if (length != mInputLength) {
366 return false;
367 }
368 const int *inputCodes = mInputCodes;
369 while (length--) {
370 if ((unsigned int) *inputCodes != (unsigned int) *word) {
371 return false;
372 }
373 inputCodes += MAX_PROXIMITY_CHARS_SIZE;
374 word++;
375 }
376 return true;
377}
378
Yusuke Nojimae4ba8222011-10-05 14:55:07 +0900379const int ProximityInfo::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
380const int ProximityInfo::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR;
Yusuke Nojima0e1f6562011-09-21 12:02:47 +0900381const int ProximityInfo::MAX_KEY_COUNT_IN_A_KEYBOARD;
Yusuke Nojimaad358352011-09-29 16:44:54 +0900382const int ProximityInfo::MAX_CHAR_CODE;
Yusuke Nojima0e1f6562011-09-21 12:02:47 +0900383
Ken Wakasace9e52a2011-06-18 13:09:55 +0900384} // namespace latinime