summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--match/match.c35
-rw-r--r--match/match.h2
-rw-r--r--match/test.c96
-rw-r--r--src/state.c21
4 files changed, 80 insertions, 74 deletions
diff --git a/match/match.c b/match/match.c
index a3f4deb..4cb4495 100644
--- a/match/match.c
+++ b/match/match.c
@@ -64,25 +64,25 @@ static void buildixvector(int *ix, mat_t mstar, int nrows, int ncols)
64 64
65/********************************************************/ 65/********************************************************/
66 66
67static void step2a(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 67static void step2a(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
68 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 68 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
69 int dmin); 69 int dmin);
70static void step2b(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 70static void step2b(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
71 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 71 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
72 int dmin); 72 int dmin);
73static void step3(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 73static void step3(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
74 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 74 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
75 int dmin); 75 int dmin);
76static void step4(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 76static void step4(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
77 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 77 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
78 int dmin, int row, int col); 78 int dmin, int row, int col);
79static void step5(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 79static void step5(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
80 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 80 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
81 int dmin); 81 int dmin);
82 82
83static void ixoptimal(int *ix, float *mdist, int nrows, int ncols) 83static void ixoptimal(int *ix, int *mdist, int nrows, int ncols)
84{ 84{
85 float *mdistTemp, *mdistEnd, *columnEnd, value, minValue; 85 int *mdistTemp, *mdistEnd, *columnEnd, value, minValue;
86 int dmin, row, col; 86 int dmin, row, col;
87 col_t ccol, crow; 87 col_t ccol, crow;
88 mat_t mstar, mprime, nmstar; 88 mat_t mstar, mprime, nmstar;
@@ -181,7 +181,7 @@ static void ixoptimal(int *ix, float *mdist, int nrows, int ncols)
181} 181}
182 182
183/********************************************************/ 183/********************************************************/
184static void step2a(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 184static void step2a(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
185 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 185 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
186 int dmin) 186 int dmin)
187{ 187{
@@ -204,7 +204,7 @@ static void step2a(int *ix, float *mdist, mat_t mstar, mat_t nmstar,
204} 204}
205 205
206/********************************************************/ 206/********************************************************/
207static void step2b(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 207static void step2b(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
208 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 208 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
209 int dmin) 209 int dmin)
210{ 210{
@@ -229,7 +229,7 @@ static void step2b(int *ix, float *mdist, mat_t mstar, mat_t nmstar,
229} 229}
230 230
231/********************************************************/ 231/********************************************************/
232static void step3(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 232static void step3(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
233 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 233 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
234 int dmin) 234 int dmin)
235{ 235{
@@ -279,7 +279,7 @@ static void step3(int *ix, float *mdist, mat_t mstar, mat_t nmstar,
279} 279}
280 280
281/********************************************************/ 281/********************************************************/
282static void step4(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 282static void step4(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
283 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 283 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
284 int dmin, int row, int col) 284 int dmin, int row, int col)
285{ 285{
@@ -330,11 +330,11 @@ static void step4(int *ix, float *mdist, mat_t mstar, mat_t nmstar,
330} 330}
331 331
332/********************************************************/ 332/********************************************************/
333static void step5(int *ix, float *mdist, mat_t mstar, mat_t nmstar, 333static void step5(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
334 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, 334 mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
335 int dmin) 335 int dmin)
336{ 336{
337 float h = 0, value; 337 int h = 0, value;
338 int row, col, found = 0; 338 int row, col, found = 0;
339 339
340 /* find smallest uncovered element h */ 340 /* find smallest uncovered element h */
@@ -378,15 +378,8 @@ static void step5(int *ix, float *mdist, mat_t mstar, mat_t nmstar,
378 dmin); 378 dmin);
379} 379}
380 380
381void match_fingers(int ix[DIM_FINGER], float A[DIM2_FINGER], int nrow, int ncol) 381void match_fingers(int ix[DIM_FINGER], int A[DIM2_FINGER], int nrow, int ncol)
382{ 382{
383 int i;
384 float max = 1;
385 for (i = 0; i < nrow * ncol; i++)
386 if (A[i] > max)
387 max = A[i];
388 for (i = 0; i < nrow * ncol; i++)
389 A[i] /= max;
390 ixoptimal(ix, A, nrow, ncol); 383 ixoptimal(ix, A, nrow, ncol);
391} 384}
392 385
diff --git a/match/match.h b/match/match.h
index 0c4274e..6420b00 100644
--- a/match/match.h
+++ b/match/match.h
@@ -34,7 +34,7 @@
34#define MIN(a, b) ((a) < (b) ? (a) : (b)) 34#define MIN(a, b) ((a) < (b) ? (a) : (b))
35#define MAX(a, b) ((a) < (b) ? (b) : (a)) 35#define MAX(a, b) ((a) < (b) ? (b) : (a))
36 36
37void match_fingers(int index[DIM_FINGER], float A[DIM2_FINGER], 37void match_fingers(int index[DIM_FINGER], int A[DIM2_FINGER],
38 int nrow, int ncol); 38 int nrow, int ncol);
39 39
40#endif 40#endif
diff --git a/match/test.c b/match/test.c
index 192f969..f9f2a27 100644
--- a/match/test.c
+++ b/match/test.c
@@ -27,23 +27,23 @@
27 27
28static void test1() 28static void test1()
29{ 29{
30 float A[] = { 30 int A[] = {
31 1013.000000, 31 1013,
32 3030660.000000, 32 3030660,
33 3559354.000000, 33 3559354,
34 12505925.000000, 34 12505925,
35 19008450.000000, 35 19008450,
36 6946421.000000, 36 6946421,
37 6118613.000000, 37 6118613,
38 698020.000000, 38 698020,
39 3021800.000000, 39 3021800,
40 1017.000000, 40 1017,
41 37573.000000, 41 37573,
42 3242018.000000, 42 3242018,
43 8152794.000000, 43 8152794,
44 1266053.000000, 44 1266053,
45 942941.000000, 45 942941,
46 462820.000000, 46 462820,
47 }; 47 };
48 int index[DIM_FINGER], i; 48 int index[DIM_FINGER], i;
49 match_fingers(index, A, 4, 4); 49 match_fingers(index, A, 4, 4);
@@ -53,32 +53,32 @@ static void test1()
53 53
54static void test2() 54static void test2()
55{ 55{
56 float A[] = { 56 int A[] = {
57 0.000000, 57 0,
58 4534330.000000, 58 4534330,
59 22653552.000000, 59 22653552,
60 12252500.000000, 60 12252500,
61 685352.000000, 61 685352,
62 4534330.000000, 62 4534330,
63 0.000000, 63 0,
64 9619317.000000, 64 9619317,
65 28409530.000000, 65 28409530,
66 6710170.000000, 66 6710170,
67 22653552.000000, 67 22653552,
68 9619317.000000, 68 9619317,
69 0.000000, 69 0,
70 47015292.000000, 70 47015292,
71 29788572.000000, 71 29788572,
72 2809040.000000, 72 2809040,
73 10428866.000000, 73 10428866,
74 38615920.000000, 74 38615920,
75 17732500.000000, 75 17732500,
76 719528.000000, 76 719528,
77 12113945.000000, 77 12113945,
78 28196220.000000, 78 28196220,
79 46778656.000000, 79 46778656,
80 405.000000, 80 405,
81 14175493.000000, 81 14175493,
82 }; 82 };
83 int index[DIM_FINGER], i; 83 int index[DIM_FINGER], i;
84 match_fingers(index, A, 5, 5); 84 match_fingers(index, A, 5, 5);
@@ -89,11 +89,11 @@ static void test2()
89static void speed1() 89static void speed1()
90{ 90{
91 /* column-by-column matrix */ 91 /* column-by-column matrix */
92 float A[DIM2_FINGER]; 92 int A[DIM2_FINGER];
93 float x1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5, 6, 7, 8 }; 93 int x1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5, 6, 7, 8 };
94 float y1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5.1, 6, 7, 8 }; 94 int y1[DIM_FINGER] = { 1, 5, 2, 3, 4, 6, 6, 7, 8 };
95 float x2[DIM_FINGER] = { 1.1, 3, 2, 4, 5, 6, 7, 8 }; 95 int x2[DIM_FINGER] = { 1.1, 3, 2, 4, 5, 6, 7, 8 };
96 float y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 }; 96 int y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 };
97 int index[DIM_FINGER]; 97 int index[DIM_FINGER];
98 int n1 = 4; 98 int n1 = 4;
99 int n2 = 7; 99 int n2 = 7;
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
39inline float dist2(const struct FingerData *a, const struct FingerData *b) 39/* seander@cs.stanford.edu */
40inline 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
46inline int abs15(int x)
47{
48 return 32767 & abs32(x);
49}
50
51/* abslute scale is assumed to fit in 15 bits */
52inline 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