float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloatG( const int keyId, const int x, const int y, const bool isGeometric) const { const float centerX = static_cast<float>(getKeyCenterXOfKeyIdG(keyId, x, isGeometric)); const float centerY = static_cast<float>(getKeyCenterYOfKeyIdG(keyId, y, isGeometric)); const float touchX = static_cast<float>(x); const float touchY = static_cast<float>(y); return ProximityInfoUtils::getSquaredDistanceFloat(centerX, centerY, touchX, touchY) / GeometryUtils::SQUARE_FLOAT(static_cast<float>(getMostCommonKeyWidth())); }
// referencePointX is used only for keys wider than most common key width. When the referencePointX // is NOT_A_COORDINATE, this method calculates the return value without using the line segment. // isGeometric is currently not used because we don't have extra X coordinates sweet spots for // geometric input. int ProximityInfo::getKeyCenterXOfKeyIdG( const int keyId, const int referencePointX, const bool isGeometric) const { if (keyId < 0) { return 0; } int centerX = (hasTouchPositionCorrectionData()) ? static_cast<int>(mSweetSpotCenterXs[keyId]) : mCenterXsG[keyId]; const int keyWidth = mKeyWidths[keyId]; if (referencePointX != NOT_A_COORDINATE && keyWidth > getMostCommonKeyWidth()) { // For keys wider than most common keys, we use a line segment instead of the center point; // thus, centerX is adjusted depending on referencePointX. const int keyWidthHalfDiff = (keyWidth - getMostCommonKeyWidth()) / 2; if (referencePointX < centerX - keyWidthHalfDiff) { centerX -= keyWidthHalfDiff; } else if (referencePointX > centerX + keyWidthHalfDiff) { centerX += keyWidthHalfDiff; } else { centerX = referencePointX; } } return centerX; }
float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloatG( const int keyId, const int x, const int y, const float verticalScale) const { const bool correctTouchPosition = hasTouchPositionCorrectionData(); const float centerX = static_cast<float>(correctTouchPosition ? getSweetSpotCenterXAt(keyId) : getKeyCenterXOfKeyIdG(keyId)); const float visualKeyCenterY = static_cast<float>(getKeyCenterYOfKeyIdG(keyId)); float centerY; if (correctTouchPosition) { const float sweetSpotCenterY = static_cast<float>(getSweetSpotCenterYAt(keyId)); const float gapY = sweetSpotCenterY - visualKeyCenterY; centerY = visualKeyCenterY + gapY * verticalScale; } else { centerY = visualKeyCenterY; } const float touchX = static_cast<float>(x); const float touchY = static_cast<float>(y); const float keyWidth = static_cast<float>(getMostCommonKeyWidth()); return ProximityInfoUtils::getSquaredDistanceFloat(centerX, centerY, touchX, touchY) / SQUARE_FLOAT(keyWidth); }