diff options
author | Henrik Rydberg <rydberg@euromail.se> | 2010-03-20 14:18:16 +0100 |
---|---|---|
committer | Henrik Rydberg <rydberg@euromail.se> | 2010-03-21 14:56:15 +0100 |
commit | e9dcbeaba956e84d1e591e9b520f3b7bb4fa6354 (patch) | |
tree | 19b4d548127766862a79f5521f75a590b90090b1 /src | |
parent | ea6cfa421b7cef91eba85c5144eec14288c41c4c (diff) | |
download | xorg-input-kobomultitouch-e9dcbeaba956e84d1e591e9b520f3b7bb4fa6354.tar.gz xorg-input-kobomultitouch-e9dcbeaba956e84d1e591e9b520f3b7bb4fa6354.tar.bz2 xorg-input-kobomultitouch-e9dcbeaba956e84d1e591e9b520f3b7bb4fa6354.zip |
Matcher: convert distance matrix to integer
In order to reduce the requirements on the cpu environment running
the matcher, the floating-point operations are converted to integer.
Care is taken as to not overflow the distance matrix.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
-rw-r--r-- | src/state.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/state.c b/src/state.c index 5387828..895d096 100644 --- a/src/state.c +++ b/src/state.c @@ -36,10 +36,23 @@ static int fincmp(const void *a, const void *b) return ((struct FingerState *)a)->id - ((struct FingerState *)b)->id; } -inline float dist2(const struct FingerData *a, const struct FingerData *b) +/* seander@cs.stanford.edu */ +inline unsigned abs32(int x) { - float dx = a->position_x - b->position_x; - float dy = a->position_y - b->position_y; + int const m = x >> 31; + return (x + m) ^ m; +} + +inline int abs15(int x) +{ + return 32767 & abs32(x); +} + +/* abslute scale is assumed to fit in 15 bits */ +inline int dist2(const struct FingerData *a, const struct FingerData *b) +{ + int dx = abs15(a->position_x - b->position_x); + int dy = abs15(a->position_y - b->position_y); return dx * dx + dy * dy; } @@ -71,7 +84,7 @@ void modify_state(struct State *s, const struct HWData *hw, const struct Capabilities *caps) { - float A[DIM2_FINGER], *row; + int A[DIM2_FINGER], *row; int sid[DIM_FINGER], hw2s[DIM_FINGER]; int id, sk, hwk; |