OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2011 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_PROXIMITY_INFO_H |
| 18 #define LATINIME_PROXIMITY_INFO_H |
| 19 |
| 20 #include <string> |
| 21 #include <unordered_map> |
| 22 |
| 23 #include "third_party/prediction/defines.h" |
| 24 #include "third_party/prediction/suggest/core/layout/proximity_info_utils.h" |
| 25 |
| 26 namespace latinime { |
| 27 |
| 28 class ProximityInfo { |
| 29 public: |
| 30 ProximityInfo(const std::string localeJStr, |
| 31 const int keyboardWidth, |
| 32 const int keyboardHeight, |
| 33 const int gridWidth, |
| 34 const int gridHeight, |
| 35 const int mostCommonKeyWidth, |
| 36 const int mostCommonKeyHeight, |
| 37 int* proximityChars, |
| 38 int proximitySize, |
| 39 const int keyCount, |
| 40 const int* keyXCoordinates, |
| 41 const int* keyYCoordinates, |
| 42 const int* keyWidths, |
| 43 const int* keyHeights, |
| 44 const int* keyCharCodes, |
| 45 const float* sweetSpotCenterXs, |
| 46 const float* sweetSpotCenterYs, |
| 47 const float* sweetSpotRadii); |
| 48 ~ProximityInfo(); |
| 49 bool hasSpaceProximity(const int x, const int y) const; |
| 50 float getNormalizedSquaredDistanceFromCenterFloatG( |
| 51 const int keyId, |
| 52 const int x, |
| 53 const int y, |
| 54 const bool isGeometric) const; |
| 55 int getCodePointOf(const int keyIndex) const; |
| 56 int getOriginalCodePointOf(const int keyIndex) const; |
| 57 bool hasSweetSpotData(const int keyIndex) const { |
| 58 // When there are no calibration data for a key, |
| 59 // the radius of the key is assigned to zero. |
| 60 return mSweetSpotRadii[keyIndex] > 0.0f; |
| 61 } |
| 62 float getSweetSpotRadiiAt(int keyIndex) const { |
| 63 return mSweetSpotRadii[keyIndex]; |
| 64 } |
| 65 float getSweetSpotCenterXAt(int keyIndex) const { |
| 66 return mSweetSpotCenterXs[keyIndex]; |
| 67 } |
| 68 float getSweetSpotCenterYAt(int keyIndex) const { |
| 69 return mSweetSpotCenterYs[keyIndex]; |
| 70 } |
| 71 bool hasTouchPositionCorrectionData() const { |
| 72 return HAS_TOUCH_POSITION_CORRECTION_DATA; |
| 73 } |
| 74 int getMostCommonKeyWidth() const { return MOST_COMMON_KEY_WIDTH; } |
| 75 int getMostCommonKeyWidthSquare() const { |
| 76 return MOST_COMMON_KEY_WIDTH_SQUARE; |
| 77 } |
| 78 float getNormalizedSquaredMostCommonKeyHypotenuse() const { |
| 79 return NORMALIZED_SQUARED_MOST_COMMON_KEY_HYPOTENUSE; |
| 80 } |
| 81 int getKeyCount() const { return KEY_COUNT; } |
| 82 int getCellHeight() const { return CELL_HEIGHT; } |
| 83 int getCellWidth() const { return CELL_WIDTH; } |
| 84 int getGridWidth() const { return GRID_WIDTH; } |
| 85 int getGridHeight() const { return GRID_HEIGHT; } |
| 86 int getKeyboardWidth() const { return KEYBOARD_WIDTH; } |
| 87 int getKeyboardHeight() const { return KEYBOARD_HEIGHT; } |
| 88 float getKeyboardHypotenuse() const { return KEYBOARD_HYPOTENUSE; } |
| 89 |
| 90 int getKeyCenterXOfKeyIdG(const int keyId, |
| 91 const int referencePointX, |
| 92 const bool isGeometric) const; |
| 93 int getKeyCenterYOfKeyIdG(const int keyId, |
| 94 const int referencePointY, |
| 95 const bool isGeometric) const; |
| 96 int getKeyKeyDistanceG(int keyId0, int keyId1) const; |
| 97 |
| 98 AK_FORCE_INLINE void initializeProximities(const int* const inputCodes, |
| 99 const int* const inputXCoordinates, |
| 100 const int* const inputYCoordinates, |
| 101 const int inputSize, |
| 102 int* allInputCodes) const { |
| 103 ProximityInfoUtils::initializeProximities( |
| 104 inputCodes, inputXCoordinates, inputYCoordinates, inputSize, |
| 105 mKeyXCoordinates, mKeyYCoordinates, mKeyWidths, mKeyHeights, |
| 106 mProximityCharsArray, CELL_HEIGHT, CELL_WIDTH, GRID_WIDTH, |
| 107 MOST_COMMON_KEY_WIDTH, KEY_COUNT, mLocaleStr, &mLowerCodePointToKeyMap, |
| 108 allInputCodes); |
| 109 } |
| 110 |
| 111 AK_FORCE_INLINE int getKeyIndexOf(const int c) const { |
| 112 return ProximityInfoUtils::getKeyIndexOf(KEY_COUNT, c, |
| 113 &mLowerCodePointToKeyMap); |
| 114 } |
| 115 |
| 116 AK_FORCE_INLINE bool isCodePointOnKeyboard(const int codePoint) const { |
| 117 return getKeyIndexOf(codePoint) != NOT_AN_INDEX; |
| 118 } |
| 119 |
| 120 private: |
| 121 DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo); |
| 122 |
| 123 void initializeG(); |
| 124 |
| 125 const int GRID_WIDTH; |
| 126 const int GRID_HEIGHT; |
| 127 const int MOST_COMMON_KEY_WIDTH; |
| 128 const int MOST_COMMON_KEY_WIDTH_SQUARE; |
| 129 const float NORMALIZED_SQUARED_MOST_COMMON_KEY_HYPOTENUSE; |
| 130 const int CELL_WIDTH; |
| 131 const int CELL_HEIGHT; |
| 132 const int KEY_COUNT; |
| 133 const int KEYBOARD_WIDTH; |
| 134 const int KEYBOARD_HEIGHT; |
| 135 const float KEYBOARD_HYPOTENUSE; |
| 136 const bool HAS_TOUCH_POSITION_CORRECTION_DATA; |
| 137 // Assuming locale strings such as en_US, sr-Latn etc. |
| 138 static const int MAX_LOCALE_STRING_LENGTH = 10; |
| 139 char mLocaleStr[MAX_LOCALE_STRING_LENGTH]; |
| 140 int* mProximityCharsArray; |
| 141 int mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 142 int mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 143 int mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 144 int mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 145 int mKeyCodePoints[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 146 float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 147 float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 148 // Sweet spots for geometric input. Note that we have extra sweet spots only |
| 149 // for Y coordinates. |
| 150 float mSweetSpotCenterYsG[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 151 float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 152 std::unordered_map<int, int> mLowerCodePointToKeyMap; |
| 153 int mKeyIndexToOriginalCodePoint[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 154 int mKeyIndexToLowerCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 155 int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 156 int mCenterYsG[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 157 int mKeyKeyDistancesG[MAX_KEY_COUNT_IN_A_KEYBOARD] |
| 158 [MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 159 }; |
| 160 } // namespace latinime |
| 161 #endif // LATINIME_PROXIMITY_INFO_H |
OLD | NEW |