parent
7afd910242
commit
c25c7ccf25
|
@ -114,40 +114,53 @@ void ProximityInfo::setInputParams(const int* inputCodes, const int inputLength,
|
||||||
mPrimaryInputWord[i] = getPrimaryCharAt(i);
|
mPrimaryInputWord[i] = getPrimaryCharAt(i);
|
||||||
}
|
}
|
||||||
mPrimaryInputWord[inputLength] = 0;
|
mPrimaryInputWord[inputLength] = 0;
|
||||||
|
for (int i = 0; i < mInputLength; ++i) {
|
||||||
|
mSweetSpotTypes[i] = calculateSweetSpotType(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float square(const float x) { return x * x; }
|
inline float square(const float x) { return x * x; }
|
||||||
|
|
||||||
ProximityInfo::SweetSpotType ProximityInfo::calculateSweetSpotType(
|
ProximityInfo::SweetSpotType ProximityInfo::calculateSweetSpotType(int index) const {
|
||||||
int index, unsigned short baseLowerC) const {
|
if (KEY_COUNT == 0 || !mInputXCoordinates || !mInputYCoordinates) {
|
||||||
if (KEY_COUNT == 0 || !mInputXCoordinates || !mInputYCoordinates
|
// We do not have the coordinate data
|
||||||
|| baseLowerC > MAX_CHAR_CODE) {
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
const int currentChar = getPrimaryCharAt(index);
|
||||||
|
const unsigned short baseLowerC = Dictionary::toBaseLowerCase(currentChar);
|
||||||
|
if (baseLowerC > MAX_CHAR_CODE) {
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
const int keyIndex = mCodeToKeyIndex[baseLowerC];
|
const int keyIndex = mCodeToKeyIndex[baseLowerC];
|
||||||
if (keyIndex < 0) {
|
if (keyIndex < 0) {
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
const float sweetSpotRadius = mSweetSpotRadii[keyIndex];
|
const float radius = mSweetSpotRadii[keyIndex];
|
||||||
if (sweetSpotRadius <= 0.0) {
|
if (radius <= 0.0) {
|
||||||
|
// When there are no calibration data for a key,
|
||||||
|
// the radius of the key is assigned to zero.
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
const float sweetSpotCenterX = mSweetSpotCenterXs[keyIndex];
|
const float squaredRadius = square(radius);
|
||||||
const float sweetSpotCenterY = mSweetSpotCenterYs[keyIndex];
|
const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(keyIndex, index);
|
||||||
const float inputX = (float)mInputXCoordinates[index];
|
if (squaredDistance <= squaredRadius) {
|
||||||
const float inputY = (float)mInputYCoordinates[index];
|
|
||||||
const float squaredDistance =
|
|
||||||
square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
|
|
||||||
const float squaredSweetSpotRadius = square(sweetSpotRadius);
|
|
||||||
if (squaredDistance <= squaredSweetSpotRadius) {
|
|
||||||
return IN_SWEET_SPOT;
|
return IN_SWEET_SPOT;
|
||||||
}
|
}
|
||||||
if (squaredDistance <= square(NEUTRAL_AREA_RADIUS_RATIO) * squaredSweetSpotRadius) {
|
if (squaredDistance <= square(NEUTRAL_AREA_RADIUS_RATIO) * squaredRadius) {
|
||||||
return IN_NEUTRAL_AREA;
|
return IN_NEUTRAL_AREA;
|
||||||
}
|
}
|
||||||
return OUT_OF_NEUTRAL_AREA;
|
return OUT_OF_NEUTRAL_AREA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ProximityInfo::calculateSquaredDistanceFromSweetSpotCenter(
|
||||||
|
int keyIndex, int inputIndex) const {
|
||||||
|
const float sweetSpotCenterX = mSweetSpotCenterXs[keyIndex];
|
||||||
|
const float sweetSpotCenterY = mSweetSpotCenterYs[keyIndex];
|
||||||
|
const float inputX = (float)mInputXCoordinates[inputIndex];
|
||||||
|
const float inputY = (float)mInputYCoordinates[inputIndex];
|
||||||
|
return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
|
||||||
|
}
|
||||||
|
|
||||||
inline const int* ProximityInfo::getProximityCharsAt(const int index) const {
|
inline const int* ProximityInfo::getProximityCharsAt(const int index) const {
|
||||||
return mInputCodes + (index * MAX_PROXIMITY_CHARS_SIZE);
|
return mInputCodes + (index * MAX_PROXIMITY_CHARS_SIZE);
|
||||||
}
|
}
|
||||||
|
@ -201,8 +214,7 @@ ProximityInfo::ProximityType ProximityInfo::getMatchedProximityId(
|
||||||
// that means the user typed that same char for this pos.
|
// that means the user typed that same char for this pos.
|
||||||
if (firstChar == baseLowerC || firstChar == c) {
|
if (firstChar == baseLowerC || firstChar == c) {
|
||||||
if (CALIBRATE_SCORE_BY_TOUCH_COORDINATES) {
|
if (CALIBRATE_SCORE_BY_TOUCH_COORDINATES) {
|
||||||
const SweetSpotType result = calculateSweetSpotType(index, baseLowerC);
|
switch (mSweetSpotTypes[index]) {
|
||||||
switch (result) {
|
|
||||||
case UNKNOWN:
|
case UNKNOWN:
|
||||||
return EQUIVALENT_CHAR_NORMAL;
|
return EQUIVALENT_CHAR_NORMAL;
|
||||||
case IN_SWEET_SPOT:
|
case IN_SWEET_SPOT:
|
||||||
|
|
|
@ -81,7 +81,9 @@ private:
|
||||||
|
|
||||||
int getStartIndexFromCoordinates(const int x, const int y) const;
|
int getStartIndexFromCoordinates(const int x, const int y) const;
|
||||||
void initializeCodeToKeyIndex();
|
void initializeCodeToKeyIndex();
|
||||||
SweetSpotType calculateSweetSpotType(int index, unsigned short baseLowerC) const;
|
SweetSpotType calculateSweetSpotType(int index) const;
|
||||||
|
float calculateSquaredDistanceFromSweetSpotCenter(int keyIndex, int inputIndex) const;
|
||||||
|
|
||||||
const int MAX_PROXIMITY_CHARS_SIZE;
|
const int MAX_PROXIMITY_CHARS_SIZE;
|
||||||
const int KEYBOARD_WIDTH;
|
const int KEYBOARD_WIDTH;
|
||||||
const int KEYBOARD_HEIGHT;
|
const int KEYBOARD_HEIGHT;
|
||||||
|
@ -102,6 +104,7 @@ private:
|
||||||
float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||||
float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||||
float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||||
|
SweetSpotType mSweetSpotTypes[MAX_WORD_LENGTH_INTERNAL];
|
||||||
int mInputLength;
|
int mInputLength;
|
||||||
unsigned short mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL];
|
unsigned short mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL];
|
||||||
int mCodeToKeyIndex[MAX_CHAR_CODE + 1];
|
int mCodeToKeyIndex[MAX_CHAR_CODE + 1];
|
||||||
|
|
Loading…
Reference in New Issue