aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dictionaries/en_whitelist.xml82
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java14
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java59
-rw-r--r--java/src/com/android/inputmethod/latin/NativeUtils.java32
-rw-r--r--java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java2
-rw-r--r--native/jni/Android.mk1
-rw-r--r--native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp4
-rw-r--r--native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp39
-rw-r--r--native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp12
-rw-r--r--native/jni/com_android_inputmethod_latin_NativeUtils.cpp38
-rw-r--r--native/jni/com_android_inputmethod_latin_NativeUtils.h27
-rw-r--r--native/jni/jni_common.cpp6
-rw-r--r--native/jni/src/bigram_dictionary.cpp13
-rw-r--r--native/jni/src/char_utils.cpp9
-rw-r--r--native/jni/src/correction.cpp8
-rw-r--r--native/jni/src/debug.h7
-rw-r--r--native/jni/src/dictionary.cpp6
-rw-r--r--native/jni/src/dictionary.h11
-rw-r--r--native/jni/src/geometry_utils.h100
-rw-r--r--native/jni/src/gesture/gesture_decoder_wrapper.h10
-rw-r--r--native/jni/src/gesture/incremental_decoder_interface.h5
-rw-r--r--native/jni/src/gesture/incremental_decoder_wrapper.h10
-rw-r--r--native/jni/src/proximity_info.cpp4
-rw-r--r--native/jni/src/words_priority_queue.h9
25 files changed, 197 insertions, 316 deletions
diff --git a/dictionaries/en_whitelist.xml b/dictionaries/en_whitelist.xml
index f112077bd..e11935fdf 100644
--- a/dictionaries/en_whitelist.xml
+++ b/dictionaries/en_whitelist.xml
@@ -19,13 +19,13 @@
-->
<shortcuts>
<entry shortcut="ill">
- <target replacement="I\'ll" priority="whitelist" />
+ <target replacement="I'll" priority="whitelist" />
</entry>
<entry shortcut="acomodate">
<target replacement="accommodate" priority="whitelist" />
</entry>
<entry shortcut="aint">
- <target replacement="ain\'t" priority="whitelist" />
+ <target replacement="ain't" priority="whitelist" />
</entry>
<entry shortcut="alot">
<target replacement="a lot" priority="whitelist" />
@@ -34,7 +34,7 @@
<target replacement="and the" priority="whitelist" />
</entry>
<entry shortcut="arent">
- <target replacement="aren\'t" priority="whitelist" />
+ <target replacement="aren't" priority="whitelist" />
</entry>
<entry shortcut="bern">
<target replacement="been" priority="whitelist" />
@@ -49,13 +49,13 @@
<target replacement="can" priority="whitelist" />
</entry>
<entry shortcut="cant">
- <target replacement="can\'t" priority="whitelist" />
+ <target replacement="can't" priority="whitelist" />
</entry>
<entry shortcut="dame">
<target replacement="same" priority="whitelist" />
</entry>
<entry shortcut="didint">
- <target replacement="didn\'t" priority="whitelist" />
+ <target replacement="didn't" priority="whitelist" />
</entry>
<entry shortcut="dormer">
<target replacement="former" priority="whitelist" />
@@ -82,13 +82,13 @@
<target replacement="too" priority="whitelist" />
</entry>
<entry shortcut="hed">
- <target replacement="he\'d" priority="whitelist" />
+ <target replacement="he'd" priority="whitelist" />
</entry>
<entry shortcut="hel">
- <target replacement="he\'ll" priority="whitelist" />
+ <target replacement="he'll" priority="whitelist" />
</entry>
<entry shortcut="heres">
- <target replacement="here\'s" priority="whitelist" />
+ <target replacement="here's" priority="whitelist" />
</entry>
<entry shortcut="hew">
<target replacement="new" priority="whitelist" />
@@ -97,19 +97,19 @@
<target replacement="how" priority="whitelist" />
</entry>
<entry shortcut="hoes">
- <target replacement="how\'s" priority="whitelist" />
+ <target replacement="how's" priority="whitelist" />
</entry>
<entry shortcut="howd">
- <target replacement="how\'d" priority="whitelist" />
+ <target replacement="how'd" priority="whitelist" />
</entry>
<entry shortcut="howll">
- <target replacement="how\'ll" priority="whitelist" />
+ <target replacement="how'll" priority="whitelist" />
</entry>
<entry shortcut="hows">
- <target replacement="how\'s" priority="whitelist" />
+ <target replacement="how's" priority="whitelist" />
</entry>
<entry shortcut="howve">
- <target replacement="how\'ve" priority="whitelist" />
+ <target replacement="how've" priority="whitelist" />
</entry>
<entry shortcut="hum">
<target replacement="him" priority="whitelist" />
@@ -121,25 +121,25 @@
<target replacement="its" priority="whitelist" />
</entry>
<entry shortcut="il">
- <target replacement="I\'ll" priority="whitelist" />
+ <target replacement="I'll" priority="whitelist" />
</entry>
<entry shortcut="im">
- <target replacement="I\'m" priority="whitelist" />
+ <target replacement="I'm" priority="whitelist" />
</entry>
<entry shortcut="inteh">
<target replacement="in the" priority="whitelist" />
</entry>
<entry shortcut="itd">
- <target replacement="it\'d" priority="whitelist" />
+ <target replacement="it'd" priority="whitelist" />
</entry>
<entry shortcut="itsa">
- <target replacement="it\'s a" priority="whitelist" />
+ <target replacement="it's a" priority="whitelist" />
</entry>
<entry shortcut="lets">
- <target replacement="let\'s" priority="whitelist" />
+ <target replacement="let's" priority="whitelist" />
</entry>
<entry shortcut="maam">
- <target replacement="ma\'am" priority="whitelist" />
+ <target replacement="ma'am" priority="whitelist" />
</entry>
<entry shortcut="manu">
<target replacement="many" priority="whitelist" />
@@ -196,10 +196,10 @@
<target replacement="took" priority="whitelist" />
</entry>
<entry shortcut="shel">
- <target replacement="she\'ll" priority="whitelist" />
+ <target replacement="she'll" priority="whitelist" />
</entry>
<entry shortcut="shouldent">
- <target replacement="shouldn\'t" priority="whitelist" />
+ <target replacement="shouldn't" priority="whitelist" />
</entry>
<entry shortcut="sill">
<target replacement="will" priority="whitelist" />
@@ -208,7 +208,7 @@
<target replacement="down" priority="whitelist" />
</entry>
<entry shortcut="thatd">
- <target replacement="that\'d" priority="whitelist" />
+ <target replacement="that'd" priority="whitelist" />
</entry>
<entry shortcut="tine">
<target replacement="time" priority="whitelist" />
@@ -238,60 +238,60 @@
<target replacement="weird" priority="whitelist" />
</entry>
<entry shortcut="wel">
- <target replacement="we\'ll" priority="whitelist" />
+ <target replacement="we'll" priority="whitelist" />
</entry>
<entry shortcut="wer">
- <target replacement="we\'re" priority="whitelist" />
+ <target replacement="we're" priority="whitelist" />
</entry>
<entry shortcut="whatd">
- <target replacement="what\'d" priority="whitelist" />
+ <target replacement="what'd" priority="whitelist" />
</entry>
<entry shortcut="whatm">
- <target replacement="what\'m" priority="whitelist" />
+ <target replacement="what'm" priority="whitelist" />
</entry>
<entry shortcut="whatre">
- <target replacement="what\'re" priority="whitelist" />
+ <target replacement="what're" priority="whitelist" />
</entry>
<entry shortcut="whats">
- <target replacement="what\'s" priority="whitelist" />
+ <target replacement="what's" priority="whitelist" />
</entry>
<entry shortcut="whens">
- <target replacement="when\'s" priority="whitelist" />
+ <target replacement="when's" priority="whitelist" />
</entry>
<entry shortcut="whered">
- <target replacement="where\'d" priority="whitelist" />
+ <target replacement="where'd" priority="whitelist" />
</entry>
<entry shortcut="wherell">
- <target replacement="where\'ll" priority="whitelist" />
+ <target replacement="where'll" priority="whitelist" />
</entry>
<entry shortcut="wheres">
- <target replacement="where\'s" priority="whitelist" />
+ <target replacement="where's" priority="whitelist" />
</entry>
<entry shortcut="wholl">
- <target replacement="who\'ll" priority="whitelist" />
+ <target replacement="who'll" priority="whitelist" />
</entry>
<entry shortcut="whove">
- <target replacement="who\'ve" priority="whitelist" />
+ <target replacement="who've" priority="whitelist" />
</entry>
<entry shortcut="whyd">
- <target replacement="why\'d" priority="whitelist" />
+ <target replacement="why'd" priority="whitelist" />
</entry>
<entry shortcut="whyll">
- <target replacement="why\'ll" priority="whitelist" />
+ <target replacement="why'll" priority="whitelist" />
</entry>
<entry shortcut="whys">
- <target replacement="why\'s" priority="whitelist" />
+ <target replacement="why's" priority="whitelist" />
</entry>
<entry shortcut="whyve">
- <target replacement="why\'ve" priority="whitelist" />
+ <target replacement="why've" priority="whitelist" />
</entry>
<entry shortcut="wont">
- <target replacement="won\'t" priority="whitelist" />
+ <target replacement="won't" priority="whitelist" />
</entry>
<entry shortcut="yall">
- <target replacement="y\'all" priority="whitelist" />
+ <target replacement="y'all" priority="whitelist" />
</entry>
<entry shortcut="youd">
- <target replacement="you\'d" priority="whitelist" />
+ <target replacement="you'd" priority="whitelist" />
</entry>
</shortcuts>
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 85360c410..7d565a64f 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -29,7 +29,6 @@ import com.android.inputmethod.keyboard.internal.GestureStroke;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinImeLogger;
-import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger;
@@ -130,10 +129,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
private static final InputPointers sAggregratedPointers = new InputPointers(
GestureStroke.DEFAULT_CAPACITY);
private static PointerTrackerQueue sPointerTrackerQueue;
- // HACK: Change gesture detection criteria depending on this variable.
- // TODO: Find more comprehensive ways to detect a gesture start.
- // True when the previous user input was a gesture input, not a typing input.
- private static boolean sWasInGesture;
public final int mPointerId;
@@ -413,8 +408,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mKeyDetector = keyDetector;
mKeyboard = keyDetector.getKeyboard();
mIsAlphabetKeyboard = mKeyboard.mId.isAlphabetKeyboard();
- mGestureStroke.setGestureSampleLength(
- mKeyboard.mMostCommonKeyWidth, mKeyboard.mMostCommonKeyHeight);
+ mGestureStroke.setGestureSampleLength(mKeyboard.mMostCommonKeyWidth);
final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY);
if (newKey != mCurrentKey) {
if (mDrawingProxy != null) {
@@ -526,7 +520,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
public void drawGestureTrail(Canvas canvas, Paint paint) {
if (mInGesture) {
- mGestureStroke.drawGestureTrail(canvas, paint, mLastX, mLastY);
+ mGestureStroke.drawGestureTrail(canvas, paint);
}
}
@@ -586,7 +580,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mListener.onEndBatchInput(batchPoints);
clearBatchInputRecognitionStateOfThisPointerTracker();
clearBatchInputPointsOfAllPointerTrackers();
- sWasInGesture = true;
}
private void abortBatchInput() {
@@ -719,7 +712,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
if (sShouldHandleGesture && mIsPossibleGesture) {
final GestureStroke stroke = mGestureStroke;
stroke.addPoint(x, y, gestureTime, isHistorical);
- if (!mInGesture && stroke.isStartOfAGesture(gestureTime, sWasInGesture)) {
+ if (!mInGesture && stroke.isStartOfAGesture()) {
startBatchInput();
}
}
@@ -1002,7 +995,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
int code = key.mCode;
callListenerOnCodeInput(key, code, x, y);
callListenerOnRelease(key, code, false);
- sWasInGesture = false;
}
private void printTouchEvent(String title, int x, int y, long eventTime) {
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index ae123e29a..ac0a56ba3 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard;
import android.graphics.Rect;
import android.text.TextUtils;
-import android.util.FloatMath;
import com.android.inputmethod.keyboard.Keyboard.Params.TouchPositionCorrection;
import com.android.inputmethod.latin.JniUtils;
@@ -155,7 +154,9 @@ public class ProximityInfo {
final float radius = touchPositionCorrection.mRadii[row];
sweetSpotCenterXs[i] = hitBox.exactCenterX() + x * hitBoxWidth;
sweetSpotCenterYs[i] = hitBox.exactCenterY() + y * hitBoxHeight;
- sweetSpotRadii[i] = radius * FloatMath.sqrt(
+ // Note that, in recent versions of Android, FloatMath is actually slower than
+ // java.lang.Math due to the way the JIT optimizes java.lang.Math.
+ sweetSpotRadii[i] = radius * (float)Math.sqrt(
hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
index 28d6c1d07..79e977a40 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
@@ -16,7 +16,6 @@ package com.android.inputmethod.keyboard.internal;
import android.graphics.Canvas;
import android.graphics.Paint;
-import android.util.FloatMath;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.InputPointers;
@@ -38,19 +37,16 @@ public class GestureStroke {
private int mLastPointY;
private int mMinGestureLength;
- private int mMinGestureLengthWhileInGesture;
private int mMinGestureSampleLength;
// TODO: Move some of these to resource.
- private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 1.0f;
- private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH_WHILE_IN_GESTURE = 0.5f;
- private static final int MIN_GESTURE_DURATION = 150; // msec
- private static final int MIN_GESTURE_DURATION_WHILE_IN_GESTURE = 75; // msec
- private static final float MIN_GESTURE_SAMPLING_RATIO_TO_KEY_HEIGHT = 1.0f / 6.0f;
+ private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 0.75f;
+ private static final int MIN_GESTURE_DURATION = 100; // msec
+ private static final float MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH = 1.0f / 6.0f;
private static final float GESTURE_RECOG_SPEED_THRESHOLD = 0.4f; // dip/msec
private static final float GESTURE_RECOG_CURVATURE_THRESHOLD = (float)(Math.PI / 4.0f);
- private static final float DOUBLE_PI = (float)(2 * Math.PI);
+ private static final float DOUBLE_PI = (float)(2.0f * Math.PI);
// Fade based on number of gesture samples, see MIN_GESTURE_SAMPLING_RATIO_TO_KEY_HEIGHT
private static final int DRAWING_GESTURE_FADE_START = 10;
@@ -61,21 +57,15 @@ public class GestureStroke {
reset();
}
- public void setGestureSampleLength(final int keyWidth, final int keyHeight) {
+ public void setGestureSampleLength(final int keyWidth) {
// TODO: Find an appropriate base metric for these length. Maybe diagonal length of the key?
mMinGestureLength = (int)(keyWidth * MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH);
- mMinGestureLengthWhileInGesture = (int)(
- keyWidth * MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH_WHILE_IN_GESTURE);
- mMinGestureSampleLength = (int)(keyHeight * MIN_GESTURE_SAMPLING_RATIO_TO_KEY_HEIGHT);
+ mMinGestureSampleLength = (int)(keyWidth * MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH);
}
- public boolean isStartOfAGesture(final int downDuration, final boolean wasInGesture) {
- // The tolerance of the time duration and the stroke length to detect the start of a
- // gesture stroke should be eased when the previous input was a gesture input.
- if (wasInGesture) {
- return downDuration > MIN_GESTURE_DURATION_WHILE_IN_GESTURE
- && mLength > mMinGestureLengthWhileInGesture;
- }
+ public boolean isStartOfAGesture() {
+ final int size = mEventTimes.getLength();
+ final int downDuration = (size > 0) ? mEventTimes.get(size - 1) : 0;
return downDuration > MIN_GESTURE_DURATION && mLength > mMinGestureLength;
}
@@ -154,19 +144,21 @@ public class GestureStroke {
mLastIncrementalBatchSize = size;
}
- private static float getDistance(final int p1x, final int p1y,
- final int p2x, final int p2y) {
- final float dx = p1x - p2x;
- final float dy = p1y - p2y;
- // TODO: Optimize out this {@link FloatMath#sqrt(float)} call.
- return FloatMath.sqrt(dx * dx + dy * dy);
+ private static float getDistance(final int x1, final int y1, final int x2, final int y2) {
+ final float dx = x1 - x2;
+ final float dy = y1 - y2;
+ // Note that, in recent versions of Android, FloatMath is actually slower than
+ // java.lang.Math due to the way the JIT optimizes java.lang.Math.
+ return (float)Math.sqrt(dx * dx + dy * dy);
}
- private static float getAngle(final int p1x, final int p1y, final int p2x, final int p2y) {
- final int dx = p1x - p2x;
- final int dy = p1y - p2y;
+ private static float getAngle(final int x1, final int y1, final int x2, final int y2) {
+ final int dx = x1 - x2;
+ final int dy = y1 - y2;
if (dx == 0 && dy == 0) return 0;
- return (float)Math.atan2(dy, dx);
+ // Would it be faster to call atan2f() directly via JNI? Not sure about what the JIT
+ // does with Math.atan2().
+ return (float)Math.atan2((double)dy, (double)dx);
}
private static float getAngleDiff(final float a1, final float a2) {
@@ -177,12 +169,12 @@ public class GestureStroke {
return diff;
}
- public void drawGestureTrail(Canvas canvas, Paint paint, int lastX, int lastY) {
+ public void drawGestureTrail(final Canvas canvas, final Paint paint) {
// TODO: These paint parameter interpolation should be tunable, possibly introduce an object
// that implements an interface such as Paint getPaint(int step, int strokePoints)
final int size = mXCoordinates.getLength();
- int[] xCoords = mXCoordinates.getPrimitiveArray();
- int[] yCoords = mYCoordinates.getPrimitiveArray();
+ final int[] xCoords = mXCoordinates.getPrimitiveArray();
+ final int[] yCoords = mYCoordinates.getPrimitiveArray();
int alpha = Constants.Color.ALPHA_OPAQUE;
for (int i = size - 1; i > 0 && alpha > 0; i--) {
paint.setAlpha(alpha);
@@ -190,9 +182,6 @@ public class GestureStroke {
alpha -= DRAWING_GESTURE_FADE_RATE;
}
canvas.drawLine(xCoords[i - 1], yCoords[i - 1], xCoords[i], yCoords[i], paint);
- if (i == size - 1) {
- canvas.drawLine(lastX, lastY, xCoords[i], yCoords[i], paint);
- }
}
}
}
diff --git a/java/src/com/android/inputmethod/latin/NativeUtils.java b/java/src/com/android/inputmethod/latin/NativeUtils.java
deleted file mode 100644
index 9cc2bc02e..000000000
--- a/java/src/com/android/inputmethod/latin/NativeUtils.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-package com.android.inputmethod.latin;
-
-public class NativeUtils {
- static {
- JniUtils.loadNativeLibrary();
- }
-
- private NativeUtils() {
- // This utility class is not publicly instantiable.
- }
-
- /**
- * This method just calls up libm's powf() directly.
- */
- public static native float powf(float x, float y);
-}
diff --git a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java
index 1de95d7b8..5a2fdf48e 100644
--- a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java
+++ b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java
@@ -212,7 +212,7 @@ public class UserHistoryForgettingCurveUtils {
for (int j = 0; j < ELAPSED_TIME_MAX; ++j) {
final float elapsedHours = j * ELAPSED_TIME_INTERVAL_HOURS;
final float freq = initialFreq
- * NativeUtils.powf(initialFreq, elapsedHours / HALF_LIFE_HOURS);
+ * (float)Math.pow(initialFreq, elapsedHours / HALF_LIFE_HOURS);
final int intFreq = Math.min(FC_FREQ_MAX, Math.max(0, (int)freq));
SCORE_TABLE[i][j] = intFreq;
}
diff --git a/native/jni/Android.mk b/native/jni/Android.mk
index 86ad8576e..1725a7638 100644
--- a/native/jni/Android.mk
+++ b/native/jni/Android.mk
@@ -37,7 +37,6 @@ LATIN_IME_JNI_SRC_FILES := \
com_android_inputmethod_keyboard_ProximityInfo.cpp \
com_android_inputmethod_latin_BinaryDictionary.cpp \
com_android_inputmethod_latin_DicTraverseSession.cpp \
- com_android_inputmethod_latin_NativeUtils.cpp \
jni_common.cpp
LATIN_IME_CORE_SRC_FILES := \
diff --git a/native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp b/native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp
index f9b23f06d..545d91a70 100644
--- a/native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp
+++ b/native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp
@@ -43,8 +43,8 @@ static void latinime_Keyboard_release(JNIEnv *env, jobject object, jlong proximi
static JNINativeMethod sKeyboardMethods[] = {
{"setProximityInfoNative", "(Ljava/lang/String;IIIIII[II[I[I[I[I[I[F[F[F)J",
- (void*)latinime_Keyboard_setProximityInfo},
- {"releaseProximityInfoNative", "(J)V", (void*)latinime_Keyboard_release}
+ reinterpret_cast<void *>(latinime_Keyboard_setProximityInfo)},
+ {"releaseProximityInfoNative", "(J)V", reinterpret_cast<void *>(latinime_Keyboard_release)}
};
int register_ProximityInfo(JNIEnv *env) {
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index 7e1e0e424..5a287a122 100644
--- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -75,7 +75,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
AKLOGE("DICT: Can't mmap dictionary. errno=%d", errno);
return 0;
}
- dictBuf = (void *)((char *)dictBuf + adjust);
+ dictBuf = reinterpret_cast<void *>(reinterpret_cast<char *>(dictBuf) + adjust);
#else // USE_MMAP_FOR_DICTIONARY
/* malloc version */
FILE *file = 0;
@@ -110,10 +110,11 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
return 0;
}
Dictionary *dictionary = 0;
- if (BinaryFormat::UNKNOWN_FORMAT == BinaryFormat::detectFormat((uint8_t*)dictBuf)) {
+ if (BinaryFormat::UNKNOWN_FORMAT
+ == BinaryFormat::detectFormat(reinterpret_cast<uint8_t *>(dictBuf))) {
AKLOGE("DICT: dictionary format is unknown, bad magic number");
#ifdef USE_MMAP_FOR_DICTIONARY
- releaseDictBuf(((char*)dictBuf) - adjust, adjDictSize, fd);
+ releaseDictBuf(reinterpret_cast<char *>(dictBuf) - adjust, adjDictSize, fd);
#else // USE_MMAP_FOR_DICTIONARY
releaseDictBuf(dictBuf, 0, 0);
#endif // USE_MMAP_FOR_DICTIONARY
@@ -227,8 +228,9 @@ static jfloat latinime_BinaryDictionary_calcNormalizedScore(JNIEnv *env, jobject
jchar afterChars[afterLength];
env->GetCharArrayRegion(before, 0, beforeLength, beforeChars);
env->GetCharArrayRegion(after, 0, afterLength, afterChars);
- return Correction::RankingAlgorithm::calcNormalizedScore((unsigned short*)beforeChars,
- beforeLength, (unsigned short*)afterChars, afterLength, score);
+ return Correction::RankingAlgorithm::calcNormalizedScore(
+ reinterpret_cast<unsigned short *>(beforeChars), beforeLength,
+ reinterpret_cast<unsigned short *>(afterChars), afterLength, score);
}
static jint latinime_BinaryDictionary_editDistance(JNIEnv *env, jobject object,
@@ -239,8 +241,9 @@ static jint latinime_BinaryDictionary_editDistance(JNIEnv *env, jobject object,
jchar afterChars[afterLength];
env->GetCharArrayRegion(before, 0, beforeLength, beforeChars);
env->GetCharArrayRegion(after, 0, afterLength, afterChars);
- return Correction::RankingAlgorithm::editDistance((unsigned short*)beforeChars, beforeLength,
- (unsigned short*)afterChars, afterLength);
+ return Correction::RankingAlgorithm::editDistance(
+ reinterpret_cast<unsigned short *>(beforeChars), beforeLength,
+ reinterpret_cast<unsigned short *>(afterChars), afterLength);
}
static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong dict) {
@@ -249,7 +252,9 @@ static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong d
void *dictBuf = dictionary->getDict();
if (!dictBuf) return;
#ifdef USE_MMAP_FOR_DICTIONARY
- releaseDictBuf((void *)((char *)dictBuf - dictionary->getDictBufAdjust()),
+ releaseDictBuf(
+ reinterpret_cast<void *>(
+ reinterpret_cast<char *>(dictBuf) - dictionary->getDictBufAdjust()),
dictionary->getDictSize() + dictionary->getDictBufAdjust(), dictionary->getMmapFd());
#else // USE_MMAP_FOR_DICTIONARY
releaseDictBuf(dictBuf, 0, 0);
@@ -273,15 +278,19 @@ static void releaseDictBuf(void *dictBuf, const size_t length, int fd) {
}
static JNINativeMethod sMethods[] = {
- {"openNative", "(Ljava/lang/String;JJIIIII)J", (void*)latinime_BinaryDictionary_open},
- {"closeNative", "(J)V", (void*)latinime_BinaryDictionary_close},
+ {"openNative", "(Ljava/lang/String;JJIIIII)J",
+ reinterpret_cast<void *>(latinime_BinaryDictionary_open)},
+ {"closeNative", "(J)V", reinterpret_cast<void *>(latinime_BinaryDictionary_close)},
{"getSuggestionsNative", "(JJJ[I[I[I[I[IIIZ[IZ[C[I[I[I)I",
- (void*) latinime_BinaryDictionary_getSuggestions},
- {"getFrequencyNative", "(J[I)I", (void*)latinime_BinaryDictionary_getFrequency},
- {"isValidBigramNative", "(J[I[I)Z", (void*)latinime_BinaryDictionary_isValidBigram},
+ reinterpret_cast<void *>(latinime_BinaryDictionary_getSuggestions)},
+ {"getFrequencyNative", "(J[I)I",
+ reinterpret_cast<void *>(latinime_BinaryDictionary_getFrequency)},
+ {"isValidBigramNative", "(J[I[I)Z",
+ reinterpret_cast<void *>(latinime_BinaryDictionary_isValidBigram)},
{"calcNormalizedScoreNative", "([C[CI)F",
- (void*)latinime_BinaryDictionary_calcNormalizedScore},
- {"editDistanceNative", "([C[C)I", (void*)latinime_BinaryDictionary_editDistance}
+ reinterpret_cast<void *>(latinime_BinaryDictionary_calcNormalizedScore)},
+ {"editDistanceNative", "([C[C)I",
+ reinterpret_cast<void *>(latinime_BinaryDictionary_editDistance)}
};
int register_BinaryDictionary(JNIEnv *env) {
diff --git a/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp b/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp
index 806ff1f1d..947360e8e 100644
--- a/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp
+++ b/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp
@@ -41,16 +41,18 @@ static void latinime_initDicTraverseSession(JNIEnv *env, jobject object, jlong t
DicTraverseWrapper::initDicTraverseSession(ts, dict, prevWord, previousWordLength);
}
-static void latinime_releaseDicTraverseSession(
- JNIEnv *env, jobject object, jlong traverseSession) {
+static void latinime_releaseDicTraverseSession(JNIEnv *env, jobject object, jlong traverseSession) {
void *ts = reinterpret_cast<void*>(traverseSession);
DicTraverseWrapper::releaseDicTraverseSession(ts);
}
static JNINativeMethod sMethods[] = {
- {"setDicTraverseSessionNative", "(Ljava/lang/String;)J", (void*)latinime_setDicTraverseSession},
- {"initDicTraverseSessionNative", "(JJ[II)V", (void*)latinime_initDicTraverseSession},
- {"releaseDicTraverseSessionNative", "(J)V", (void*)latinime_releaseDicTraverseSession}
+ {"setDicTraverseSessionNative", "(Ljava/lang/String;)J",
+ reinterpret_cast<void *>(latinime_setDicTraverseSession)},
+ {"initDicTraverseSessionNative", "(JJ[II)V",
+ reinterpret_cast<void *>(latinime_initDicTraverseSession)},
+ {"releaseDicTraverseSessionNative", "(J)V",
+ reinterpret_cast<void *>(latinime_releaseDicTraverseSession)}
};
int register_DicTraverseSession(JNIEnv *env) {
diff --git a/native/jni/com_android_inputmethod_latin_NativeUtils.cpp b/native/jni/com_android_inputmethod_latin_NativeUtils.cpp
deleted file mode 100644
index 8f1afbeb6..000000000
--- a/native/jni/com_android_inputmethod_latin_NativeUtils.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2012, 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.
- */
-
-#include "com_android_inputmethod_latin_NativeUtils.h"
-#include "jni.h"
-#include "jni_common.h"
-
-#include <cmath>
-
-namespace latinime {
-
-static float latinime_NativeUtils_powf(float x, float y) {
- return powf(x, y);
-}
-
-static JNINativeMethod sMethods[] = {
- {"powf", "(FF)F", (void*)latinime_NativeUtils_powf}
-};
-
-int register_NativeUtils(JNIEnv *env) {
- const char *const kClassPathName = "com/android/inputmethod/latin/NativeUtils";
- return registerNativeMethods(env, kClassPathName, sMethods,
- sizeof(sMethods) / sizeof(sMethods[0]));
-}
-} // namespace latinime
diff --git a/native/jni/com_android_inputmethod_latin_NativeUtils.h b/native/jni/com_android_inputmethod_latin_NativeUtils.h
deleted file mode 100644
index d1ffb8f4a..000000000
--- a/native/jni/com_android_inputmethod_latin_NativeUtils.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2012, 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 _COM_ANDROID_INPUTMETHOD_LATIN_NATIVEUTILS_H
-#define _COM_ANDROID_INPUTMETHOD_LATIN_NATIVEUTILS_H
-
-#include "jni.h"
-
-namespace latinime {
-
-int register_NativeUtils(JNIEnv *env);
-
-} // namespace latinime
-#endif // _COM_ANDROID_INPUTMETHOD_LATIN_NATIVEUTILS_H
diff --git a/native/jni/jni_common.cpp b/native/jni/jni_common.cpp
index 795262aa4..1586f253b 100644
--- a/native/jni/jni_common.cpp
+++ b/native/jni/jni_common.cpp
@@ -21,7 +21,6 @@
#include "com_android_inputmethod_keyboard_ProximityInfo.h"
#include "com_android_inputmethod_latin_BinaryDictionary.h"
#include "com_android_inputmethod_latin_DicTraverseSession.h"
-#include "com_android_inputmethod_latin_NativeUtils.h"
#include "defines.h"
#include "jni.h"
#include "jni_common.h"
@@ -56,11 +55,6 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
goto bail;
}
- if (!register_NativeUtils(env)) {
- AKLOGE("ERROR: NativeUtils native registration failed");
- goto bail;
- }
-
/* success -- return valid version number */
result = JNI_VERSION_1_6;
diff --git a/native/jni/src/bigram_dictionary.cpp b/native/jni/src/bigram_dictionary.cpp
index 220171127..df1ebc0e3 100644
--- a/native/jni/src/bigram_dictionary.cpp
+++ b/native/jni/src/bigram_dictionary.cpp
@@ -60,14 +60,15 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
AKLOGI("Bigram: InsertAt -> %d MAX_PREDICTIONS: %d", insertAt, MAX_PREDICTIONS);
}
if (insertAt < MAX_PREDICTIONS) {
- memmove((char*) bigramFreq + (insertAt + 1) * sizeof(bigramFreq[0]),
- (char*) bigramFreq + insertAt * sizeof(bigramFreq[0]),
- (MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0]));
+ memmove(reinterpret_cast<char *>(bigramFreq) + (insertAt + 1) * sizeof(bigramFreq[0]),
+ reinterpret_cast<char *>(bigramFreq) + insertAt * sizeof(bigramFreq[0]),
+ (MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0]));
bigramFreq[insertAt] = frequency;
outputTypes[insertAt] = Dictionary::KIND_PREDICTION;
- memmove((char*) bigramChars + (insertAt + 1) * MAX_WORD_LENGTH * sizeof(short),
- (char*) bigramChars + (insertAt ) * MAX_WORD_LENGTH * sizeof(short),
- (MAX_PREDICTIONS - insertAt - 1) * sizeof(short) * MAX_WORD_LENGTH);
+ memmove(reinterpret_cast<char *>(bigramChars)
+ + (insertAt + 1) * MAX_WORD_LENGTH * sizeof(short),
+ reinterpret_cast<char *>(bigramChars) + insertAt * MAX_WORD_LENGTH * sizeof(short),
+ (MAX_PREDICTIONS - insertAt - 1) * sizeof(short) * MAX_WORD_LENGTH);
unsigned short *dest = bigramChars + (insertAt ) * MAX_WORD_LENGTH;
while (length--) {
*dest++ = *word++;
diff --git a/native/jni/src/char_utils.cpp b/native/jni/src/char_utils.cpp
index 45d49b087..fc0a0596f 100644
--- a/native/jni/src/char_utils.cpp
+++ b/native/jni/src/char_utils.cpp
@@ -885,16 +885,17 @@ static const struct LatinCapitalSmallPair SORTED_CHAR_MAP[] = {
};
static int compare_pair_capital(const void *a, const void *b) {
- return (int)(*(unsigned short *)a)
- - (int)((struct LatinCapitalSmallPair*)b)->capital;
+ return static_cast<int>(*reinterpret_cast<const unsigned short *>(a))
+ - static_cast<int>(
+ (reinterpret_cast<const struct LatinCapitalSmallPair *>(b))->capital);
}
unsigned short latin_tolower(unsigned short c) {
struct LatinCapitalSmallPair *p =
- (struct LatinCapitalSmallPair *)bsearch(&c, SORTED_CHAR_MAP,
+ reinterpret_cast<struct LatinCapitalSmallPair *>(bsearch(&c, SORTED_CHAR_MAP,
sizeof(SORTED_CHAR_MAP) / sizeof(SORTED_CHAR_MAP[0]),
sizeof(SORTED_CHAR_MAP[0]),
- compare_pair_capital);
+ compare_pair_capital));
return p ? p->small : c;
}
} // namespace latinime
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp
index c815dabe6..e55da0113 100644
--- a/native/jni/src/correction.cpp
+++ b/native/jni/src/correction.cpp
@@ -1096,7 +1096,7 @@ int Correction::RankingAlgorithm::editDistance(const unsigned short *before,
// In dictionary.cpp, getSuggestion() method,
// suggestion scores are computed using the below formula.
// original score
-// := pow(mTypedLetterMultiplier (this is defined 2),
+// := powf(mTypedLetterMultiplier (this is defined 2),
// (the number of matched characters between typed word and suggested word))
// * (individual word's score which defined in the unigram dictionary,
// and this score is defined in range [0, 255].)
@@ -1108,11 +1108,11 @@ int Correction::RankingAlgorithm::editDistance(const unsigned short *before,
// capitalization, then treat it as if the score was 255.
// - If before.length() == after.length()
// => multiply by mFullWordMultiplier (this is defined 2))
-// So, maximum original score is pow(2, min(before.length(), after.length())) * 255 * 2 * 1.2
+// So, maximum original score is powf(2, min(before.length(), after.length())) * 255 * 2 * 1.2
// For historical reasons we ignore the 1.2 modifier (because the measure for a good
// autocorrection threshold was done at a time when it didn't exist). This doesn't change
// the result.
-// So, we can normalize original score by dividing pow(2, min(b.l(),a.l())) * 255 * 2.
+// So, we can normalize original score by dividing powf(2, min(b.l(),a.l())) * 255 * 2.
/* static */
float Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short *before,
@@ -1134,7 +1134,7 @@ float Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short *be
}
const float maxScore = score >= S_INT_MAX ? S_INT_MAX : MAX_INITIAL_SCORE
- * pow(static_cast<float>(TYPED_LETTER_MULTIPLIER),
+ * powf(static_cast<float>(TYPED_LETTER_MULTIPLIER),
static_cast<float>(min(beforeLength, afterLength - spaceCount)))
* FULL_WORD_MULTIPLIER;
diff --git a/native/jni/src/debug.h b/native/jni/src/debug.h
index 2168d6672..2432b1f2e 100644
--- a/native/jni/src/debug.h
+++ b/native/jni/src/debug.h
@@ -58,11 +58,12 @@ static inline void LOGI_S16_PLUS(unsigned short *string, const unsigned int leng
}
static inline void printDebug(const char *tag, int *codes, int codesSize, int MAX_PROXIMITY_CHARS) {
- unsigned char *buf = (unsigned char*)malloc((1 + codesSize) * sizeof(*buf));
+ unsigned char *buf = reinterpret_cast<unsigned char *>(malloc((1 + codesSize) * sizeof(*buf)));
buf[codesSize] = 0;
- while (--codesSize >= 0)
- buf[codesSize] = (unsigned char)codes[codesSize * MAX_PROXIMITY_CHARS];
+ while (--codesSize >= 0) {
+ buf[codesSize] = static_cast<unsigned char>(codes[codesSize * MAX_PROXIMITY_CHARS]);
+ }
AKLOGI("%s, WORD = %s", tag, buf);
free(buf);
diff --git a/native/jni/src/dictionary.cpp b/native/jni/src/dictionary.cpp
index f3bdb310d..9e4bd15a9 100644
--- a/native/jni/src/dictionary.cpp
+++ b/native/jni/src/dictionary.cpp
@@ -32,8 +32,8 @@ namespace latinime {
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
int typedLetterMultiplier, int fullWordMultiplier,
int maxWordLength, int maxWords, int maxPredictions)
- : mDict((unsigned char*) dict),
- mOffsetDict(((unsigned char*) dict) + BinaryFormat::getHeaderSize(mDict)),
+ : mDict(reinterpret_cast<unsigned char *>(dict)),
+ mOffsetDict((reinterpret_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) {
if (DEBUG_DICT) {
if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {
@@ -47,8 +47,6 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
fullWordMultiplier, maxWordLength, maxWords, options);
mBigramDictionary = new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions);
mGestureDecoder = new GestureDecoderWrapper(maxWordLength, maxWords);
- mGestureDecoder->setDict(mUnigramDictionary, mBigramDictionary,
- mOffsetDict /* dict root */, 0 /* root pos */);
}
Dictionary::~Dictionary() {
diff --git a/native/jni/src/dictionary.h b/native/jni/src/dictionary.h
index b550ba4df..3b55e5de9 100644
--- a/native/jni/src/dictionary.h
+++ b/native/jni/src/dictionary.h
@@ -55,8 +55,12 @@ class Dictionary {
int getFrequency(const int32_t *word, int length) const;
bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const;
- void *getDict() const { return (void *)mDict; } // required to release dictionary buffer
- void *getOffsetDict() const { return (void *)mOffsetDict; }
+ void *getDict() const { // required to release dictionary buffer
+ return reinterpret_cast<void *>(const_cast<unsigned char *>(mDict));
+ }
+ void *getOffsetDict() const {
+ return reinterpret_cast<void *>(const_cast<unsigned char *>(mOffsetDict));
+ }
int getDictSize() const { return mDictSize; }
int getMmapFd() const { return mMmapFd; }
int getDictBufAdjust() const { return mDictBufAdjust; }
@@ -87,8 +91,9 @@ class Dictionary {
inline int Dictionary::wideStrLen(unsigned short *str) {
if (!str) return 0;
unsigned short *end = str;
- while (*end)
+ while (*end) {
end++;
+ }
return end - str;
}
} // namespace latinime
diff --git a/native/jni/src/geometry_utils.h b/native/jni/src/geometry_utils.h
index ada889e11..deb042525 100644
--- a/native/jni/src/geometry_utils.h
+++ b/native/jni/src/geometry_utils.h
@@ -14,88 +14,90 @@
* limitations under the License.
*/
-#ifndef LATINIME_INCREMENTAL_GEOMETRY_UTILS_H
-#define LATINIME_INCREMENTAL_GEOMETRY_UTILS_H
+#ifndef LATINIME_GEOMETRY_UTILS_H
+#define LATINIME_GEOMETRY_UTILS_H
#include <cmath>
#define MAX_DISTANCE 10000000
-#define KEY_NUM 27
-#define SPACE_KEY 26
#define MAX_PATHS 2
#define DEBUG_DECODER false
+#define M_PI_F 3.14159265f
+
namespace latinime {
-static inline float sqr(float x) {
+static inline float squareFloat(float x) {
return x * x;
}
-static inline float getNormalizedSqrDistance(int x1, int y1, int x2, int y2, int scale) {
- return sqr((x1 - x2) * 1.0 / scale) + sqr((y1 - y2) * 1.0 / scale);
+static inline float getNormalizedSquaredDistanceFloat(float x1, float y1, float x2, float y2,
+ float scale) {
+ return squareFloat((x1 - x2) / scale) + squareFloat((y1 - y2) / scale);
+}
+
+static inline float getSquaredDistanceFloat(float x1, float y1, float x2, float y2) {
+ return squareFloat(x1 - x2) + squareFloat(y1 - y2);
}
-static inline int getDistance(int x1, int y1, int x2, int y2) {
- return (int) sqrt(sqr(x2 - x1) + sqr(y2 - y1));
+static inline float getDistanceFloat(float x1, float y1, float x2, float y2) {
+ return hypotf(x1 - x2, y1 - y2);
}
-static inline float getDistanceSq(float x1, float y1, float x2, float y2) {
- return sqr(x2 - x1) + sqr(y2 - y1);
+static inline int getDistanceInt(int x1, int y1, int x2, int y2) {
+ return static_cast<int>(getDistanceFloat(static_cast<float>(x1), static_cast<float>(y1),
+ static_cast<float>(x2), static_cast<float>(y2)));
}
static inline float getAngle(int x1, int y1, int x2, int y2) {
- float dx = x1 - x2;
- float dy = y1 - y2;
- if (dx == 0 && dy == 0)
- return 0;
- return atan2(dy, dx);
+ const int dx = x1 - x2;
+ const int dy = y1 - y2;
+ if (dx == 0 && dy == 0) return 0;
+ return atan2f(static_cast<float>(dy), static_cast<float>(dx));
}
-static inline float angleDiff(float a1, float a2) {
- float diff = a1 - a2;
- if (diff < 0) {
- diff = -diff;
- }
- if (diff > M_PI) {
- return 2 * M_PI - diff;
+static inline float getAngleDiff(float a1, float a2) {
+ const float diff = fabsf(a1 - a2);
+ if (diff > M_PI_F) {
+ return 2.0f * M_PI_F - diff;
}
return diff;
}
-//static float pointToLineDistanceSq(float x, float y, float x1, float y1, float x2, float y2) {
-// float A = x - x1;
-// float B = y - y1;
-// float C = x2 - x1;
-// float D = y2 - y1;
-// return abs(A * D - C * B) / sqrt(C * C + D * D);
-//}
+// static float pointToLineSegSquaredDistanceFloat(
+// float x, float y, float x1, float y1, float x2, float y2) {
+// float A = x - x1;
+// float B = y - y1;
+// float C = x2 - x1;
+// float D = y2 - y1;
+// return fabsf(A * D - C * B) / sqrtf(C * C + D * D);
+// }
-static inline float pointToLineSegDistanceSq(
+static inline float pointToLineSegSquaredDistanceFloat(
float x, float y, float x1, float y1, float x2, float y2) {
- float ray1x = x - x1;
- float ray1y = y - y1;
- float ray2x = x2 - x1;
- float ray2y = y2 - y1;
-
- float dotProduct = ray1x * ray2x + ray1y * ray2y;
- float lineLengthSq = ray2x * ray2x + ray2y * ray2y;
- float projectionLengthSq = dotProduct / lineLengthSq;
-
- float projectionX, projectionY;
- if (projectionLengthSq < 0) {
+ const float ray1x = x - x1;
+ const float ray1y = y - y1;
+ const float ray2x = x2 - x1;
+ const float ray2y = y2 - y1;
+
+ const float dotProduct = ray1x * ray2x + ray1y * ray2y;
+ const float lineLengthSqr = squareFloat(ray2x) + squareFloat(ray2y);
+ const float projectionLengthSqr = dotProduct / lineLengthSqr;
+
+ float projectionX;
+ float projectionY;
+ if (projectionLengthSqr < 0.0f) {
projectionX = x1;
projectionY = y1;
- } else if (projectionLengthSq > 1) {
+ } else if (projectionLengthSqr > 1.0f) {
projectionX = x2;
projectionY = y2;
} else {
- projectionX = x1 + projectionLengthSq * ray2x;
- projectionY = y1 + projectionLengthSq * ray2y;
+ projectionX = x1 + projectionLengthSqr * ray2x;
+ projectionY = y1 + projectionLengthSqr * ray2y;
}
-
- float dist = getDistanceSq(x, y, projectionX, projectionY);
- return dist;
+ return getSquaredDistanceFloat(x, y, projectionX, projectionY);
}
} // namespace latinime
-#endif // LATINIME_INCREMENTAL_GEOMETRY_UTILS_H
+#endif // LATINIME_GEOMETRY_UTILS_H
diff --git a/native/jni/src/gesture/gesture_decoder_wrapper.h b/native/jni/src/gesture/gesture_decoder_wrapper.h
index 2b9054f70..f8bfe7c79 100644
--- a/native/jni/src/gesture/gesture_decoder_wrapper.h
+++ b/native/jni/src/gesture/gesture_decoder_wrapper.h
@@ -48,21 +48,13 @@ class GestureDecoderWrapper : public IncrementalDecoderInterface {
inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
}
- void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram,
- const uint8_t *dictRoot, int rootPos) {
- if (!mIncrementalDecoderInterface) {
- return;
- }
- mIncrementalDecoderInterface->setDict(dict, bigram, dictRoot, rootPos);
- }
-
static void setGestureDecoderFactoryMethod(
IncrementalDecoderInterface *(*factoryMethod)(int, int)) {
sGestureDecoderFactoryMethod = factoryMethod;
}
private:
- DISALLOW_COPY_AND_ASSIGN(GestureDecoderWrapper);
+ DISALLOW_IMPLICIT_CONSTRUCTORS(GestureDecoderWrapper);
static IncrementalDecoderInterface *getGestureDecoderInstance(int maxWordLength, int maxWords) {
if (sGestureDecoderFactoryMethod) {
return sGestureDecoderFactoryMethod(maxWordLength, maxWords);
diff --git a/native/jni/src/gesture/incremental_decoder_interface.h b/native/jni/src/gesture/incremental_decoder_interface.h
index 3951514c0..04f0095e0 100644
--- a/native/jni/src/gesture/incremental_decoder_interface.h
+++ b/native/jni/src/gesture/incremental_decoder_interface.h
@@ -32,11 +32,10 @@ class IncrementalDecoderInterface {
int *inputXs, int *inputYs, int *times, int *pointerIds, int *codes,
int inputSize, int commitPoint, unsigned short *outWords, int *frequencies,
int *outputIndices, int *outputTypes) = 0;
- virtual void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram,
- const uint8_t *dictRoot, int rootPos) = 0;
+ IncrementalDecoderInterface() { };
virtual ~IncrementalDecoderInterface() { };
private:
- //DISALLOW_COPY_AND_ASSIGN(IncrementalDecoderInterface);
+ DISALLOW_COPY_AND_ASSIGN(IncrementalDecoderInterface);
};
} // namespace latinime
#endif // LATINIME_INCREMENTAL_DECODER_INTERFACE_H
diff --git a/native/jni/src/gesture/incremental_decoder_wrapper.h b/native/jni/src/gesture/incremental_decoder_wrapper.h
index 477b2cc8a..5cb2ee368 100644
--- a/native/jni/src/gesture/incremental_decoder_wrapper.h
+++ b/native/jni/src/gesture/incremental_decoder_wrapper.h
@@ -48,21 +48,13 @@ class IncrementalDecoderWrapper : public IncrementalDecoderInterface {
inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
}
- void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram,
- const uint8_t *dictRoot, int rootPos) {
- if (!mIncrementalDecoderInterface) {
- return;
- }
- mIncrementalDecoderInterface->setDict(dict, bigram, dictRoot, rootPos);
- }
-
static void setIncrementalDecoderFactoryMethod(
IncrementalDecoderInterface *(*factoryMethod)(int, int)) {
sIncrementalDecoderFactoryMethod = factoryMethod;
}
private:
- DISALLOW_COPY_AND_ASSIGN(IncrementalDecoderWrapper);
+ DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalDecoderWrapper);
static IncrementalDecoderInterface *getIncrementalDecoderInstance(int maxWordLength,
int maxWords) {
if (sIncrementalDecoderFactoryMethod) {
diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp
index 18a0b74a8..ade78a1ec 100644
--- a/native/jni/src/proximity_info.cpp
+++ b/native/jni/src/proximity_info.cpp
@@ -248,7 +248,7 @@ void ProximityInfo::initializeG() {
for (int i = 0; i < KEY_COUNT; i++) {
mKeyKeyDistancesG[i][i] = 0;
for (int j = i + 1; j < KEY_COUNT; j++) {
- mKeyKeyDistancesG[i][j] = getDistance(
+ mKeyKeyDistancesG[i][j] = getDistanceInt(
mCenterXsG[i], mCenterYsG[i], mCenterXsG[j], mCenterYsG[j]);
mKeyKeyDistancesG[j][i] = mKeyKeyDistancesG[i][j];
}
@@ -290,7 +290,7 @@ int ProximityInfo::getKeyKeyDistanceG(int key0, int key1) const {
void ProximityInfo::getCenters(int *centerXs, int *centerYs, int *codeToKeyIndex,
int *keyToCodeIndex, int *keyCount, int *keyWidth) const {
*keyCount = KEY_COUNT;
- *keyWidth = sqrt(static_cast<float>(MOST_COMMON_KEY_WIDTH_SQUARE));
+ *keyWidth = sqrtf(static_cast<float>(MOST_COMMON_KEY_WIDTH_SQUARE));
for (int i = 0; i < KEY_COUNT; ++i) {
const int code = mKeyCharCodes[i];
diff --git a/native/jni/src/words_priority_queue.h b/native/jni/src/words_priority_queue.h
index 8a6da1c95..e97e16a12 100644
--- a/native/jni/src/words_priority_queue.h
+++ b/native/jni/src/words_priority_queue.h
@@ -129,7 +129,7 @@ class WordsPriorityQueue {
}
}
if (maxIndex > 0 && nsMaxSw) {
- memmove(&swBuffer[1], &swBuffer[0], maxIndex * sizeof(SuggestedWord*));
+ memmove(&swBuffer[1], &swBuffer[0], maxIndex * sizeof(SuggestedWord *));
swBuffer[0] = nsMaxSw;
}
}
@@ -140,12 +140,13 @@ class WordsPriorityQueue {
continue;
}
const unsigned int wordLength = sw->mWordLength;
- char *targetAdr = (char*) outputChars + i * MAX_WORD_LENGTH * sizeof(short);
+ char *targetAddress = reinterpret_cast<char *>(outputChars)
+ + i * MAX_WORD_LENGTH * sizeof(short);
frequencies[i] = sw->mScore;
outputTypes[i] = sw->mType;
- memcpy(targetAdr, sw->mWord, (wordLength) * sizeof(short));
+ memcpy(targetAddress, sw->mWord, (wordLength) * sizeof(short));
if (wordLength < MAX_WORD_LENGTH) {
- ((unsigned short*) targetAdr)[wordLength] = 0;
+ reinterpret_cast<unsigned short *>(targetAddress)[wordLength] = 0;
}
sw->mUsed = false;
}