Pre-compute for square of threshold and scale to lessen computation
This commit is contained in:
parent
5df590f172
commit
fa92b8a56b
@ -113,7 +113,7 @@ const char* const command_map[] = {
|
|||||||
|
|
||||||
struct swipe_gesture_impl : swipe_gesture {
|
struct swipe_gesture_impl : swipe_gesture {
|
||||||
int screen_num, ix, iy;
|
int screen_num, ix, iy;
|
||||||
float x, y, threshold;
|
float x, y, threshold_squared;
|
||||||
int previous_gesture;
|
int previous_gesture;
|
||||||
const char** commands;
|
const char** commands;
|
||||||
swipe_gesture_impl(
|
swipe_gesture_impl(
|
||||||
@ -126,7 +126,7 @@ struct swipe_gesture_impl : swipe_gesture {
|
|||||||
const char* up4 /* 101 */,
|
const char* up4 /* 101 */,
|
||||||
const char* down3 /* 110 */,
|
const char* down3 /* 110 */,
|
||||||
const char* down4 /* 111 */
|
const char* down4 /* 111 */
|
||||||
): swipe_gesture(), threshold(threshold) {
|
): swipe_gesture(), threshold_squared(threshold*threshold) {
|
||||||
commands = new const char*[8];
|
commands = new const char*[8];
|
||||||
commands[0] = left3;
|
commands[0] = left3;
|
||||||
commands[1] = left4;
|
commands[1] = left4;
|
||||||
@ -153,10 +153,10 @@ struct swipe_gesture_impl : swipe_gesture {
|
|||||||
x += stof(dx);
|
x += stof(dx);
|
||||||
y += stof(dy);
|
y += stof(dy);
|
||||||
// scale threshold to 1/10 when gesture is not fresh
|
// scale threshold to 1/10 when gesture is not fresh
|
||||||
float scale = previous_gesture == FRESH ?
|
float scale = previous_gesture == FRESH
|
||||||
1.0f :
|
? 1.00f
|
||||||
0.1f;
|
: 0.01f; // square root of 1/10
|
||||||
if (x*x + y*y > threshold*threshold*(scale*scale)) {
|
if (x*x + y*y > threshold_squared*scale) {
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
if (fingers == "3") mask |= MSK_THREE_FINGERS; else
|
if (fingers == "3") mask |= MSK_THREE_FINGERS; else
|
||||||
if (fingers == "4") mask |= MSK_FOUR_FINGERS;
|
if (fingers == "4") mask |= MSK_FOUR_FINGERS;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user