diff options
Diffstat (limited to 'native/jni/src/proximity_info_state.cpp')
-rw-r--r-- | native/jni/src/proximity_info_state.cpp | 71 |
1 files changed, 59 insertions, 12 deletions
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp index e13d4e664..c9a1ed0c0 100644 --- a/native/jni/src/proximity_info_state.cpp +++ b/native/jni/src/proximity_info_state.cpp @@ -76,6 +76,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi mTimes.clear(); mLengthCache.clear(); mDistanceCache.clear(); + mNearKeysVector.clear(); mInputSize = 0; if (xCoordinates && yCoordinates) { @@ -122,14 +123,34 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi if (mInputSize > 0) { const int keyCount = mProximityInfo->getKeyCount(); + mNearKeysVector.resize(mInputSize); mDistanceCache.resize(mInputSize * keyCount); for (int i = 0; i < mInputSize; ++i) { + mNearKeysVector[i].reset(); + static const float NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD = 4.0f; for (int k = 0; k < keyCount; ++k) { const int index = i * keyCount + k; const int x = mInputXs[i]; const int y = mInputYs[i]; - mDistanceCache[index] = + const float normalizedSquaredDistance = mProximityInfo->getNormalizedSquaredDistanceFromCenterFloat(k, x, y); + mDistanceCache[index] = normalizedSquaredDistance; + if (normalizedSquaredDistance < NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD) { + mNearKeysVector[i].set(k, 1); + } + } + } + + static const float READ_FORWORD_LENGTH_SCALE = 0.95f; + const int readForwordLength = static_cast<int>( + hypotf(mProximityInfo->getKeyboardWidth(), mProximityInfo->getKeyboardHeight()) + * READ_FORWORD_LENGTH_SCALE); + for (int i = 0; i < mInputSize; ++i) { + for (int j = i + 1; j < mInputSize; ++j) { + if (mLengthCache[j] - mLengthCache[i] >= readForwordLength) { + break; + } + mNearKeysVector[i] |= mNearKeysVector[j]; } } } @@ -160,7 +181,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi const int currentChar = proximityChars[j]; const float squaredDistance = hasInputCoordinates() ? calculateNormalizedSquaredDistance( - mProximityInfo->getKeyIndex(currentChar), i) : + mProximityInfo->getKeyIndexOf(currentChar), i) : NOT_A_DISTANCE_FLOAT; if (squaredDistance >= 0.0f) { mNormalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE_INTERNAL + j] = @@ -182,7 +203,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi // the given point and the nearest key position. float ProximityInfoState::updateNearKeysDistances(const int x, const int y, NearKeysDistanceMap *const currentNearKeysDistances) { - static const float NEAR_KEY_THRESHOLD = 10.0f; + static const float NEAR_KEY_THRESHOLD = 4.0f; currentNearKeysDistances->clear(); const int keyCount = mProximityInfo->getKeyCount(); @@ -282,7 +303,7 @@ bool ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y, const const NearKeysDistanceMap *const prevPrevNearKeysDistances) { static const float LAST_POINT_SKIP_DISTANCE_SCALE = 0.25f; - uint32_t size = mInputXs.size(); + size_t size = mInputXs.size(); bool popped = false; if (nodeChar < 0 && sample) { const float nearest = updateNearKeysDistances(x, y, currentNearKeysDistances); @@ -309,7 +330,7 @@ bool ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y, const float minDist = mMaxPointToKeyLength; for (NearKeysDistanceMap::const_iterator it = currentNearKeysDistances->begin(); it != currentNearKeysDistances->end(); ++it) { - if(minDist > it->second){ + if (minDist > it->second) { minChar = it->first; minDist = it->second; } @@ -324,10 +345,10 @@ bool ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y, const } if (nodeChar >= 0 && (x < 0 || y < 0)) { - const int keyId = mProximityInfo->getKeyIndex(nodeChar); + const int keyId = mProximityInfo->getKeyIndexOf(nodeChar); if (keyId >= 0) { - x = mProximityInfo->getKeyCenterXOfIdG(keyId); - y = mProximityInfo->getKeyCenterYOfIdG(keyId); + x = mProximityInfo->getKeyCenterXOfKeyIdG(keyId); + y = mProximityInfo->getKeyCenterYOfKeyIdG(keyId); } } @@ -368,8 +389,8 @@ int ProximityInfoState::getDuration(const int index) const { return 0; } -float ProximityInfoState::getPointToKeyLength(int inputIndex, int charCode, float scale) { - const int keyId = mProximityInfo->getKeyIndex(charCode); +float ProximityInfoState::getPointToKeyLength(int inputIndex, int codePoint, float scale) { + const int keyId = mProximityInfo->getKeyIndexOf(codePoint); if (keyId >= 0) { const int index = inputIndex * mProximityInfo->getKeyCount() + keyId; return min(mDistanceCache[index] * scale, mMaxPointToKeyLength); @@ -382,8 +403,8 @@ int ProximityInfoState::getKeyKeyDistance(int key0, int key1) { } int ProximityInfoState::getSpaceY() { - const int keyId = mProximityInfo->getKeyIndex(' '); - return mProximityInfo->getKeyCenterYOfIdG(keyId); + const int keyId = mProximityInfo->getKeyIndexOf(' '); + return mProximityInfo->getKeyCenterYOfKeyIdG(keyId); } float ProximityInfoState::calculateSquaredDistanceFromSweetSpotCenter( @@ -394,4 +415,30 @@ float ProximityInfoState::calculateSquaredDistanceFromSweetSpotCenter( const float inputY = static_cast<float>(mInputYs[inputIndex]); return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY); } + +// Puts possible characters into filter and returns new filter size. +int32_t ProximityInfoState::getAllPossibleChars( + const size_t index, int32_t *const filter, const int32_t filterSize) const { + if (index >= mInputXs.size()) { + return filterSize; + } + int i = filterSize; + for (int j = 0; j < mProximityInfo->getKeyCount(); ++j) { + if (mNearKeysVector[index].test(j)) { + const int32_t keyCodePoint = mProximityInfo->getCodePointOf(j); + bool insert = true; + // TODO: Avoid linear search + for (int k = 0; k < filterSize; ++k) { + if (filter[k] == keyCodePoint) { + insert = false; + break; + } + } + if (insert) { + filter[i++] = keyCodePoint; + } + } + } + return i; +} } // namespace latinime |