am 096f35ff
: Fix the condition of continuation for gesture input and make ProximityInfoState incremental.
* commit '096f35ff4b5413906e2a339663baf16e5dabaf64': Fix the condition of continuation for gesture input and make ProximityInfoState incremental.
This commit is contained in:
commit
33164f3287
2 changed files with 70 additions and 22 deletions
|
@ -29,6 +29,14 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
|
||||||
const ProximityInfo *proximityInfo, const int32_t *const inputCodes, const int inputSize,
|
const ProximityInfo *proximityInfo, const int32_t *const inputCodes, const int inputSize,
|
||||||
const int *const xCoordinates, const int *const yCoordinates, const int *const times,
|
const int *const xCoordinates, const int *const yCoordinates, const int *const times,
|
||||||
const int *const pointerIds, const bool isGeometric) {
|
const int *const pointerIds, const bool isGeometric) {
|
||||||
|
|
||||||
|
if (isGeometric) {
|
||||||
|
mIsContinuationPossible = checkAndReturnIsContinuationPossible(
|
||||||
|
inputSize, xCoordinates, yCoordinates, times);
|
||||||
|
} else {
|
||||||
|
mIsContinuationPossible = false;
|
||||||
|
}
|
||||||
|
|
||||||
mProximityInfo = proximityInfo;
|
mProximityInfo = proximityInfo;
|
||||||
mHasTouchPositionCorrectionData = proximityInfo->hasTouchPositionCorrectionData();
|
mHasTouchPositionCorrectionData = proximityInfo->hasTouchPositionCorrectionData();
|
||||||
mMostCommonKeyWidthSquare = proximityInfo->getMostCommonKeyWidthSquare();
|
mMostCommonKeyWidthSquare = proximityInfo->getMostCommonKeyWidthSquare();
|
||||||
|
@ -70,19 +78,32 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
// Setup touch points
|
// Setup touch points
|
||||||
|
int pushTouchPointStartIndex = 0;
|
||||||
|
int lastSavedInputSize = 0;
|
||||||
mMaxPointToKeyLength = maxPointToKeyLength;
|
mMaxPointToKeyLength = maxPointToKeyLength;
|
||||||
mInputXs.clear();
|
if (mIsContinuationPossible && mInputIndice.size() > 1) {
|
||||||
mInputYs.clear();
|
// Just update difference.
|
||||||
mTimes.clear();
|
// Two points prior is never skipped. Thus, we pop 2 input point data here.
|
||||||
mLengthCache.clear();
|
pushTouchPointStartIndex = mInputIndice[mInputIndice.size() - 2];
|
||||||
mDistanceCache.clear();
|
popInputData();
|
||||||
mNearKeysVector.clear();
|
popInputData();
|
||||||
|
lastSavedInputSize = mInputXs.size();
|
||||||
|
} else {
|
||||||
|
// Clear all data.
|
||||||
|
mInputXs.clear();
|
||||||
|
mInputYs.clear();
|
||||||
|
mTimes.clear();
|
||||||
|
mInputIndice.clear();
|
||||||
|
mLengthCache.clear();
|
||||||
|
mDistanceCache.clear();
|
||||||
|
mNearKeysVector.clear();
|
||||||
|
}
|
||||||
mInputSize = 0;
|
mInputSize = 0;
|
||||||
|
|
||||||
if (xCoordinates && yCoordinates) {
|
if (xCoordinates && yCoordinates) {
|
||||||
const bool proximityOnly = !isGeometric && (xCoordinates[0] < 0 || yCoordinates[0] < 0);
|
const bool proximityOnly = !isGeometric && (xCoordinates[0] < 0 || yCoordinates[0] < 0);
|
||||||
int lastInputIndex = 0;
|
int lastInputIndex = pushTouchPointStartIndex;
|
||||||
for (int i = 0; i < inputSize; ++i) {
|
for (int i = lastInputIndex; i < inputSize; ++i) {
|
||||||
const int pid = pointerIds ? pointerIds[i] : 0;
|
const int pid = pointerIds ? pointerIds[i] : 0;
|
||||||
if (pointerId == pid) {
|
if (pointerId == pid) {
|
||||||
lastInputIndex = i;
|
lastInputIndex = i;
|
||||||
|
@ -95,7 +116,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
|
||||||
NearKeysDistanceMap *prevNearKeysDistances = &nearKeysDistances[1];
|
NearKeysDistanceMap *prevNearKeysDistances = &nearKeysDistances[1];
|
||||||
NearKeysDistanceMap *prevPrevNearKeysDistances = &nearKeysDistances[2];
|
NearKeysDistanceMap *prevPrevNearKeysDistances = &nearKeysDistances[2];
|
||||||
|
|
||||||
for (int i = 0; i < inputSize; ++i) {
|
for (int i = pushTouchPointStartIndex; i <= lastInputIndex; ++i) {
|
||||||
// Assuming pointerId == 0 if pointerIds is null.
|
// Assuming pointerId == 0 if pointerIds is null.
|
||||||
const int pid = pointerIds ? pointerIds[i] : 0;
|
const int pid = pointerIds ? pointerIds[i] : 0;
|
||||||
if (pointerId == pid) {
|
if (pointerId == pid) {
|
||||||
|
@ -103,7 +124,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
|
||||||
const int x = proximityOnly ? NOT_A_COORDINATE : xCoordinates[i];
|
const int x = proximityOnly ? NOT_A_COORDINATE : xCoordinates[i];
|
||||||
const int y = proximityOnly ? NOT_A_COORDINATE : yCoordinates[i];
|
const int y = proximityOnly ? NOT_A_COORDINATE : yCoordinates[i];
|
||||||
const int time = times ? times[i] : -1;
|
const int time = times ? times[i] : -1;
|
||||||
if (pushTouchPoint(c, x, y, time, isGeometric, i == lastInputIndex,
|
if (pushTouchPoint(i, c, x, y, time, isGeometric, i == lastInputIndex,
|
||||||
currentNearKeysDistances, prevNearKeysDistances,
|
currentNearKeysDistances, prevNearKeysDistances,
|
||||||
prevPrevNearKeysDistances)) {
|
prevPrevNearKeysDistances)) {
|
||||||
// Previous point information was popped.
|
// Previous point information was popped.
|
||||||
|
@ -125,7 +146,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
|
||||||
const int keyCount = mProximityInfo->getKeyCount();
|
const int keyCount = mProximityInfo->getKeyCount();
|
||||||
mNearKeysVector.resize(mInputSize);
|
mNearKeysVector.resize(mInputSize);
|
||||||
mDistanceCache.resize(mInputSize * keyCount);
|
mDistanceCache.resize(mInputSize * keyCount);
|
||||||
for (int i = 0; i < mInputSize; ++i) {
|
for (int i = lastSavedInputSize; i < mInputSize; ++i) {
|
||||||
mNearKeysVector[i].reset();
|
mNearKeysVector[i].reset();
|
||||||
static const float NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD = 4.0f;
|
static const float NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD = 4.0f;
|
||||||
for (int k = 0; k < keyCount; ++k) {
|
for (int k = 0; k < keyCount; ++k) {
|
||||||
|
@ -146,7 +167,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
|
||||||
hypotf(mProximityInfo->getKeyboardWidth(), mProximityInfo->getKeyboardHeight())
|
hypotf(mProximityInfo->getKeyboardWidth(), mProximityInfo->getKeyboardHeight())
|
||||||
* READ_FORWORD_LENGTH_SCALE);
|
* READ_FORWORD_LENGTH_SCALE);
|
||||||
for (int i = 0; i < mInputSize; ++i) {
|
for (int i = 0; i < mInputSize; ++i) {
|
||||||
for (int j = i + 1; j < mInputSize; ++j) {
|
for (int j = max(i + 1, lastSavedInputSize); j < mInputSize; ++j) {
|
||||||
if (mLengthCache[j] - mLengthCache[i] >= readForwordLength) {
|
if (mLengthCache[j] - mLengthCache[i] >= readForwordLength) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -199,6 +220,18 @@ 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) {
|
||||||
|
for (int i = 0; i < mInputSize; ++i) {
|
||||||
|
const int index = mInputIndice[i];
|
||||||
|
if (index > inputSize || xCoordinates[index] != mInputXs[i] ||
|
||||||
|
yCoordinates[index] != mInputYs[i] || times[index] != mTimes[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculating point to key distance for all near keys and returning the distance between
|
// Calculating point to key distance for all near keys and returning the distance between
|
||||||
// the given point and the nearest key position.
|
// the given point and the nearest key position.
|
||||||
float ProximityInfoState::updateNearKeysDistances(const int x, const int y,
|
float ProximityInfoState::updateNearKeysDistances(const int x, const int y,
|
||||||
|
@ -305,8 +338,8 @@ float ProximityInfoState::getPointScore(
|
||||||
|
|
||||||
// Sampling touch point and pushing information to vectors.
|
// Sampling touch point and pushing information to vectors.
|
||||||
// Returning if previous point is popped or not.
|
// Returning if previous point is popped or not.
|
||||||
bool ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y, const int time,
|
bool ProximityInfoState::pushTouchPoint(const int inputIndex, const int nodeChar, int x, int y,
|
||||||
const bool sample, const bool isLastPoint,
|
const int time, const bool sample, const bool isLastPoint,
|
||||||
NearKeysDistanceMap *const currentNearKeysDistances,
|
NearKeysDistanceMap *const currentNearKeysDistances,
|
||||||
const NearKeysDistanceMap *const prevNearKeysDistances,
|
const NearKeysDistanceMap *const prevNearKeysDistances,
|
||||||
const NearKeysDistanceMap *const prevPrevNearKeysDistances) {
|
const NearKeysDistanceMap *const prevPrevNearKeysDistances) {
|
||||||
|
@ -320,10 +353,7 @@ bool ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y, const
|
||||||
currentNearKeysDistances, prevNearKeysDistances, prevPrevNearKeysDistances);
|
currentNearKeysDistances, prevNearKeysDistances, prevPrevNearKeysDistances);
|
||||||
if (score < 0) {
|
if (score < 0) {
|
||||||
// Pop previous point because it would be useless.
|
// Pop previous point because it would be useless.
|
||||||
mInputXs.pop_back();
|
popInputData();
|
||||||
mInputYs.pop_back();
|
|
||||||
mTimes.pop_back();
|
|
||||||
mLengthCache.pop_back();
|
|
||||||
size = mInputXs.size();
|
size = mInputXs.size();
|
||||||
popped = true;
|
popped = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -371,6 +401,7 @@ bool ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y, const
|
||||||
mInputXs.push_back(x);
|
mInputXs.push_back(x);
|
||||||
mInputYs.push_back(y);
|
mInputYs.push_back(y);
|
||||||
mTimes.push_back(time);
|
mTimes.push_back(time);
|
||||||
|
mInputIndice.push_back(inputIndex);
|
||||||
return popped;
|
return popped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,4 +492,12 @@ float ProximityInfoState::getAveragePointDuration() const {
|
||||||
return static_cast<float>(mTimes[mInputSize - 1] - mTimes[0]) / static_cast<float>(mInputSize);
|
return static_cast<float>(mTimes[mInputSize - 1] - mTimes[0]) / static_cast<float>(mInputSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProximityInfoState::popInputData() {
|
||||||
|
mInputXs.pop_back();
|
||||||
|
mInputYs.pop_back();
|
||||||
|
mTimes.pop_back();
|
||||||
|
mLengthCache.pop_back();
|
||||||
|
mInputIndice.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
|
|
|
@ -57,9 +57,9 @@ class ProximityInfoState {
|
||||||
: mProximityInfo(0), mMaxPointToKeyLength(0),
|
: mProximityInfo(0), mMaxPointToKeyLength(0),
|
||||||
mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0), mLocaleStr(),
|
mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0), mLocaleStr(),
|
||||||
mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0),
|
mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0),
|
||||||
mInputXs(), mInputYs(), mTimes(), mDistanceCache(), mLengthCache(),
|
mIsContinuationPossible(false), mInputXs(), mInputYs(), mTimes(), mInputIndice(),
|
||||||
mNearKeysVector(), mTouchPositionCorrectionEnabled(false),
|
mDistanceCache(), mLengthCache(), mNearKeysVector(),
|
||||||
mInputSize(0) {
|
mTouchPositionCorrectionEnabled(false), mInputSize(0) {
|
||||||
memset(mInputCodes, 0, sizeof(mInputCodes));
|
memset(mInputCodes, 0, sizeof(mInputCodes));
|
||||||
memset(mNormalizedSquaredDistances, 0, sizeof(mNormalizedSquaredDistances));
|
memset(mNormalizedSquaredDistances, 0, sizeof(mNormalizedSquaredDistances));
|
||||||
memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
|
memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
|
||||||
|
@ -212,6 +212,10 @@ class ProximityInfoState {
|
||||||
return mLengthCache[index];
|
return mLengthCache[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isContinuationPossible() const {
|
||||||
|
return mIsContinuationPossible;
|
||||||
|
}
|
||||||
|
|
||||||
float getPointToKeyLength(const int inputIndex, const int charCode, const float scale) const;
|
float getPointToKeyLength(const int inputIndex, const int charCode, const float scale) const;
|
||||||
|
|
||||||
int getSpaceY() const;
|
int getSpaceY() const;
|
||||||
|
@ -231,7 +235,7 @@ class ProximityInfoState {
|
||||||
float calculateSquaredDistanceFromSweetSpotCenter(
|
float calculateSquaredDistanceFromSweetSpotCenter(
|
||||||
const int keyIndex, const int inputIndex) const;
|
const int keyIndex, const int inputIndex) const;
|
||||||
|
|
||||||
bool pushTouchPoint(const int nodeChar, int x, int y, const int time,
|
bool pushTouchPoint(const int inputIndex, const int nodeChar, int x, int y, const int time,
|
||||||
const bool sample, const bool isLastPoint,
|
const bool sample, const bool isLastPoint,
|
||||||
NearKeysDistanceMap *const currentNearKeysDistances,
|
NearKeysDistanceMap *const currentNearKeysDistances,
|
||||||
const NearKeysDistanceMap *const prevNearKeysDistances,
|
const NearKeysDistanceMap *const prevNearKeysDistances,
|
||||||
|
@ -259,6 +263,9 @@ class ProximityInfoState {
|
||||||
const NearKeysDistanceMap *const currentNearKeysDistances,
|
const NearKeysDistanceMap *const currentNearKeysDistances,
|
||||||
const NearKeysDistanceMap *const prevNearKeysDistances,
|
const NearKeysDistanceMap *const prevNearKeysDistances,
|
||||||
const NearKeysDistanceMap *const prevPrevNearKeysDistances) const;
|
const NearKeysDistanceMap *const prevPrevNearKeysDistances) const;
|
||||||
|
bool checkAndReturnIsContinuationPossible(const int inputSize, const int *const xCoordinates,
|
||||||
|
const int *const yCoordinates, const int *const times);
|
||||||
|
void popInputData();
|
||||||
|
|
||||||
// const
|
// const
|
||||||
const ProximityInfo *mProximityInfo;
|
const ProximityInfo *mProximityInfo;
|
||||||
|
@ -271,10 +278,12 @@ class ProximityInfoState {
|
||||||
int mCellWidth;
|
int mCellWidth;
|
||||||
int mGridHeight;
|
int mGridHeight;
|
||||||
int mGridWidth;
|
int mGridWidth;
|
||||||
|
bool mIsContinuationPossible;
|
||||||
|
|
||||||
std::vector<int> mInputXs;
|
std::vector<int> mInputXs;
|
||||||
std::vector<int> mInputYs;
|
std::vector<int> mInputYs;
|
||||||
std::vector<int> mTimes;
|
std::vector<int> mTimes;
|
||||||
|
std::vector<int> mInputIndice;
|
||||||
std::vector<float> mDistanceCache;
|
std::vector<float> mDistanceCache;
|
||||||
std::vector<int> mLengthCache;
|
std::vector<int> mLengthCache;
|
||||||
std::vector<NearKeycodesSet> mNearKeysVector;
|
std::vector<NearKeycodesSet> mNearKeysVector;
|
||||||
|
|
Loading…
Reference in a new issue