diff options
author | 2013-01-21 20:28:10 -0800 | |
---|---|---|
committer | 2013-01-21 20:28:10 -0800 | |
commit | 8a3e8dca21ef251fb4a493c9323e9464cb2b1edb (patch) | |
tree | e55c2bf0b602beb8059f7d0306db51959ca9b5b4 /native/jni/src | |
parent | 5d8e9d915931ce0ab659b96b7e75b9b1d9ddbe73 (diff) | |
parent | 6c22439bf80da08576e86c1282afc5cfa431e235 (diff) | |
download | latinime-8a3e8dca21ef251fb4a493c9323e9464cb2b1edb.tar.gz latinime-8a3e8dca21ef251fb4a493c9323e9464cb2b1edb.tar.xz latinime-8a3e8dca21ef251fb4a493c9323e9464cb2b1edb.zip |
am 6c22439b: Remove MAX_PROXIMITY_CHARS_SIZE_INTERNAL
* commit '6c22439bf80da08576e86c1282afc5cfa431e235':
Remove MAX_PROXIMITY_CHARS_SIZE_INTERNAL
Diffstat (limited to 'native/jni/src')
-rw-r--r-- | native/jni/src/defines.h | 16 | ||||
-rw-r--r-- | native/jni/src/proximity_info.cpp | 20 | ||||
-rw-r--r-- | native/jni/src/proximity_info.h | 3 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state.cpp | 12 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state.h | 15 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state_utils.cpp | 22 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state_utils.h | 16 | ||||
-rw-r--r-- | native/jni/src/proximity_info_utils.h | 6 |
8 files changed, 52 insertions, 58 deletions
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h index 1f432b431..922a746b8 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -28,10 +28,13 @@ #define AK_FORCE_INLINE inline #endif // defined(FLAG_DO_PROFILE) || defined(FLAG_DBG) -// Must be identical to Constants.Dictionary.MAX_WORD_LENGTH in Java +// Must be equal to Constants.Dictionary.MAX_WORD_LENGTH in Java #define MAX_WORD_LENGTH 48 -// Must be identical to BinaryDictionary.MAX_RESULTS in Java +// Must be equal to BinaryDictionary.MAX_RESULTS in Java #define MAX_RESULTS 18 +// Must be equal to ProximityInfo.MAX_PROXIMITY_CHARS_SIZE in Java +#define MAX_PROXIMITY_CHARS_SIZE 16 +#define ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE 2 #if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG) #include <android/log.h> @@ -249,6 +252,7 @@ static inline void prof_out(void) { #define S_INT_MIN (-2147483647 - 1) // -(1 << 31) #endif +#define M_PI_F 3.14159265f #define MAX_PERCENTILE 100 // Number of base-10 digits in the largest integer + 1 to leave room for a zero terminator. @@ -325,12 +329,6 @@ static inline void prof_out(void) { #define MAX_FREQ 255 #define MAX_BIGRAM_FREQ 15 -// This must be the same as ProximityInfo#MAX_PROXIMITY_CHARS_SIZE, currently it's 16. -#define MAX_PROXIMITY_CHARS_SIZE_INTERNAL 16 - -// This must be equal to ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE in KeyDetector.java -#define ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE 2 - // Assuming locale strings such as en_US, sr-Latn etc. #define MAX_LOCALE_STRING_LENGTH 10 @@ -395,8 +393,6 @@ static inline void prof_out(void) { template<typename T> inline T min(T a, T b) { return a < b ? a : b; } template<typename T> inline T max(T a, T b) { return a > b ? a : b; } -#define M_PI_F 3.14159265f - #define NELEMS(x) (sizeof(x) / sizeof((x)[0])) // The ratio of neutral area radius to sweet spot radius. diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp index c563b0796..8157fe2d0 100644 --- a/native/jni/src/proximity_info.cpp +++ b/native/jni/src/proximity_info.cpp @@ -47,15 +47,14 @@ static AK_FORCE_INLINE void safeGetOrFillZeroFloatArrayRegion(JNIEnv *env, jfloa } } -ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int maxProximityCharsSize, +ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int keyboardWidth, const int keyboardHeight, const int gridWidth, const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars, const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates, const jintArray keyWidths, const jintArray keyHeights, const jintArray keyCharCodes, const jfloatArray sweetSpotCenterXs, const jfloatArray sweetSpotCenterYs, const jfloatArray sweetSpotRadii) - : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), GRID_WIDTH(gridWidth), - GRID_HEIGHT(gridHeight), MOST_COMMON_KEY_WIDTH(mostCommonKeyWidth), + : GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight), MOST_COMMON_KEY_WIDTH(mostCommonKeyWidth), MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth), CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth), CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight), @@ -65,11 +64,17 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma && keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs && sweetSpotCenterYs && sweetSpotRadii), mProximityCharsArray(new int[GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE - /* proximityGridLength */]), + /* proximityCharsLength */]), mCodeToKeyMap() { - const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE; + /* Let's check the input array length here to make sure */ + const jsize proximityCharsLength = env->GetArrayLength(proximityChars); + if (proximityCharsLength != GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE) { + AKLOGE("Invalid proximityCharsLength: %d", proximityCharsLength); + ASSERT(false); + return; + } if (DEBUG_PROXIMITY_INFO) { - AKLOGI("Create proximity info array %d", proximityGridLength); + AKLOGI("Create proximity info array %d", proximityCharsLength); } const jsize localeCStrUtf8Length = env->GetStringUTFLength(localeJStr); if (localeCStrUtf8Length >= MAX_LOCALE_STRING_LENGTH) { @@ -78,7 +83,8 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma } memset(mLocaleStr, 0, sizeof(mLocaleStr)); env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), mLocaleStr); - safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray); + safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityCharsLength, + mProximityCharsArray); safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates); safeGetOrFillZeroIntArrayRegion(env, keyYCoordinates, KEY_COUNT, mKeyYCoordinates); safeGetOrFillZeroIntArrayRegion(env, keyWidths, KEY_COUNT, mKeyWidths); diff --git a/native/jni/src/proximity_info.h b/native/jni/src/proximity_info.h index cd0bc32cc..6d571d7bb 100644 --- a/native/jni/src/proximity_info.h +++ b/native/jni/src/proximity_info.h @@ -28,7 +28,7 @@ class Correction; class ProximityInfo { public: - ProximityInfo(JNIEnv *env, const jstring localeJStr, const int maxProximityCharsSize, + ProximityInfo(JNIEnv *env, const jstring localeJStr, const int keyboardWidth, const int keyboardHeight, const int gridWidth, const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars, const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates, @@ -126,7 +126,6 @@ class ProximityInfo { float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const; bool hasInputCoordinates() const; - const int MAX_PROXIMITY_CHARS_SIZE; const int GRID_WIDTH; const int GRID_HEIGHT; const int MOST_COMMON_KEY_WIDTH; diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp index 5f3b26662..058a03187 100644 --- a/native/jni/src/proximity_info_state.cpp +++ b/native/jni/src/proximity_info_state.cpp @@ -208,7 +208,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi a += 0; AKLOGI("--- Primary = %c, x = %d, y = %d", primaryKey, x, y); } - for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL && proximityCodePoints[j] > 0; + for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE && proximityCodePoints[j] > 0; ++j) { const int currentCodePoint = proximityCodePoints[j]; const float squaredDistance = @@ -216,10 +216,10 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi mProximityInfo->getKeyIndexOf(currentCodePoint), i) : NOT_A_DISTANCE_FLOAT; if (squaredDistance >= 0.0f) { - mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + j] = + mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] = (int) (squaredDistance * NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR); } else { - mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + j] = + mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] = (j == 0) ? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO : PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO; } @@ -355,7 +355,7 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i // Not an exact nor an accent-alike match: search the list of close keys int j = 1; - while (j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL + while (j < MAX_PROXIMITY_CHARS_SIZE && currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) { const bool matched = (currentCodePoints[j] == baseLowerC || currentCodePoints[j] == c); if (matched) { @@ -366,10 +366,10 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i } ++j; } - if (j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL + if (j < MAX_PROXIMITY_CHARS_SIZE && currentCodePoints[j] == ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) { ++j; - while (j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL + while (j < MAX_PROXIMITY_CHARS_SIZE && currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) { const bool matched = (currentCodePoints[j] == baseLowerC || currentCodePoints[j] == c); if (matched) { diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h index d31447ead..9d3976f3a 100644 --- a/native/jni/src/proximity_info_state.h +++ b/native/jni/src/proximity_info_state.h @@ -73,7 +73,7 @@ class ProximityInfoState { AK_FORCE_INLINE bool existsCodePointInProximityAt(const int index, const int c) const { const int *codePoints = getProximityCodePointsAt(index); int i = 0; - while (codePoints[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE_INTERNAL) { + while (codePoints[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE) { if (codePoints[i++] == c) { return true; } @@ -99,7 +99,7 @@ class ProximityInfoState { inline int getNormalizedSquaredDistance( const int inputIndex, const int proximityIndex) const { return mNormalizedSquaredDistances[ - inputIndex * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + proximityIndex]; + inputIndex * MAX_PROXIMITY_CHARS_SIZE + proximityIndex]; } inline const int *getPrimaryInputWord() const { @@ -119,7 +119,7 @@ class ProximityInfoState { if (*inputProximities != *word) { return false; } - inputProximities += MAX_PROXIMITY_CHARS_SIZE_INTERNAL; + inputProximities += MAX_PROXIMITY_CHARS_SIZE; word++; } return true; @@ -214,11 +214,6 @@ class ProximityInfoState { float calculateSquaredDistanceFromSweetSpotCenter( const int keyIndex, const int inputIndex) const; - bool pushTouchPoint(const int inputIndex, const int nodeCodePoint, int x, int y, const int time, - const bool sample, const bool isLastPoint, const float sumAngle, - NearKeysDistanceMap *const currentNearKeysDistances, - const NearKeysDistanceMap *const prevNearKeysDistances, - const NearKeysDistanceMap *const prevPrevNearKeysDistances); ///////////////////////////////////////// // Defined here // ///////////////////////////////////////// @@ -284,8 +279,8 @@ class ProximityInfoState { // inputs including the current input point. std::vector<NearKeycodesSet> mSearchKeysVector; bool mTouchPositionCorrectionEnabled; - int mInputProximities[MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH]; - int mNormalizedSquaredDistances[MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH]; + int mInputProximities[MAX_PROXIMITY_CHARS_SIZE * MAX_WORD_LENGTH]; + int mNormalizedSquaredDistances[MAX_PROXIMITY_CHARS_SIZE * MAX_WORD_LENGTH]; int mSampledInputSize; int mPrimaryInputWord[MAX_WORD_LENGTH]; }; diff --git a/native/jni/src/proximity_info_state_utils.cpp b/native/jni/src/proximity_info_state_utils.cpp index 146ce0545..65a258309 100644 --- a/native/jni/src/proximity_info_state_utils.cpp +++ b/native/jni/src/proximity_info_state_utils.cpp @@ -16,6 +16,7 @@ #include <vector> +#include "defines.h" #include "geometry_utils.h" #include "proximity_info.h" #include "proximity_info_params.h" @@ -24,13 +25,12 @@ namespace latinime { /* static */ int ProximityInfoStateUtils::updateTouchPoints(const int mostCommonKeyWidth, const ProximityInfo *const proximityInfo, const int maxPointToKeyLength, - const int *const inputProximities, - const int *const inputXCoordinates, const int *const inputYCoordinates, - const int *const times, const int *const pointerIds, const int inputSize, - const bool isGeometric, const int pointerId, const int pushTouchPointStartIndex, - std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs, - std::vector<int> *sampledInputTimes, std::vector<int> *sampledLengthCache, - std::vector<int> *sampledInputIndice) { + const int *const inputProximities, const int *const inputXCoordinates, + const int *const inputYCoordinates, const int *const times, const int *const pointerIds, + const int inputSize, const bool isGeometric, const int pointerId, + const int pushTouchPointStartIndex, std::vector<int> *sampledInputXs, + std::vector<int> *sampledInputYs, std::vector<int> *sampledInputTimes, + std::vector<int> *sampledLengthCache, std::vector<int> *sampledInputIndice) { if (DEBUG_SAMPLING_POINTS) { if (times) { for (int i = 0; i < inputSize; ++i) { @@ -94,7 +94,7 @@ namespace latinime { } if (pushTouchPoint(mostCommonKeyWidth, proximityInfo, maxPointToKeyLength, - i, c, x, y, time, isGeometric /* do sampling */, + i, c, x, y, time, isGeometric /* doSampling */, i == lastInputIndex, sumAngle, currentNearKeysDistances, prevNearKeysDistances, prevPrevNearKeysDistances, sampledInputXs, sampledInputYs, sampledInputTimes, sampledLengthCache, @@ -117,7 +117,7 @@ namespace latinime { /* static */ const int *ProximityInfoStateUtils::getProximityCodePointsAt( const int *const inputProximities, const int index) { - return inputProximities + (index * MAX_PROXIMITY_CHARS_SIZE_INTERNAL); + return inputProximities + (index * MAX_PROXIMITY_CHARS_SIZE); } /* static */ int ProximityInfoStateUtils::getPrimaryCodePointAt( @@ -325,7 +325,7 @@ namespace latinime { /* static */ bool ProximityInfoStateUtils::pushTouchPoint(const int mostCommonKeyWidth, const ProximityInfo *const proximityInfo, const int maxPointToKeyLength, const int inputIndex, const int nodeCodePoint, int x, int y, - const int time, const bool sample, const bool isLastPoint, const float sumAngle, + const int time, const bool doSampling, const bool isLastPoint, const float sumAngle, NearKeysDistanceMap *const currentNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances, @@ -336,7 +336,7 @@ namespace latinime { size_t size = sampledInputXs->size(); bool popped = false; - if (nodeCodePoint < 0 && sample) { + if (nodeCodePoint < 0 && doSampling) { const float nearest = updateNearKeysDistances( proximityInfo, maxPointToKeyLength, x, y, currentNearKeysDistances); const float score = getPointScore(mostCommonKeyWidth, x, y, time, isLastPoint, nearest, diff --git a/native/jni/src/proximity_info_state_utils.h b/native/jni/src/proximity_info_state_utils.h index 90a98ef8d..3408aef89 100644 --- a/native/jni/src/proximity_info_state_utils.h +++ b/native/jni/src/proximity_info_state_utils.h @@ -36,8 +36,7 @@ class ProximityInfoStateUtils { std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs, std::vector<int> *sampledInputTimes, std::vector<int> *sampledLengthCache, std::vector<int> *sampledInputIndice); - static const int *getProximityCodePointsAt( - const int *const inputProximities, const int index); + static const int *getProximityCodePointsAt(const int *const inputProximities, const int index); static int getPrimaryCodePointAt(const int *const inputProximities, const int index); static void popInputData(std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs, std::vector<int> *sampledInputTimes, std::vector<int> *sampledLengthCache, @@ -57,8 +56,7 @@ class ProximityInfoStateUtils { const std::vector<int> *const sampledInputYs, const std::vector<int> *const inputIndice, std::vector<int> *beelineSpeedPercentiles); static float getDirection(const std::vector<int> *const sampledInputXs, - const std::vector<int> *const sampledInputYs, - const int index0, const int index1); + const std::vector<int> *const sampledInputYs, const int index0, const int index1); private: DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoStateUtils); @@ -71,16 +69,16 @@ class ProximityInfoStateUtils { static bool isPrevLocalMin(const NearKeysDistanceMap *const currentNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances); - static float getPointScore(const int mostCommonKeyWidth, - const int x, const int y, const int time, const bool lastPoint, const float nearest, - const float sumAngle, const NearKeysDistanceMap *const currentNearKeysDistances, + static float getPointScore(const int mostCommonKeyWidth, const int x, const int y, + const int time, const bool lastPoint, const float nearest, const float sumAngle, + const NearKeysDistanceMap *const currentNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances, std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs); static bool pushTouchPoint(const int mostCommonKeyWidth, const ProximityInfo *const proximityInfo, const int maxPointToKeyLength, - const int inputIndex, const int nodeCodePoint, int x, int y, - const int time, const bool sample, const bool isLastPoint, const float sumAngle, + const int inputIndex, const int nodeCodePoint, int x, int y, const int time, + const bool doSampling, const bool isLastPoint, const float sumAngle, NearKeysDistanceMap *const currentNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances, diff --git a/native/jni/src/proximity_info_utils.h b/native/jni/src/proximity_info_utils.h index 09302075a..24917d879 100644 --- a/native/jni/src/proximity_info_utils.h +++ b/native/jni/src/proximity_info_utils.h @@ -61,7 +61,7 @@ class ProximityInfoUtils { const int primaryKey = inputCodes[i]; const int x = inputXCoordinates[i]; const int y = inputYCoordinates[i]; - int *proximities = &inputProximities[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL]; + int *proximities = &inputProximities[i * MAX_PROXIMITY_CHARS_SIZE]; calculateProximities(keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, proximityCharsArray, maxProximityCharsSize, cellHeight, cellWidth, gridWidth, mostCommonKeyWidth, keyCount, x, y, primaryKey, localeStr, codeToKeyMap, @@ -71,9 +71,9 @@ class ProximityInfoUtils { if (DEBUG_PROXIMITY_CHARS) { for (int i = 0; i < inputSize; ++i) { AKLOGI("---"); - for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE_INTERNAL; ++j) { + for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE; ++j) { int proximityChar = - inputProximities[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + j]; + inputProximities[i * MAX_PROXIMITY_CHARS_SIZE + j]; proximityChar += 0; AKLOGI("--- (%d)%c", i, proximityChar); } |