Refactor proximity info

Change-Id: Ie9ea10fe6850721dd7fe64ffc05edc68f2217d2e
main
Satoshi Kataoka 2013-01-24 15:20:50 +09:00
parent e5aad56463
commit 9d18c6dd38
4 changed files with 38 additions and 39 deletions

View File

@ -33,8 +33,10 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
const ProximityInfo *proximityInfo, const int *const inputCodes, const int inputSize, 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 xCoordinates, const int *const yCoordinates, const int *const times,
const int *const pointerIds, const bool isGeometric) { const int *const pointerIds, const bool isGeometric) {
mIsContinuationPossible = checkAndReturnIsContinuationPossible( ASSERT(isGeometric || (inputSize < MAX_WORD_LENGTH));
inputSize, xCoordinates, yCoordinates, times, isGeometric); mIsContinuationPossible = ProximityInfoStateUtils::checkAndReturnIsContinuationPossible(
inputSize, xCoordinates, yCoordinates, times, mSampledInputSize, &mSampledInputXs,
&mSampledInputYs, &mSampledTimes, &mSampledInputIndice);
mProximityInfo = proximityInfo; mProximityInfo = proximityInfo;
mHasTouchPositionCorrectionData = proximityInfo->hasTouchPositionCorrectionData(); 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 // TODO: Remove the "scale" parameter
// This function basically converts from a length to an edit distance. Accordingly, it's obviously // This function basically converts from a length to an edit distance. Accordingly, it's obviously
// wrong to compare with mMaxPointToKeyLength. // wrong to compare with mMaxPointToKeyLength.

View File

@ -122,8 +122,6 @@ class ProximityInfoState {
return true; return true;
} }
int getDuration(const int index) const;
bool isUsed() const { bool isUsed() const {
return mSampledInputSize > 0; return mSampledInputSize > 0;
} }
@ -217,8 +215,6 @@ class ProximityInfoState {
inline const int *getProximityCodePointsAt(const int index) const { inline const int *getProximityCodePointsAt(const int index) const {
return ProximityInfoStateUtils::getProximityCodePointsAt(mInputProximities, index); 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(); void popInputData();
// const // const

View File

@ -983,6 +983,34 @@ namespace latinime {
return true; 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<int> *const sampledInputXs,
const std::vector<int> *const sampledInputYs,
const std::vector<int> *const sampledTimes,
const std::vector<int> *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, /* static */ void ProximityInfoStateUtils::dump(const bool isGeometric, const int inputSize,
const int *const inputXCoordinates, const int *const inputYCoordinates, const int *const inputXCoordinates, const int *const inputYCoordinates,
const int sampledInputSize, const std::vector<int> *const sampledInputXs, const int sampledInputSize, const std::vector<int> *const sampledInputXs,

View File

@ -107,6 +107,12 @@ class ProximityInfoStateUtils {
const std::vector<int> *const sampledTimes, const std::vector<int> *const sampledTimes,
const std::vector<float> *const sampledSpeedRates, const std::vector<float> *const sampledSpeedRates,
const std::vector<int> *const sampledBeelineSpeedPercentiles); const std::vector<int> *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<int> *const sampledInputXs,
const std::vector<int> *const sampledInputYs,
const std::vector<int> *const sampledTimes,
const std::vector<int> *const sampledInputIndices);
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoStateUtils); DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoStateUtils);