Remove MAX_PROXIMITY_CHARS_SIZE_INTERNAL
Change-Id: I18a997503de4033b5341b564145bca862a872098
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 1f432b4..922a746 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 @@
#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 @@
#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 @@
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 c563b07..8157fe2 100644
--- a/native/jni/src/proximity_info.cpp
+++ b/native/jni/src/proximity_info.cpp
@@ -47,15 +47,14 @@
}
}
-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 @@
&& 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 @@
}
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 cd0bc32..6d571d7 100644
--- a/native/jni/src/proximity_info.h
+++ b/native/jni/src/proximity_info.h
@@ -28,7 +28,7 @@
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 @@
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 5f3b266..058a031 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -208,7 +208,7 @@
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 @@
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 @@
// 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 @@
}
++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 d31447e..9d3976f 100644
--- a/native/jni/src/proximity_info_state.h
+++ b/native/jni/src/proximity_info_state.h
@@ -73,7 +73,7 @@
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 @@
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 @@
if (*inputProximities != *word) {
return false;
}
- inputProximities += MAX_PROXIMITY_CHARS_SIZE_INTERNAL;
+ inputProximities += MAX_PROXIMITY_CHARS_SIZE;
word++;
}
return true;
@@ -214,11 +214,6 @@
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 @@
// 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 146ce05..65a2583 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 @@
}
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 @@
/* 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 @@
/* 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 @@
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 90a98ef..3408aef 100644
--- a/native/jni/src/proximity_info_state_utils.h
+++ b/native/jni/src/proximity_info_state_utils.h
@@ -36,8 +36,7 @@
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 @@
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 @@
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 0930207..24917d8 100644
--- a/native/jni/src/proximity_info_utils.h
+++ b/native/jni/src/proximity_info_utils.h
@@ -61,7 +61,7 @@
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 @@
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);
}