Skip to content
Snippets Groups Projects
Commit 7aea41ee authored by Aleksandras Kostarevas's avatar Aleksandras Kostarevas
Browse files

Add decomposeTapPosition fallback for nonintersecting cases

parent 5e0722c9
No related branches found
No related tags found
1 merge request!7Merge model-metadata to master
......@@ -147,6 +147,7 @@ class ProximityInfo {
float tapRadius = MOST_COMMON_KEY_WIDTH / 1.33f;
float totalArea = M_PI * ((float)(tapRadius * tapRadius));
bool anySet = false;
for(int key = 0; key < KEY_COUNT; key++) {
const int left = mKeyXCoordinates[key];
const int top = mKeyYCoordinates[key];
......@@ -154,6 +155,33 @@ class ProximityInfo {
const int bottom = top + mKeyHeights[key];
percentages[key] = insmat::area(left, right, bottom, top, tapX, tapY, tapRadius) / totalArea;
if(percentages[key] > 0.05f) {
anySet = true;
}
}
if(!anySet) {
// Fallback - have to pick the closest key
AKLOGE("FALLBACK - Have to pick closest key");
int closestKey = -1;
int minDistance = 1000000;
for(int key = 0; key < KEY_COUNT; key++) {
const int keyX = mKeyXCoordinates[key];
const int keyY = mKeyYCoordinates[key];
const int distance = (keyX - tapX) * (keyX - tapX) + (keyY - tapY) * (keyY - tapY);
if(distance < minDistance) {
minDistance = distance;
closestKey = key;
}
}
if(closestKey != -1) {
percentages[closestKey] = 1.0f;
} else {
AKLOGE("Failed to find even the closest key!");
}
}
return percentages;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment