From e7398cdb2b48eb52dc9676c8efa75bc7cb9af3e9 Mon Sep 17 00:00:00 2001 From: Satoshi Kataoka Date: Mon, 13 Aug 2012 20:20:04 +0900 Subject: [PATCH] Step 26-A Cleanup geometory_utils Change-Id: I839c498c85009a5d6428a71f121a2906fd667db8 --- native/jni/src/geometry_utils.h | 5 ----- native/jni/src/proximity_info.cpp | 37 +++++++++++++------------------ native/jni/src/proximity_info.h | 2 ++ 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/native/jni/src/geometry_utils.h b/native/jni/src/geometry_utils.h index deb042525..146eb8055 100644 --- a/native/jni/src/geometry_utils.h +++ b/native/jni/src/geometry_utils.h @@ -32,11 +32,6 @@ static inline float squareFloat(float x) { return x * x; } -static inline float getNormalizedSquaredDistanceFloat(float x1, float y1, float x2, float y2, - float scale) { - return squareFloat((x1 - x2) / scale) + squareFloat((y1 - y2) / scale); -} - static inline float getSquaredDistanceFloat(float x1, float y1, float x2, float y2) { return squareFloat(x1 - x2) + squareFloat(y1 - y2); } diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp index ade78a1ec..1b9bac0f0 100644 --- a/native/jni/src/proximity_info.cpp +++ b/native/jni/src/proximity_info.cpp @@ -135,6 +135,21 @@ bool ProximityInfo::hasSpaceProximity(const int x, const int y) const { return false; } +static inline float getNormalizedSquaredDistanceFloat(float x1, float y1, float x2, float y2, + float scale) { + return squareFloat((x1 - x2) / scale) + squareFloat((y1 - y2) / scale); +} + +float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloat( + const int keyId, const int x, const int y) const { + const float centerX = static_cast(getKeyCenterXOfIdG(keyId)); + const float centerY = static_cast(getKeyCenterYOfIdG(keyId)); + const float touchX = static_cast(x); + const float touchY = static_cast(y); + const float keyWidth = static_cast(getMostCommonKeyWidth()); + return getNormalizedSquaredDistanceFloat(centerX, centerY, touchX, touchY, keyWidth); +} + 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]; @@ -233,6 +248,7 @@ int ProximityInfo::getKeyCode(const int keyIndex) const { } void ProximityInfo::initializeG() { + // TODO: Optimize for (int i = 0; i < KEY_COUNT; ++i) { const int code = mKeyCharCodes[i]; const int lowerCode = toBaseLowerCase(code); @@ -285,25 +301,4 @@ int ProximityInfo::getKeyKeyDistanceG(int key0, int key1) const { } return 0; } - -// TODO: [Staging] Optimize -void ProximityInfo::getCenters(int *centerXs, int *centerYs, int *codeToKeyIndex, - int *keyToCodeIndex, int *keyCount, int *keyWidth) const { - *keyCount = KEY_COUNT; - *keyWidth = sqrtf(static_cast(MOST_COMMON_KEY_WIDTH_SQUARE)); - - for (int i = 0; i < KEY_COUNT; ++i) { - const int code = mKeyCharCodes[i]; - const int lowerCode = toBaseLowerCase(code); - centerXs[i] = mKeyXCoordinates[i] + mKeyWidths[i] / 2; - centerYs[i] = mKeyYCoordinates[i] + mKeyHeights[i] / 2; - codeToKeyIndex[code] = i; - if (code != lowerCode && lowerCode >= 0 && lowerCode <= MAX_CHAR_CODE) { - codeToKeyIndex[lowerCode] = i; - keyToCodeIndex[i] = lowerCode; - } else { - keyToCodeIndex[i] = code; - } - } -} } // namespace latinime diff --git a/native/jni/src/proximity_info.h b/native/jni/src/proximity_info.h index 58f2d7502..8a407e71a 100644 --- a/native/jni/src/proximity_info.h +++ b/native/jni/src/proximity_info.h @@ -38,6 +38,8 @@ class ProximityInfo { ~ProximityInfo(); bool hasSpaceProximity(const int x, const int y) const; int getNormalizedSquaredDistance(const int inputIndex, const int proximityIndex) const; + float getNormalizedSquaredDistanceFromCenterFloat( + const int keyId, const int x, const int y) const; bool sameAsTyped(const unsigned short *word, int length) const; int squaredDistanceToEdge(const int keyId, const int x, const int y) const; bool isOnKey(const int keyId, const int x, const int y) const {