am 7324052a: Merge "Refactor proximity info"

# Via Android (Google) Code Review (1) and Satoshi Kataoka (1)
* commit '7324052ad73d9ead3612ddd3b64f9ed96e6bbcab':
  Refactor proximity info
This commit is contained in:
Satoshi Kataoka 2013-01-24 16:14:15 -08:00 committed by Android Git Automerger
commit aca66ac942
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 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.

View file

@ -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

View file

@ -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<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,
const int *const inputXCoordinates, const int *const inputYCoordinates,
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<float> *const sampledSpeedRates,
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:
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoStateUtils);