2013-01-21 07:33:24 +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_PROXIMITY_INFO_STATE_UTILS_H
|
|
|
|
#define LATINIME_PROXIMITY_INFO_STATE_UTILS_H
|
|
|
|
|
2013-01-22 04:18:40 +00:00
|
|
|
#include <bitset>
|
2013-01-21 07:33:24 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "defines.h"
|
2013-01-22 04:18:40 +00:00
|
|
|
#include "hash_map_compat.h"
|
2013-01-21 07:33:24 +00:00
|
|
|
|
|
|
|
namespace latinime {
|
2013-01-21 09:29:27 +00:00
|
|
|
class ProximityInfo;
|
|
|
|
class ProximityInfoParams;
|
|
|
|
|
2013-01-21 07:33:24 +00:00
|
|
|
class ProximityInfoStateUtils {
|
|
|
|
public:
|
2013-01-22 04:18:40 +00:00
|
|
|
typedef hash_map_compat<int, float> NearKeysDistanceMap;
|
|
|
|
typedef std::bitset<MAX_KEY_COUNT_IN_A_KEYBOARD> NearKeycodesSet;
|
|
|
|
|
2013-01-21 07:33:24 +00:00
|
|
|
static int updateTouchPoints(const int mostCommonKeyWidth,
|
|
|
|
const ProximityInfo *const proximityInfo, const int maxPointToKeyLength,
|
|
|
|
const int *const inputProximities,
|
|
|
|
const int *const inputXCoordinates, const int *const inputYCoordinates,
|
|
|
|
const int *const times, const int *const pointerIds, const int inputSize,
|
|
|
|
const bool isGeometric, const int pointerId, const int pushTouchPointStartIndex,
|
|
|
|
std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs,
|
|
|
|
std::vector<int> *sampledInputTimes, std::vector<int> *sampledLengthCache,
|
2013-01-21 09:29:27 +00:00
|
|
|
std::vector<int> *sampledInputIndice);
|
2013-01-22 04:14:53 +00:00
|
|
|
static const int *getProximityCodePointsAt(const int *const inputProximities, const int index);
|
2013-01-21 09:29:27 +00:00
|
|
|
static int getPrimaryCodePointAt(const int *const inputProximities, const int index);
|
2013-01-21 07:33:24 +00:00
|
|
|
static void popInputData(std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs,
|
|
|
|
std::vector<int> *sampledInputTimes, std::vector<int> *sampledLengthCache,
|
2013-01-21 09:29:27 +00:00
|
|
|
std::vector<int> *sampledInputIndice);
|
|
|
|
static float refreshSpeedRates(const int inputSize, const int *const xCoordinates,
|
|
|
|
const int *const yCoordinates, const int *const times, const int lastSavedInputSize,
|
|
|
|
const int sampledInputSize, const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs,
|
|
|
|
const std::vector<int> *const sampledInputTimes,
|
|
|
|
const std::vector<int> *const sampledLengthCache,
|
|
|
|
const std::vector<int> *const sampledInputIndice,
|
|
|
|
std::vector<float> *sampledSpeedRates, std::vector<float> *sampledDirections);
|
|
|
|
static void refreshBeelineSpeedRates(const int mostCommonKeyWidth, const float averageSpeed,
|
|
|
|
const int inputSize, const int *const xCoordinates, const int *const yCoordinates,
|
|
|
|
const int *times, const int sampledInputSize,
|
|
|
|
const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs, const std::vector<int> *const inputIndice,
|
|
|
|
std::vector<int> *beelineSpeedPercentiles);
|
|
|
|
static float getDirection(const std::vector<int> *const sampledInputXs,
|
2013-01-22 04:14:53 +00:00
|
|
|
const std::vector<int> *const sampledInputYs, const int index0, const int index1);
|
2013-01-22 04:18:40 +00:00
|
|
|
static void updateAlignPointProbabilities(
|
|
|
|
const float maxPointToKeyLength, const int mostCommonKeyWidth, const int keyCount,
|
|
|
|
const int start, const int sampledInputSize,
|
|
|
|
const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs,
|
|
|
|
const std::vector<float> *const sampledSpeedRates,
|
|
|
|
const std::vector<int> *const sampledLengthCache,
|
2013-01-23 07:47:17 +00:00
|
|
|
const std::vector<float> *const SampledDistanceCache_G,
|
|
|
|
std::vector<NearKeycodesSet> *SampledNearKeysVector,
|
2013-01-22 04:18:40 +00:00
|
|
|
std::vector<hash_map_compat<int, float> > *charProbabilities);
|
2013-01-23 07:47:17 +00:00
|
|
|
static void updateSampledSearchKeysVector(
|
2013-01-23 05:37:56 +00:00
|
|
|
const ProximityInfo *const proximityInfo, const int sampledInputSize,
|
|
|
|
const int lastSavedInputSize,
|
|
|
|
const std::vector<int> *const sampledLengthCache,
|
2013-01-23 07:47:17 +00:00
|
|
|
const std::vector<NearKeycodesSet> *const SampledNearKeysVector,
|
|
|
|
std::vector<NearKeycodesSet> *sampledSearchKeysVector);
|
2013-01-22 04:18:40 +00:00
|
|
|
static float getPointToKeyByIdLength(const float maxPointToKeyLength,
|
2013-01-23 07:47:17 +00:00
|
|
|
const std::vector<float> *const SampledDistanceCache_G, const int keyCount,
|
2013-01-22 04:18:40 +00:00
|
|
|
const int inputIndex, const int keyId, const float scale);
|
|
|
|
static float getPointToKeyByIdLength(const float maxPointToKeyLength,
|
2013-01-23 07:47:17 +00:00
|
|
|
const std::vector<float> *const SampledDistanceCache_G, const int keyCount,
|
2013-01-22 04:18:40 +00:00
|
|
|
const int inputIndex, const int keyId);
|
2013-01-22 08:00:43 +00:00
|
|
|
static void initGeometricDistanceInfos(
|
|
|
|
const ProximityInfo *const proximityInfo, const int keyCount,
|
|
|
|
const int sampledInputSize, const int lastSavedInputSize,
|
|
|
|
const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs,
|
2013-01-23 07:47:17 +00:00
|
|
|
std::vector<NearKeycodesSet> *SampledNearKeysVector,
|
|
|
|
std::vector<float> *SampledDistanceCache_G);
|
2013-01-22 08:00:43 +00:00
|
|
|
static void initPrimaryInputWord(
|
|
|
|
const int inputSize, const int *const inputProximities, int *primaryInputWord);
|
|
|
|
static void initNormalizedSquaredDistances(
|
|
|
|
const ProximityInfo *const proximityInfo, const int inputSize,
|
|
|
|
const int *inputXCoordinates, const int *inputYCoordinates,
|
|
|
|
const int *const inputProximities, const bool hasInputCoordinates,
|
|
|
|
const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs,
|
|
|
|
int *normalizedSquaredDistances);
|
|
|
|
static void dump(const bool isGeometric, const int inputSize,
|
|
|
|
const int *const inputXCoordinates, const int *const inputYCoordinates,
|
|
|
|
const int sampledInputSize, const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs,
|
2013-01-23 05:37:56 +00:00
|
|
|
const std::vector<int> *const sampledTimes,
|
2013-01-22 08:00:43 +00:00
|
|
|
const std::vector<float> *const sampledSpeedRates,
|
|
|
|
const std::vector<int> *const sampledBeelineSpeedPercentiles);
|
2013-01-24 06:20:50 +00:00
|
|
|
static bool checkAndReturnIsContinuationPossible(const int inputSize,
|
|
|
|
const int *const xCoordinates, const int *const yCoordinates, const int *const times,
|
|
|
|
const int sampledInputSize, const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs,
|
|
|
|
const std::vector<int> *const sampledTimes,
|
|
|
|
const std::vector<int> *const sampledInputIndices);
|
2013-01-21 07:33:24 +00:00
|
|
|
private:
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoStateUtils);
|
|
|
|
|
|
|
|
static float updateNearKeysDistances(const ProximityInfo *const proximityInfo,
|
|
|
|
const float maxPointToKeyLength, const int x, const int y,
|
2013-01-21 09:29:27 +00:00
|
|
|
NearKeysDistanceMap *const currentNearKeysDistances);
|
2013-01-21 07:33:24 +00:00
|
|
|
static bool isPrevLocalMin(const NearKeysDistanceMap *const currentNearKeysDistances,
|
|
|
|
const NearKeysDistanceMap *const prevNearKeysDistances,
|
2013-01-21 09:29:27 +00:00
|
|
|
const NearKeysDistanceMap *const prevPrevNearKeysDistances);
|
2013-01-22 04:14:53 +00:00
|
|
|
static float getPointScore(const int mostCommonKeyWidth, const int x, const int y,
|
|
|
|
const int time, const bool lastPoint, const float nearest, const float sumAngle,
|
|
|
|
const NearKeysDistanceMap *const currentNearKeysDistances,
|
2013-01-21 07:33:24 +00:00
|
|
|
const NearKeysDistanceMap *const prevNearKeysDistances,
|
|
|
|
const NearKeysDistanceMap *const prevPrevNearKeysDistances,
|
2013-01-21 09:29:27 +00:00
|
|
|
std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs);
|
2013-01-21 07:33:24 +00:00
|
|
|
static bool pushTouchPoint(const int mostCommonKeyWidth,
|
|
|
|
const ProximityInfo *const proximityInfo, const int maxPointToKeyLength,
|
2013-01-22 04:14:53 +00:00
|
|
|
const int inputIndex, const int nodeCodePoint, int x, int y, const int time,
|
|
|
|
const bool doSampling, const bool isLastPoint, const float sumAngle,
|
2013-01-21 07:33:24 +00:00
|
|
|
NearKeysDistanceMap *const currentNearKeysDistances,
|
|
|
|
const NearKeysDistanceMap *const prevNearKeysDistances,
|
|
|
|
const NearKeysDistanceMap *const prevPrevNearKeysDistances,
|
|
|
|
std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs,
|
|
|
|
std::vector<int> *sampledInputTimes, std::vector<int> *sampledLengthCache,
|
2013-01-21 09:29:27 +00:00
|
|
|
std::vector<int> *sampledInputIndice);
|
|
|
|
static float calculateBeelineSpeedRate(const int mostCommonKeyWidth, const float averageSpeed,
|
|
|
|
const int id, const int inputSize, const int *const xCoordinates,
|
|
|
|
const int *const yCoordinates, const int *times, const int sampledInputSize,
|
|
|
|
const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs,
|
|
|
|
const std::vector<int> *const inputIndice);
|
2013-01-22 04:18:40 +00:00
|
|
|
static float getPointAngle(
|
|
|
|
const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs, const int index);
|
|
|
|
static float getPointsAngle(
|
|
|
|
const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs,
|
|
|
|
const int index0, const int index1, const int index2);
|
|
|
|
static bool suppressCharProbabilities(const int mostCommonKeyWidth,
|
|
|
|
const int sampledInputSize, const std::vector<int> *const lengthCache,
|
|
|
|
const int index0, const int index1,
|
|
|
|
std::vector<hash_map_compat<int, float> > *charProbabilities);
|
2013-01-22 08:00:43 +00:00
|
|
|
static float calculateSquaredDistanceFromSweetSpotCenter(
|
|
|
|
const ProximityInfo *const proximityInfo, const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs, const int keyIndex,
|
|
|
|
const int inputIndex);
|
|
|
|
static float calculateNormalizedSquaredDistance(
|
|
|
|
const ProximityInfo *const proximityInfo, const std::vector<int> *const sampledInputXs,
|
|
|
|
const std::vector<int> *const sampledInputYs, const int keyIndex, const int inputIndex);
|
2013-01-21 07:33:24 +00:00
|
|
|
};
|
|
|
|
} // namespace latinime
|
|
|
|
#endif // LATINIME_PROXIMITY_INFO_STATE_UTILS_H
|