aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/geometry_utils.h
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2012-09-12 23:40:48 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-09-12 23:40:48 -0700
commit6b966b2623647ebbab0e2a51f1390be93c422f2b (patch)
tree76c26c733662b6227cff7830d15f854427fedac6 /native/jni/src/geometry_utils.h
parentcdf4135f6332d5e2bb25f6447e0d1fb735eb1976 (diff)
parentf4554d8b10f25ab300d057ff0ebd16b2b7a70be8 (diff)
downloadlatinime-6b966b2623647ebbab0e2a51f1390be93c422f2b.tar.gz
latinime-6b966b2623647ebbab0e2a51f1390be93c422f2b.tar.xz
latinime-6b966b2623647ebbab0e2a51f1390be93c422f2b.zip
am f4554d8b: Fix an issue on FP calculation diff of osx and linux
* commit 'f4554d8b10f25ab300d057ff0ebd16b2b7a70be8': Fix an issue on FP calculation diff of osx and linux
Diffstat (limited to 'native/jni/src/geometry_utils.h')
-rw-r--r--native/jni/src/geometry_utils.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/native/jni/src/geometry_utils.h b/native/jni/src/geometry_utils.h
index f30e9fcc0..bad5eda61 100644
--- a/native/jni/src/geometry_utils.h
+++ b/native/jni/src/geometry_utils.h
@@ -25,14 +25,17 @@
#define M_PI_F 3.14159265f
-namespace latinime {
+#define ROUND_FLOAT_10000(f) ((f) < 1000.0f && (f) > 0.001f) \
+ ? (floorf((f) * 10000.0f) / 10000.0f) : (f)
-static inline float squareFloat(float x) {
- return x * x;
-}
+#define SQUARE_FLOAT(x) ((x) * (x))
+
+namespace latinime {
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) {
@@ -52,9 +55,11 @@ static inline float getAngle(int x1, int y1, int x2, int y2) {
}
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) {
- return 2.0f * M_PI_F - diff;
+ const float normalizedDiff = 2.0f * M_PI_F - diff;
+ return ROUND_FLOAT_10000(normalizedDiff);
}
return diff;
}
@@ -76,7 +81,7 @@ static inline float pointToLineSegSquaredDistanceFloat(
const float ray2y = y2 - y1;
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;
float projectionX;