am 6b966b26: am f4554d8b: Fix an issue on FP calculation diff of osx and linux

* commit '6b966b2623647ebbab0e2a51f1390be93c422f2b':
  Fix an issue on FP calculation diff of osx and linux
This commit is contained in:
Satoshi Kataoka 2012-09-13 14:11:04 -07:00 committed by Android Git Automerger
commit 877545e895
3 changed files with 20 additions and 9 deletions

View file

@ -25,14 +25,17 @@
#define M_PI_F 3.14159265f #define M_PI_F 3.14159265f
#define ROUND_FLOAT_10000(f) ((f) < 1000.0f && (f) > 0.001f) \
? (floorf((f) * 10000.0f) / 10000.0f) : (f)
#define SQUARE_FLOAT(x) ((x) * (x))
namespace latinime { namespace latinime {
static inline float squareFloat(float x) {
return x * x;
}
static inline float getSquaredDistanceFloat(float x1, float y1, float x2, float y2) { static inline float getSquaredDistanceFloat(float x1, float y1, float x2, float y2) {
return squareFloat(x1 - x2) + squareFloat(y1 - y2); const float deltaX = x1 - x2;
const float deltaY = y1 - y2;
return SQUARE_FLOAT(deltaX) + SQUARE_FLOAT(deltaY);
} }
static inline float getDistanceFloat(float x1, float y1, float x2, float y2) { static inline float getDistanceFloat(float x1, float y1, float x2, float y2) {
@ -52,9 +55,11 @@ static inline float getAngle(int x1, int y1, int x2, int y2) {
} }
static inline float getAngleDiff(float a1, float a2) { static inline float getAngleDiff(float a1, float a2) {
const float diff = fabsf(a1 - a2); const float deltaA = fabsf(a1 - a2);
const float diff = ROUND_FLOAT_10000(deltaA);
if (diff > M_PI_F) { if (diff > M_PI_F) {
return 2.0f * M_PI_F - diff; const float normalizedDiff = 2.0f * M_PI_F - diff;
return ROUND_FLOAT_10000(normalizedDiff);
} }
return diff; return diff;
} }
@ -76,7 +81,7 @@ static inline float pointToLineSegSquaredDistanceFloat(
const float ray2y = y2 - y1; const float ray2y = y2 - y1;
const float dotProduct = ray1x * ray2x + ray1y * ray2y; const float dotProduct = ray1x * ray2x + ray1y * ray2y;
const float lineLengthSqr = squareFloat(ray2x) + squareFloat(ray2y); const float lineLengthSqr = SQUARE_FLOAT(ray2x) + SQUARE_FLOAT(ray2y);
const float projectionLengthSqr = dotProduct / lineLengthSqr; const float projectionLengthSqr = dotProduct / lineLengthSqr;
float projectionX; float projectionX;

View file

@ -141,7 +141,9 @@ bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
static inline float getNormalizedSquaredDistanceFloat(float x1, float y1, float x2, float y2, static inline float getNormalizedSquaredDistanceFloat(float x1, float y1, float x2, float y2,
float scale) { float scale) {
return squareFloat((x1 - x2) / scale) + squareFloat((y1 - y2) / scale); const float deltaX = x1 - x2;
const float deltaY = y1 - y2;
return (SQUARE_FLOAT(deltaX) + SQUARE_FLOAT(deltaY)) / SQUARE_FLOAT(scale);
} }
float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloat( float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloat(

View file

@ -177,6 +177,10 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
hypotf(mProximityInfo->getKeyboardWidth(), mProximityInfo->getKeyboardHeight()) hypotf(mProximityInfo->getKeyboardWidth(), mProximityInfo->getKeyboardHeight())
* READ_FORWORD_LENGTH_SCALE); * READ_FORWORD_LENGTH_SCALE);
for (int i = 0; i < mInputSize; ++i) { for (int i = 0; i < mInputSize; ++i) {
if (DEBUG_GEO_FULL) {
AKLOGI("Sampled(%d): x = %d, y = %d, time = %d", i, mInputXs[i], mInputYs[i],
mTimes[i]);
}
for (int j = max(i + 1, lastSavedInputSize); j < mInputSize; ++j) { for (int j = max(i + 1, lastSavedInputSize); j < mInputSize; ++j) {
if (mLengthCache[j] - mLengthCache[i] >= readForwordLength) { if (mLengthCache[j] - mLengthCache[i] >= readForwordLength) {
break; break;