aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/suggest_utils.h
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2013-04-15 03:24:16 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-04-15 03:24:16 -0700
commitd55ccbf7f95bb1af2d0b4a60994fb05af502e325 (patch)
tree91a17cee7ac752540c5abc3ac1a973fa2e676e16 /native/jni/src/suggest_utils.h
parentbe0e013be879aec19197a9e1b0a1d2631a8d4c79 (diff)
parent837f46dcb35a8f42a6bd5bc5fc6395d7386acb81 (diff)
downloadlatinime-d55ccbf7f95bb1af2d0b4a60994fb05af502e325.tar.gz
latinime-d55ccbf7f95bb1af2d0b4a60994fb05af502e325.tar.xz
latinime-d55ccbf7f95bb1af2d0b4a60994fb05af502e325.zip
am 837f46dc: Enable touch coordinate correction for new algorithm
* commit '837f46dcb35a8f42a6bd5bc5fc6395d7386acb81': Enable touch coordinate correction for new algorithm
Diffstat (limited to 'native/jni/src/suggest_utils.h')
-rw-r--r--native/jni/src/suggest_utils.h39
1 files changed, 35 insertions, 4 deletions
diff --git a/native/jni/src/suggest_utils.h b/native/jni/src/suggest_utils.h
index aab9f7ba8..e053dd662 100644
--- a/native/jni/src/suggest_utils.h
+++ b/native/jni/src/suggest_utils.h
@@ -23,10 +23,8 @@
namespace latinime {
class SuggestUtils {
public:
- static float getDistanceScalingFactor(const float normalizedSquaredDistance) {
- if (normalizedSquaredDistance < 0.0f) {
- return -1.0f;
- }
+ // TODO: (OLD) Remove
+ static float getLengthScalingFactor(const float normalizedSquaredDistance) {
// Promote or demote the score according to the distance from the sweet spot
static const float A = ZERO_DISTANCE_PROMOTION_RATE / 100.0f;
static const float B = 1.0f;
@@ -50,6 +48,39 @@ class SuggestUtils {
return factor;
}
+ static float getSweetSpotFactor(const bool isTouchPositionCorrectionEnabled,
+ const float normalizedSquaredDistance) {
+ // Promote or demote the score according to the distance from the sweet spot
+ static const float A = 0.0f;
+ static const float B = 0.24f;
+ static const float C = 1.20f;
+ static const float R0 = 0.0f;
+ static const float R1 = 0.25f; // Sweet spot
+ static const float R2 = 1.0f;
+ const float x = normalizedSquaredDistance;
+ if (!isTouchPositionCorrectionEnabled) {
+ return min(C, x);
+ }
+
+ // factor is a piecewise linear function like:
+ // C -------------.
+ // / .
+ // B / .
+ // -/ .
+ // A _-^ .
+ // .
+ // R0 R1 R2 .
+
+ if (x < R0) {
+ return A;
+ } else if (x < R1) {
+ return (A * (R1 - x) + B * (x - R0)) / (R1 - R0);
+ } else if (x < R2) {
+ return (B * (R2 - x) + C * (x - R1)) / (R2 - R1);
+ } else {
+ return C;
+ }
+ }
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestUtils);
};