2013-01-15 10:16:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LATINIME_SUGGEST_UTILS_H
|
|
|
|
#define LATINIME_SUGGEST_UTILS_H
|
|
|
|
|
|
|
|
#include "defines.h"
|
2013-01-22 08:00:43 +00:00
|
|
|
#include "proximity_info_params.h"
|
2013-01-15 10:16:38 +00:00
|
|
|
|
|
|
|
namespace latinime {
|
|
|
|
class SuggestUtils {
|
|
|
|
public:
|
2013-01-15 16:29:43 +00:00
|
|
|
static float getDistanceScalingFactor(const float normalizedSquaredDistance) {
|
2013-01-15 10:16:38 +00:00
|
|
|
if (normalizedSquaredDistance < 0.0f) {
|
|
|
|
return -1.0f;
|
|
|
|
}
|
|
|
|
// 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;
|
|
|
|
static const float C = 0.5f;
|
|
|
|
static const float MIN = 0.3f;
|
|
|
|
static const float R1 = NEUTRAL_SCORE_SQUARED_RADIUS;
|
|
|
|
static const float R2 = HALF_SCORE_SQUARED_RADIUS;
|
2013-01-15 16:29:43 +00:00
|
|
|
const float x = normalizedSquaredDistance / static_cast<float>(
|
2013-01-22 08:00:43 +00:00
|
|
|
ProximityInfoParams::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR);
|
2013-01-15 10:16:38 +00:00
|
|
|
const float factor = max((x < R1)
|
|
|
|
? (A * (R1 - x) + B * x) / R1
|
|
|
|
: (B * (R2 - x) + C * (x - R1)) / (R2 - R1), MIN);
|
|
|
|
// factor is a piecewise linear function like:
|
|
|
|
// A -_ .
|
|
|
|
// ^-_ .
|
|
|
|
// B \ .
|
|
|
|
// \_ .
|
|
|
|
// C ------------.
|
|
|
|
// .
|
|
|
|
// 0 R1 R2 .
|
|
|
|
return factor;
|
|
|
|
}
|
2013-01-15 16:29:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestUtils);
|
2013-01-15 10:16:38 +00:00
|
|
|
};
|
|
|
|
} // namespace latinime
|
|
|
|
#endif // LATINIME_SUGGEST_UTILS_H
|