Step 39-A Cleanup proximity_info_state

Change-Id: I6070929f310f7dc6359d12d62e81d2e2e032c38e
main
Satoshi Kataoka 2012-08-24 15:19:56 +09:00
parent a1a669a121
commit 08f00cf55f
2 changed files with 62 additions and 58 deletions

View File

@ -26,7 +26,7 @@
namespace latinime { namespace latinime {
void ProximityInfoState::initInputParams(const int pointerId, const float maxPointToKeyLength, void ProximityInfoState::initInputParams(const int pointerId, const float maxPointToKeyLength,
const ProximityInfo *proximityInfo, const int32_t *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) {
mProximityInfo = proximityInfo; mProximityInfo = proximityInfo;
@ -38,15 +38,14 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
mCellWidth = proximityInfo->getCellWidth(); mCellWidth = proximityInfo->getCellWidth();
mGridHeight = proximityInfo->getGridWidth(); mGridHeight = proximityInfo->getGridWidth();
mGridWidth = proximityInfo->getGridHeight(); mGridWidth = proximityInfo->getGridHeight();
const int normalizedSquaredDistancesLength =
MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH_INTERNAL;
for (int i = 0; i < normalizedSquaredDistancesLength; ++i) {
mNormalizedSquaredDistances[i] = NOT_A_DISTANCE;
}
memset(mInputCodes, 0, memset(mInputCodes, 0, sizeof(mInputCodes));
MAX_WORD_LENGTH_INTERNAL * MAX_PROXIMITY_CHARS_SIZE_INTERNAL * sizeof(mInputCodes[0]));
if (!isGeometric && pointerId == 0) {
// Initialize
// - mInputCodes
// - mNormalizedSquaredDistances
// TODO: Merge
for (int i = 0; i < inputSize; ++i) { for (int i = 0; i < inputSize; ++i) {
const int32_t primaryKey = inputCodes[i]; const int32_t primaryKey = inputCodes[i];
const int x = xCoordinates[i]; const int x = xCoordinates[i];
@ -67,10 +66,11 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
} }
} }
} }
}
mMaxPointToKeyLength = maxPointToKeyLength;
/////////////////////// ///////////////////////
// Setup touch points // Setup touch points
mMaxPointToKeyLength = maxPointToKeyLength;
mInputXs.clear(); mInputXs.clear();
mInputYs.clear(); mInputYs.clear();
mTimes.clear(); mTimes.clear();
@ -81,10 +81,10 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
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);
for (int i = 0; i < inputSize; ++i) { for (int i = 0; i < inputSize; ++i) {
++mInputSize;
// 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) {
++mInputSize;
const int c = isGeometric ? NOT_A_COORDINATE : getPrimaryCharAt(i); const int c = isGeometric ? NOT_A_COORDINATE : getPrimaryCharAt(i);
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];
@ -107,16 +107,19 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
} }
} }
} }
// end // end
/////////////////////// ///////////////////////
memset(mNormalizedSquaredDistances, NOT_A_DISTANCE, sizeof(mNormalizedSquaredDistances));
memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
mTouchPositionCorrectionEnabled = mInputSize > 0 && mHasTouchPositionCorrectionData
&& xCoordinates && yCoordinates && !isGeometric;
if (!isGeometric && pointerId == 0) {
for (int i = 0; i < inputSize; ++i) { for (int i = 0; i < inputSize; ++i) {
mPrimaryInputWord[i] = getPrimaryCharAt(i); mPrimaryInputWord[i] = getPrimaryCharAt(i);
} }
mPrimaryInputWord[inputSize] = 0;
mTouchPositionCorrectionEnabled = mInputSize > 0 && mHasTouchPositionCorrectionData
&& xCoordinates && yCoordinates && !isGeometric;
for (int i = 0; i < mInputSize && mTouchPositionCorrectionEnabled; ++i) { for (int i = 0; i < mInputSize && mTouchPositionCorrectionEnabled; ++i) {
const int *proximityChars = getProximityCharsAt(i); const int *proximityChars = getProximityCharsAt(i);
const int primaryKey = proximityChars[0]; const int primaryKey = proximityChars[0];
@ -146,6 +149,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
} }
} }
} }
}
} }
void ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y, void ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y,

View File

@ -42,9 +42,9 @@ class ProximityInfoState {
// Defined in proximity_info_state.cpp // // Defined in proximity_info_state.cpp //
///////////////////////////////////////// /////////////////////////////////////////
void initInputParams(const int pointerId, const float maxPointToKeyLength, void initInputParams(const int pointerId, const float maxPointToKeyLength,
const ProximityInfo *proximityInfo, const int32_t *inputCodes, const int inputSize, const ProximityInfo *proximityInfo, const int32_t *const inputCodes,
const int *xCoordinates, const int *yCoordinates, const int *const times, const int inputSize, const int *xCoordinates, const int *yCoordinates,
const int *const pointerIds, const bool isGeometric); const int *const times, const int *const pointerIds, const bool isGeometric);
///////////////////////////////////////// /////////////////////////////////////////
// Defined here // // Defined here //