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/state.c | |
| parent | ea6cfa421b7cef91eba85c5144eec14288c41c4c (diff) | |
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/state.c')
| -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) | |||
| 36 | return ((struct FingerState *)a)->id - ((struct FingerState *)b)->id; | 36 | return ((struct FingerState *)a)->id - ((struct FingerState *)b)->id; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | inline float dist2(const struct FingerData *a, const struct FingerData *b) | 39 | /* seander@cs.stanford.edu */ |
| 40 | inline unsigned abs32(int x) | ||
| 40 | { | 41 | { |
| 41 | float dx = a->position_x - b->position_x; | 42 | int const m = x >> 31; |
| 42 | float dy = a->position_y - b->position_y; | 43 | return (x + m) ^ m; |
| 44 | } | ||
| 45 | |||
| 46 | inline int abs15(int x) | ||
| 47 | { | ||
| 48 | return 32767 & abs32(x); | ||
| 49 | } | ||
| 50 | |||
| 51 | /* abslute scale is assumed to fit in 15 bits */ | ||
| 52 | inline int dist2(const struct FingerData *a, const struct FingerData *b) | ||
| 53 | { | ||
| 54 | int dx = abs15(a->position_x - b->position_x); | ||
| 55 | int dy = abs15(a->position_y - b->position_y); | ||
| 43 | 56 | ||
| 44 | return dx * dx + dy * dy; | 57 | return dx * dx + dy * dy; |
| 45 | } | 58 | } |
| @@ -71,7 +84,7 @@ void modify_state(struct State *s, | |||
| 71 | const struct HWData *hw, | 84 | const struct HWData *hw, |
| 72 | const struct Capabilities *caps) | 85 | const struct Capabilities *caps) |
| 73 | { | 86 | { |
| 74 | float A[DIM2_FINGER], *row; | 87 | int A[DIM2_FINGER], *row; |
| 75 | int sid[DIM_FINGER], hw2s[DIM_FINGER]; | 88 | int sid[DIM_FINGER], hw2s[DIM_FINGER]; |
| 76 | int id, sk, hwk; | 89 | int id, sk, hwk; |
| 77 | 90 | ||
