1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H 18 #define LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H 19 20 #include "defines.h" 21 #include "suggest/core/layout/proximity_info_params.h" 22 23 namespace latinime { 24 class TouchPositionCorrectionUtils { 25 public: 26 static float getSweetSpotFactor(const bool isTouchPositionCorrectionEnabled, 27 const float normalizedSquaredDistance) { 28 // Promote or demote the score according to the distance from the sweet spot 29 static const float A = 0.0f; 30 static const float B = 0.24f; 31 static const float C = 1.20f; 32 static const float R0 = 0.0f; 33 static const float R1 = 0.25f; // Sweet spot 34 static const float R2 = 1.0f; 35 const float x = normalizedSquaredDistance; 36 if (!isTouchPositionCorrectionEnabled) { 37 return min(C, x); 38 } 39 40 // factor is a piecewise linear function like: 41 // C -------------. 42 // / . 43 // B / . 44 // -/ . 45 // A _-^ . 46 // . 47 // R0 R1 R2 . 48 49 if (x < R0) { 50 return A; 51 } else if (x < R1) { 52 return (A * (R1 - x) + B * (x - R0)) / (R1 - R0); 53 } else if (x < R2) { 54 return (B * (R2 - x) + C * (x - R1)) / (R2 - R1); 55 } else { 56 return C; 57 } 58 } 59 private: 60 DISALLOW_IMPLICIT_CONSTRUCTORS(TouchPositionCorrectionUtils); 61 }; 62 } // namespace latinime 63 #endif // LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H 64