From 37b153e205c9672b299b47e97921fee2462a78bb Mon Sep 17 00:00:00 2001
From: Satoshi Kataoka <satok@google.com>
Date: Mon, 27 Aug 2012 14:39:17 +0900
Subject: [PATCH] Step 40-A Cleanup touch path

Change-Id: Id22c5ae6afbf040227dc47153b0849bbe38ff66f
---
 native/jni/src/proximity_info_state.cpp | 16 +++++++++-------
 native/jni/src/proximity_info_state.h   | 18 +++++++++++++++++-
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index 897ad46c40..f01b81e8d1 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -84,12 +84,13 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
             // Assuming pointerId == 0 if pointerIds is null.
             const int pid = pointerIds ? pointerIds[i] : 0;
             if (pointerId == pid) {
-                ++mInputSize;
                 const int c = isGeometric ? NOT_A_COORDINATE : getPrimaryCharAt(i);
                 const int x = proximityOnly ? NOT_A_COORDINATE : xCoordinates[i];
                 const int y = proximityOnly ? NOT_A_COORDINATE : yCoordinates[i];
                 const int time = times ? times[i] : -1;
-                pushTouchPoint(c, x, y, time, isGeometric);
+                if (pushTouchPoint(c, x, y, time, isGeometric)) {
+                    ++mInputSize;
+                }
             }
         }
     }
@@ -152,7 +153,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
     }
 }
 
-void ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y,
+bool ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y,
         const int time, const bool sample) {
     const uint32_t size = mInputXs.size();
     // TODO: Should have a const variable for 10
@@ -160,7 +161,7 @@ void ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y,
     if (size > 0) {
         const int dist = getDistanceInt(x, y, mInputXs[size - 1], mInputYs[size - 1]);
         if (sample && dist < sampleRate) {
-            return;
+            return false;
         }
         mLengthCache.push_back(mLengthCache[size - 1] + dist);
     } else {
@@ -176,6 +177,7 @@ void ProximityInfoState::pushTouchPoint(const int nodeChar, int x, int y,
     mInputXs.push_back(x);
     mInputYs.push_back(y);
     mTimes.push_back(time);
+    return true;
 }
 
 float ProximityInfoState::calculateNormalizedSquaredDistance(
@@ -196,10 +198,10 @@ float ProximityInfoState::calculateNormalizedSquaredDistance(
 }
 
 int ProximityInfoState::getDuration(const int index) const {
-    if (mTimes.size() == 0 || index <= 0 || index >= static_cast<int>(mInputSize) - 1) {
-        return 0;
+    if (mInputSize > 0 && index > 0 && index < static_cast<int>(mInputSize) - 1) {
+        return mTimes[index + 1] - mTimes[index - 1];
     }
-    return mTimes[index + 1] - mTimes[index - 1];
+    return 0;
 }
 
 float ProximityInfoState::getPointToKeyLength(int inputIndex, int charCode, float scale) {
diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h
index 13b080705c..26fd89b366 100644
--- a/native/jni/src/proximity_info_state.h
+++ b/native/jni/src/proximity_info_state.h
@@ -192,6 +192,22 @@ class ProximityInfoState {
         return mInputSize > 0;
     }
 
+    uint32_t size() const {
+        return mInputSize;
+    }
+
+    int getInputX(int index) const {
+        return mInputXs[index];
+    }
+
+    int getInputY(int index) const {
+        return mInputYs[index];
+    }
+
+    int getLengthCache(int index) const {
+        return mLengthCache[index];
+    }
+
     float getPointToKeyLength(int inputIndex, int charCode, float scale);
 
     int getKeyKeyDistance(int key0, int key1);
@@ -208,7 +224,7 @@ class ProximityInfoState {
     float calculateSquaredDistanceFromSweetSpotCenter(
             const int keyIndex, const int inputIndex) const;
 
-    void pushTouchPoint(const int nodeChar, int x, int y, const int time, const bool sample);
+    bool pushTouchPoint(const int nodeChar, int x, int y, const int time, const bool sample);
     /////////////////////////////////////////
     // Defined here                        //
     /////////////////////////////////////////
-- 
GitLab