diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp index 8c6a525a7..f78b84e88 100644 --- a/native/jni/src/proximity_info_state.cpp +++ b/native/jni/src/proximity_info_state.cpp @@ -33,8 +33,10 @@ 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) { - mIsContinuationPossible = checkAndReturnIsContinuationPossible( - inputSize, xCoordinates, yCoordinates, times, isGeometric); + ASSERT(isGeometric || (inputSize < MAX_WORD_LENGTH)); + mIsContinuationPossible = ProximityInfoStateUtils::checkAndReturnIsContinuationPossible( + inputSize, xCoordinates, yCoordinates, times, mSampledInputSize, &mSampledInputXs, + &mSampledInputYs, &mSampledTimes, &mSampledInputIndice); mProximityInfo = proximityInfo; mHasTouchPositionCorrectionData = proximityInfo->hasTouchPositionCorrectionData(); @@ -149,39 +151,6 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi } } -bool ProximityInfoState::checkAndReturnIsContinuationPossible(const int inputSize, - 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 = mSampledInputIndice[i]; - if (index > inputSize || xCoordinates[index] != mSampledInputXs[i] || - yCoordinates[index] != mSampledInputYs[i] || times[index] != mSampledTimes[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; ++i) { - if (xCoordinates[i] != mSampledInputXs[i] - || yCoordinates[i] != mSampledInputYs[i]) { - return false; - } - } - } - return true; -} - -int ProximityInfoState::getDuration(const int index) const { - if (index >= 0 && index < mSampledInputSize - 1) { - return mSampledTimes[index + 1] - mSampledTimes[index]; - } - return 0; -} - // 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. diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h index 642925c1a..9c4f557e2 100644 --- a/native/jni/src/proximity_info_state.h +++ b/native/jni/src/proximity_info_state.h @@ -122,8 +122,6 @@ class ProximityInfoState { return true; } - int getDuration(const int index) const; - bool isUsed() const { return mSampledInputSize > 0; } @@ -217,8 +215,6 @@ class ProximityInfoState { inline const int *getProximityCodePointsAt(const int index) const { return ProximityInfoStateUtils::getProximityCodePointsAt(mInputProximities, index); } - bool checkAndReturnIsContinuationPossible(const int inputSize, const int *const xCoordinates, - const int *const yCoordinates, const int *const times, const bool isGeometric) const; void popInputData(); // const diff --git a/native/jni/src/proximity_info_state_utils.cpp b/native/jni/src/proximity_info_state_utils.cpp index 1289b889b..123b9485b 100644 --- a/native/jni/src/proximity_info_state_utils.cpp +++ b/native/jni/src/proximity_info_state_utils.cpp @@ -983,6 +983,34 @@ namespace latinime { return true; } +/* static */ bool ProximityInfoStateUtils::checkAndReturnIsContinuationPossible(const int inputSize, + const int *const xCoordinates, const int *const yCoordinates, const int *const times, + const int sampledInputSize, const std::vector *const sampledInputXs, + const std::vector *const sampledInputYs, + const std::vector *const sampledTimes, + const std::vector *const sampledInputIndices) { + if (inputSize < sampledInputSize) { + return false; + } + for (int i = 0; i < sampledInputSize; ++i) { + const int index = (*sampledInputIndices)[i]; + if (index >= inputSize) { + return false; + } + if (xCoordinates[index] != (*sampledInputXs)[i] + || yCoordinates[index] != (*sampledInputYs)[i]) { + return false; + } + if (!times) { + continue; + } + if (times[index] != (*sampledTimes)[i]) { + return false; + } + } + return true; +} + /* static */ void ProximityInfoStateUtils::dump(const bool isGeometric, const int inputSize, const int *const inputXCoordinates, const int *const inputYCoordinates, const int sampledInputSize, const std::vector *const sampledInputXs, diff --git a/native/jni/src/proximity_info_state_utils.h b/native/jni/src/proximity_info_state_utils.h index 17ef1c3d7..931549016 100644 --- a/native/jni/src/proximity_info_state_utils.h +++ b/native/jni/src/proximity_info_state_utils.h @@ -107,6 +107,12 @@ class ProximityInfoStateUtils { const std::vector *const sampledTimes, const std::vector *const sampledSpeedRates, const std::vector *const sampledBeelineSpeedPercentiles); + static bool checkAndReturnIsContinuationPossible(const int inputSize, + const int *const xCoordinates, const int *const yCoordinates, const int *const times, + const int sampledInputSize, const std::vector *const sampledInputXs, + const std::vector *const sampledInputYs, + const std::vector *const sampledTimes, + const std::vector *const sampledInputIndices); private: DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoStateUtils);