13e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka/*
23e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * Copyright (C) 2012 The Android Open Source Project
33e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka *
43e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * Licensed under the Apache License, Version 2.0 (the "License");
53e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * you may not use this file except in compliance with the License.
63e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * You may obtain a copy of the License at
73e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka *
83e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka *      http://www.apache.org/licenses/LICENSE-2.0
93e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka *
103e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * Unless required by applicable law or agreed to in writing, software
113e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * distributed under the License is distributed on an "AS IS" BASIS,
123e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * See the License for the specific language governing permissions and
143e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka * limitations under the License.
153e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka */
163e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
173e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka#ifndef LATINIME_PROXIMITY_INFO_STATE_H
183e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka#define LATINIME_PROXIMITY_INFO_STATE_H
193e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
20162c211b44c1546b2e9be36e0cec50de497217a9Ken Wakasa#include <cstring> // for memset()
21687a244703a02323ebd64433cbaead5def499861Satoshi Kataoka#include <vector>
223e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
234a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka#include "char_utils.h"
243e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka#include "defines.h"
25d9c10b19793b011f862e3dd31883f746044431d7Keisuke Kuroyanagi#include "hash_map_compat.h"
26ee62b78c9675bddaf2437e0cf521f6115e1d9febSatoshi Kataoka#include "proximity_info_params.h"
2747cc52415e3affb83eb4369190425b2a17b956c5Satoshi Kataoka#include "proximity_info_state_utils.h"
283e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
293e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataokanamespace latinime {
303e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
313e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataokaclass ProximityInfo;
323e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
333e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataokaclass ProximityInfoState {
343e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka public:
353e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    /////////////////////////////////////////
363e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    // Defined in proximity_info_state.cpp //
373e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    /////////////////////////////////////////
38233aad5e5c7567a97af30f38f50a65365f729dfeSatoshi Kataoka    void initInputParams(const int pointerId, const float maxPointToKeyLength,
391e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa            const ProximityInfo *proximityInfo, const int *const inputCodes,
4008f00cf55f2e083c1ed254a32495b622c9ad9862Satoshi Kataoka            const int inputSize, const int *xCoordinates, const int *yCoordinates,
4108f00cf55f2e083c1ed254a32495b622c9ad9862Satoshi Kataoka            const int *const times, const int *const pointerIds, const bool isGeometric);
423e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
433e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    /////////////////////////////////////////
443e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    // Defined here                        //
453e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    /////////////////////////////////////////
466e66349ed1d37c24a1a23bf117df6750ad53d322Ken Wakasa    AK_FORCE_INLINE ProximityInfoState()
479af533538ea749d7c930bb3125fa4d3e4feb8478Satoshi Kataoka            : mProximityInfo(0), mMaxPointToKeyLength(0.0f), mAverageSpeed(0.0f),
480c2227ab991774768414d8ea60a469f005eb9f1aKen Wakasa              mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0),
49162c211b44c1546b2e9be36e0cec50de497217a9Ken Wakasa              mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0),
50394b0bd345f33b1314613a433478fd0bb711e0f7Satoshi Kataoka              mIsContinuousSuggestionPossible(false), mSampledInputXs(), mSampledInputYs(),
51394b0bd345f33b1314613a433478fd0bb711e0f7Satoshi Kataoka              mSampledTimes(), mSampledInputIndice(), mSampledLengthCache(),
52837f46dcb35a8f42a6bd5bc5fc6395d7386acb81Satoshi Kataoka              mBeelineSpeedPercentiles(), mSampledNormalizedSquaredLengthCache(), mSpeedRates(),
53837f46dcb35a8f42a6bd5bc5fc6395d7386acb81Satoshi Kataoka              mDirections(), mCharProbabilities(), mSampledNearKeySets(), mSampledSearchKeySets(),
54394b0bd345f33b1314613a433478fd0bb711e0f7Satoshi Kataoka              mSampledSearchKeyVectors(), mTouchPositionCorrectionEnabled(false),
55394b0bd345f33b1314613a433478fd0bb711e0f7Satoshi Kataoka              mSampledInputSize(0), mMostProbableStringProbability(0.0f) {
56bf78e1371c12d819020d60f0e585f5e6c26e6aa2Satoshi Kataoka        memset(mInputProximities, 0, sizeof(mInputProximities));
57162c211b44c1546b2e9be36e0cec50de497217a9Ken Wakasa        memset(mNormalizedSquaredDistances, 0, sizeof(mNormalizedSquaredDistances));
58162c211b44c1546b2e9be36e0cec50de497217a9Ken Wakasa        memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
5920b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka        memset(mMostProbableString, 0, sizeof(mMostProbableString));
60162c211b44c1546b2e9be36e0cec50de497217a9Ken Wakasa    }
61162c211b44c1546b2e9be36e0cec50de497217a9Ken Wakasa
626e66349ed1d37c24a1a23bf117df6750ad53d322Ken Wakasa    // Non virtual inline destructor -- never inherit this class
636e66349ed1d37c24a1a23bf117df6750ad53d322Ken Wakasa    AK_FORCE_INLINE ~ProximityInfoState() {}
643e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
651e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa    inline int getPrimaryCodePointAt(const int index) const {
661e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa        return getProximityCodePointsAt(index)[0];
673e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    }
683e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
6920b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka    inline bool sameAsTyped(const int *word, int length) const {
7020b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka        if (length != mSampledInputSize) {
7120b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka            return false;
7220b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka        }
7320b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka        const int *inputProximities = mInputProximities;
7420b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka        while (length--) {
7520b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka            if (*inputProximities != *word) {
7620b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka                return false;
7720b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka            }
7820b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka            inputProximities += MAX_PROXIMITY_CHARS_SIZE;
7920b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka            word++;
8020b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka        }
8120b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka        return true;
8220b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka    }
8320b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka
846e66349ed1d37c24a1a23bf117df6750ad53d322Ken Wakasa    AK_FORCE_INLINE bool existsCodePointInProximityAt(const int index, const int c) const {
851e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa        const int *codePoints = getProximityCodePointsAt(index);
863e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        int i = 0;
876c22439bf80da08576e86c1282afc5cfa431e235Ken Wakasa        while (codePoints[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE) {
881e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa            if (codePoints[i++] == c) {
893e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka                return true;
903e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka            }
913e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        }
923e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        return false;
933e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    }
943e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
953e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    inline bool existsAdjacentProximityChars(const int index) const {
96feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka        if (index < 0 || index >= mSampledInputSize) return false;
971e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa        const int currentCodePoint = getPrimaryCodePointAt(index);
983e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        const int leftIndex = index - 1;
991e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa        if (leftIndex >= 0 && existsCodePointInProximityAt(leftIndex, currentCodePoint)) {
1003e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka            return true;
1013e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        }
1023e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        const int rightIndex = index + 1;
103feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka        if (rightIndex < mSampledInputSize
104feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka                && existsCodePointInProximityAt(rightIndex, currentCodePoint)) {
1053e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka            return true;
1063e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        }
1073e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        return false;
1083e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    }
1093e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
1103e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    inline int getNormalizedSquaredDistance(
1113e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka            const int inputIndex, const int proximityIndex) const {
1124a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka        return mNormalizedSquaredDistances[
1136c22439bf80da08576e86c1282afc5cfa431e235Ken Wakasa                inputIndex * MAX_PROXIMITY_CHARS_SIZE + proximityIndex];
1143e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    }
1153e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
1161e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa    inline const int *getPrimaryInputWord() const {
1173e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        return mPrimaryInputWord;
1183e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    }
1193e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
1203e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    inline bool touchPositionCorrectionEnabled() const {
1213e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka        return mTouchPositionCorrectionEnabled;
1223e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    }
1233e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
124687a244703a02323ebd64433cbaead5def499861Satoshi Kataoka    bool isUsed() const {
125feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka        return mSampledInputSize > 0;
126687a244703a02323ebd64433cbaead5def499861Satoshi Kataoka    }
127687a244703a02323ebd64433cbaead5def499861Satoshi Kataoka
128203b2138136bc00219d371897237f6b0b1795b9cSatoshi Kataoka    int size() const {
129feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka        return mSampledInputSize;
13037b153e205c9672b299b47e97921fee2462a78bbSatoshi Kataoka    }
13137b153e205c9672b299b47e97921fee2462a78bbSatoshi Kataoka
1323811a28ddc07201930e0bbd2e1d01045b59af308Keisuke Kuroyanagi    int getInputX(const int index) const {
133feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka        return mSampledInputXs[index];
13437b153e205c9672b299b47e97921fee2462a78bbSatoshi Kataoka    }
13537b153e205c9672b299b47e97921fee2462a78bbSatoshi Kataoka
1363811a28ddc07201930e0bbd2e1d01045b59af308Keisuke Kuroyanagi    int getInputY(const int index) const {
137feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka        return mSampledInputYs[index];
13837b153e205c9672b299b47e97921fee2462a78bbSatoshi Kataoka    }
13937b153e205c9672b299b47e97921fee2462a78bbSatoshi Kataoka
140f32869c6b6296a8bf594abdf0b18281d9312e54fSatoshi Kataoka    bool hasSpaceProximity(const int index) const;
141f32869c6b6296a8bf594abdf0b18281d9312e54fSatoshi Kataoka
1423811a28ddc07201930e0bbd2e1d01045b59af308Keisuke Kuroyanagi    int getLengthCache(const int index) const {
143d7a8fbf6a9ec8828d4b6d1c615a6c605bbe5b72eSatoshi Kataoka        return mSampledLengthCache[index];
14437b153e205c9672b299b47e97921fee2462a78bbSatoshi Kataoka    }
14537b153e205c9672b299b47e97921fee2462a78bbSatoshi Kataoka
146394b0bd345f33b1314613a433478fd0bb711e0f7Satoshi Kataoka    bool isContinuousSuggestionPossible() const {
147394b0bd345f33b1314613a433478fd0bb711e0f7Satoshi Kataoka        return mIsContinuousSuggestionPossible;
148096f35ff4b5413906e2a339663baf16e5dabaf64Keisuke Kuroyanagi    }
149096f35ff4b5413906e2a339663baf16e5dabaf64Keisuke Kuroyanagi
150837f46dcb35a8f42a6bd5bc5fc6395d7386acb81Satoshi Kataoka    // TODO: Rename s/Length/NormalizedSquaredLength/
151806eba452423e5e5971ef096dfae3fed180db665Keisuke Kuroyanagi    float getPointToKeyByIdLength(const int inputIndex, const int keyId) const;
152837f46dcb35a8f42a6bd5bc5fc6395d7386acb81Satoshi Kataoka    // TODO: Rename s/Length/NormalizedSquaredLength/
1532192d08b9cca6a40d834d6a5001d19b5845ed8a0Tom Ouyang    float getPointToKeyLength(const int inputIndex, const int codePoint) const;
154687a244703a02323ebd64433cbaead5def499861Satoshi Kataoka
155697a9d3541dd5b643664fc1af9b3265267370127Satoshi Kataoka    ProximityType getProximityType(const int index, const int codePoint,
1562c2f3a90d8115777adbe9ffd597f344aede84276Ken Wakasa            const bool checkProximityChars, int *proximityIndex = 0) const;
1572c2f3a90d8115777adbe9ffd597f344aede84276Ken Wakasa
158697a9d3541dd5b643664fc1af9b3265267370127Satoshi Kataoka    ProximityType getProximityTypeG(const int index, const int codePoint) const;
159697a9d3541dd5b643664fc1af9b3265267370127Satoshi Kataoka
160e5cdd21102e4e49b18c696261a084783eb6d7e7aSatoshi Kataoka    const std::vector<int> *getSearchKeyVector(const int index) const {
161e5cdd21102e4e49b18c696261a084783eb6d7e7aSatoshi Kataoka        return &mSampledSearchKeyVectors[index];
162e5cdd21102e4e49b18c696261a084783eb6d7e7aSatoshi Kataoka    }
16395a49a527ac9c2c97cfcc758bd6f0d58fb4ad9c0Keisuke Kuroyanagi
1649af533538ea749d7c930bb3125fa4d3e4feb8478Satoshi Kataoka    float getSpeedRate(const int index) const {
1659af533538ea749d7c930bb3125fa4d3e4feb8478Satoshi Kataoka        return mSpeedRates[index];
1669af533538ea749d7c930bb3125fa4d3e4feb8478Satoshi Kataoka    }
1679af533538ea749d7c930bb3125fa4d3e4feb8478Satoshi Kataoka
1686ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka    AK_FORCE_INLINE int getBeelineSpeedPercentile(const int id) const {
1696ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka        return mBeelineSpeedPercentiles[id];
1706ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka    }
1716ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka
1726ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka    AK_FORCE_INLINE DoubleLetterLevel getDoubleLetterLevel(const int id) const {
1736ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka        const int beelineSpeedRate = getBeelineSpeedPercentile(id);
1746ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka        if (beelineSpeedRate == 0) {
1756ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka            return A_STRONG_DOUBLE_LETTER;
176ee62b78c9675bddaf2437e0cf521f6115e1d9febSatoshi Kataoka        } else if (beelineSpeedRate
177ee62b78c9675bddaf2437e0cf521f6115e1d9febSatoshi Kataoka                < ProximityInfoParams::MIN_DOUBLE_LETTER_BEELINE_SPEED_PERCENTILE) {
1786ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka            return A_DOUBLE_LETTER;
1796ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka        } else {
1806ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka            return NOT_A_DOUBLE_LETTER;
1816ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka        }
18228661069591fd1d6a8e25981aaade2e5d8b20b9aKeisuke Kuroyanagi    }
183806eba452423e5e5971ef096dfae3fed180db665Keisuke Kuroyanagi
1841e06a4d8e9e71188ed685282155ea52a48ddc050Keisuke Kuroyanagi    float getDirection(const int index) const {
1851e06a4d8e9e71188ed685282155ea52a48ddc050Keisuke Kuroyanagi        return mDirections[index];
1861e06a4d8e9e71188ed685282155ea52a48ddc050Keisuke Kuroyanagi    }
187ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    // get xy direction
188ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    float getDirection(const int x, const int y) const;
189ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi
190e0349619acdba79223390c9925d81f7e88c7f8adSatoshi Kataoka    float getMostProbableString(int *const codePointBuf) const;
191ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi
192ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    float getProbability(const int index, const int charCode) const;
193ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi
194ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    float getLineToKeyDistance(
195ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi            const int from, const int to, const int keyId, const bool extend) const;
196ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi
197ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    bool isKeyInSerchKeysAfterIndex(const int index, const int keyId) const;
198e599d7e317092da396ab0a9d2098c170e3b98dc6Ken Wakasa
1993e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka private:
2001bc038c5e40bd0fa7a44331a569abe3ae88f0152satok    DISALLOW_COPY_AND_ASSIGN(ProximityInfoState);
2014a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    /////////////////////////////////////////
2024a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    // Defined in proximity_info_state.cpp //
2034a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    /////////////////////////////////////////
2044a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
2053e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
2064a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    float calculateSquaredDistanceFromSweetSpotCenter(
2074a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka            const int keyIndex, const int inputIndex) const;
2084a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka
2094a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    /////////////////////////////////////////
2104a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    // Defined here                        //
2114a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    /////////////////////////////////////////
2123e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
2131e61493c50082264caaef862df02b1ccc84dc396Ken Wakasa    inline const int *getProximityCodePointsAt(const int index) const {
21447cc52415e3affb83eb4369190425b2a17b956c5Satoshi Kataoka        return ProximityInfoStateUtils::getProximityCodePointsAt(mInputProximities, index);
215fee0ac60b1cd0a4760ca8f310ff8a86b925d833bKen Wakasa    }
216d9c10b19793b011f862e3dd31883f746044431d7Keisuke Kuroyanagi
2174a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    // const
2184a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    const ProximityInfo *mProximityInfo;
219687a244703a02323ebd64433cbaead5def499861Satoshi Kataoka    float mMaxPointToKeyLength;
2209af533538ea749d7c930bb3125fa4d3e4feb8478Satoshi Kataoka    float mAverageSpeed;
2214a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    bool mHasTouchPositionCorrectionData;
2224a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    int mMostCommonKeyWidthSquare;
2234a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    int mKeyCount;
2244a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    int mCellHeight;
2254a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    int mCellWidth;
2264a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    int mGridHeight;
2274a3db7057f77dc85311fb1f94934b5a004ab613eSatoshi Kataoka    int mGridWidth;
228394b0bd345f33b1314613a433478fd0bb711e0f7Satoshi Kataoka    bool mIsContinuousSuggestionPossible;
2293e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka
230feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka    std::vector<int> mSampledInputXs;
231feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka    std::vector<int> mSampledInputYs;
232d7a8fbf6a9ec8828d4b6d1c615a6c605bbe5b72eSatoshi Kataoka    std::vector<int> mSampledTimes;
233d7a8fbf6a9ec8828d4b6d1c615a6c605bbe5b72eSatoshi Kataoka    std::vector<int> mSampledInputIndice;
234d7a8fbf6a9ec8828d4b6d1c615a6c605bbe5b72eSatoshi Kataoka    std::vector<int> mSampledLengthCache;
2356ae8dd4343445d2df4444388b605d2aa930fa2a0Satoshi Kataoka    std::vector<int> mBeelineSpeedPercentiles;
236837f46dcb35a8f42a6bd5bc5fc6395d7386acb81Satoshi Kataoka    std::vector<float> mSampledNormalizedSquaredLengthCache;
2379af533538ea749d7c930bb3125fa4d3e4feb8478Satoshi Kataoka    std::vector<float> mSpeedRates;
2381e06a4d8e9e71188ed685282155ea52a48ddc050Keisuke Kuroyanagi    std::vector<float> mDirections;
239806eba452423e5e5971ef096dfae3fed180db665Keisuke Kuroyanagi    // probabilities of skipping or mapping to a key for each point.
240806eba452423e5e5971ef096dfae3fed180db665Keisuke Kuroyanagi    std::vector<hash_map_compat<int, float> > mCharProbabilities;
241ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    // The vector for the key code set which holds nearby keys for each sampled input point
242ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    // 1. Used to calculate the probability of the key
243e5cdd21102e4e49b18c696261a084783eb6d7e7aSatoshi Kataoka    // 2. Used to calculate mSampledSearchKeySets
244e5cdd21102e4e49b18c696261a084783eb6d7e7aSatoshi Kataoka    std::vector<ProximityInfoStateUtils::NearKeycodesSet> mSampledNearKeySets;
245ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    // The vector for the key code set which holds nearby keys of some trailing sampled input points
246ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    // for each sampled input point. These nearby keys contain the next characters which can be in
247ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    // the dictionary. Specifically, currently we are looking for keys nearby trailing sampled
248ff74cc3e5e75fc0c6b9ffaa5e68d879775dc6115Keisuke Kuroyanagi    // inputs including the current input point.
249e5cdd21102e4e49b18c696261a084783eb6d7e7aSatoshi Kataoka    std::vector<ProximityInfoStateUtils::NearKeycodesSet> mSampledSearchKeySets;
250e5cdd21102e4e49b18c696261a084783eb6d7e7aSatoshi Kataoka    std::vector<std::vector<int> > mSampledSearchKeyVectors;
2513e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka    bool mTouchPositionCorrectionEnabled;
2526c22439bf80da08576e86c1282afc5cfa431e235Ken Wakasa    int mInputProximities[MAX_PROXIMITY_CHARS_SIZE * MAX_WORD_LENGTH];
2536c22439bf80da08576e86c1282afc5cfa431e235Ken Wakasa    int mNormalizedSquaredDistances[MAX_PROXIMITY_CHARS_SIZE * MAX_WORD_LENGTH];
254feec20a692c9ffdecf7855a45531a12f129086caSatoshi Kataoka    int mSampledInputSize;
2555db594abbad2d9e8d2cf1aa6e417aa50ffc5dfc1Ken Wakasa    int mPrimaryInputWord[MAX_WORD_LENGTH];
25620b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka    float mMostProbableStringProbability;
25720b6775acc957896bdb038dfd99794d6cd7cea5aSatoshi Kataoka    int mMostProbableString[MAX_WORD_LENGTH];
2583e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka};
2593e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka} // namespace latinime
2603e8c58f68d53e6cc9dbf59201c7bdfb8ad04a1cdSatoshi Kataoka#endif // LATINIME_PROXIMITY_INFO_STATE_H
261