Home | History | Annotate | Download | only in layout
      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 <algorithm>
     21 
     22 #include "defines.h"
     23 #include "suggest/core/layout/proximity_info_params.h"
     24 
     25 namespace latinime {
     26 class TouchPositionCorrectionUtils {
     27  public:
     28     static float getSweetSpotFactor(const bool isTouchPositionCorrectionEnabled,
     29             const float normalizedSquaredDistance) {
     30         // Promote or demote the score according to the distance from the sweet spot
     31         static const float A = 0.0f;
     32         static const float B = 0.24f;
     33         static const float C = 1.20f;
     34         static const float R0 = 0.0f;
     35         static const float R1 = 0.25f; // Sweet spot
     36         static const float R2 = 1.0f;
     37         const float x = normalizedSquaredDistance;
     38         if (!isTouchPositionCorrectionEnabled) {
     39             return std::min(C, x);
     40         }
     41 
     42         // factor is a piecewise linear function like:
     43         // C        -------------.
     44         //         /             .
     45         // B      /              .
     46         //      -/               .
     47         // A _-^                 .
     48         //                       .
     49         //   R0 R1 R2            .
     50 
     51         if (x < R0) {
     52             return A;
     53         } else if (x < R1) {
     54             return (A * (R1 - x) + B * (x - R0)) / (R1 - R0);
     55         } else if (x < R2) {
     56             return (B * (R2 - x) + C * (x - R1)) / (R2 - R1);
     57         } else {
     58             return C;
     59         }
     60     }
     61  private:
     62     DISALLOW_IMPLICIT_CONSTRUCTORS(TouchPositionCorrectionUtils);
     63 };
     64 } // namespace latinime
     65 #endif // LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H
     66