aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/proximity_info_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni/src/proximity_info_state.cpp')
-rw-r--r--native/jni/src/proximity_info_state.cpp56
1 files changed, 41 insertions, 15 deletions
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index 39d53fb52..549ac3544 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -39,12 +39,8 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
const ProximityInfo *proximityInfo, const int *const inputCodes, const int inputSize,
const int *const xCoordinates, const int *const yCoordinates, const int *const times,
const int *const pointerIds, const bool isGeometric) {
- if (isGeometric) {
- mIsContinuationPossible = checkAndReturnIsContinuationPossible(
- inputSize, xCoordinates, yCoordinates, times);
- } else {
- mIsContinuationPossible = false;
- }
+ mIsContinuationPossible = checkAndReturnIsContinuationPossible(
+ inputSize, xCoordinates, yCoordinates, times, isGeometric);
mProximityInfo = proximityInfo;
mHasTouchPositionCorrectionData = proximityInfo->hasTouchPositionCorrectionData();
@@ -466,13 +462,27 @@ float ProximityInfoState::calculateBeelineSpeedRate(
}
bool ProximityInfoState::checkAndReturnIsContinuationPossible(const int inputSize,
- const int *const xCoordinates, const int *const yCoordinates, const int *const times) {
- for (int i = 0; i < mSampledInputSize; ++i) {
- const int index = mInputIndice[i];
- if (index > inputSize || xCoordinates[index] != mSampledInputXs[i] ||
- yCoordinates[index] != mSampledInputYs[i] || times[index] != mTimes[i]) {
+ const int *const xCoordinates, const int *const yCoordinates, const int *const times,
+ const bool isGeometric) const {
+ if (isGeometric) {
+ for (int i = 0; i < mSampledInputSize; ++i) {
+ const int index = mInputIndice[i];
+ if (index > inputSize || xCoordinates[index] != mSampledInputXs[i] ||
+ yCoordinates[index] != mSampledInputYs[i] || times[index] != mTimes[i]) {
+ return false;
+ }
+ }
+ } else {
+ if (inputSize < mSampledInputSize) {
+ // Assuming the cache is invalid if the previous input size is larger than the new one.
return false;
}
+ for (int i = 0; i < mSampledInputSize && i < MAX_WORD_LENGTH_INTERNAL; ++i) {
+ if (xCoordinates[i] != mSampledInputXs[i]
+ || yCoordinates[i] != mSampledInputYs[i]) {
+ return false;
+ }
+ }
}
return true;
}
@@ -658,11 +668,15 @@ int ProximityInfoState::getDuration(const int index) const {
return 0;
}
-float ProximityInfoState::getPointToKeyLength(const int inputIndex, const int codePoint) const {
+// TODO: Remove the "scale" parameter
+// This function basically converts from a length to an edit distance. Accordingly, it's obviously
+// wrong to compare with mMaxPointToKeyLength.
+float ProximityInfoState::getPointToKeyLength(
+ const int inputIndex, const int codePoint, const float scale) const {
const int keyId = mProximityInfo->getKeyIndexOf(codePoint);
if (keyId != NOT_AN_INDEX) {
const int index = inputIndex * mProximityInfo->getKeyCount() + keyId;
- return min(mDistanceCache[index], mMaxPointToKeyLength);
+ return min(mDistanceCache[index] * scale, mMaxPointToKeyLength);
}
if (isSkippableCodePoint(codePoint)) {
return 0.0f;
@@ -671,15 +685,27 @@ float ProximityInfoState::getPointToKeyLength(const int inputIndex, const int co
return MAX_POINT_TO_KEY_LENGTH;
}
-float ProximityInfoState::getPointToKeyByIdLength(const int inputIndex, const int keyId) const {
+float ProximityInfoState::getPointToKeyLength(const int inputIndex, const int codePoint) const {
+ return getPointToKeyLength(inputIndex, codePoint, 1.0f);
+}
+
+// TODO: Remove the "scale" parameter
+// This function basically converts from a length to an edit distance. Accordingly, it's obviously
+// wrong to compare with mMaxPointToKeyLength.
+float ProximityInfoState::getPointToKeyByIdLength(
+ const int inputIndex, const int keyId, const float scale) const {
if (keyId != NOT_AN_INDEX) {
const int index = inputIndex * mProximityInfo->getKeyCount() + keyId;
- return min(mDistanceCache[index], mMaxPointToKeyLength);
+ return min(mDistanceCache[index] * scale, mMaxPointToKeyLength);
}
// If the char is not a key on the keyboard then return the max length.
return static_cast<float>(MAX_POINT_TO_KEY_LENGTH);
}
+float ProximityInfoState::getPointToKeyByIdLength(const int inputIndex, const int keyId) const {
+ return getPointToKeyByIdLength(inputIndex, keyId, 1.0f);
+}
+
// In the following function, c is the current character of the dictionary word currently examined.
// currentChars is an array containing the keys close to the character the user actually typed at
// the same position. We want to see if c is in it: if so, then the word contains at that position