annotate plugins/gestures/stroke.c @ 7085:807aba537663

[gaim-migrate @ 7650] Moved some code out of dialogs.c. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 30 Sep 2003 23:05:41 +0000
parents 5239a3b4ab33
children 19fd43d52d18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4390
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /*
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 libgstroke - a GNOME stroke interface library
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 Copyright (c) 1996,1997,1998,1999,2000,2001 Mark F. Willey, ETLA Technical
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 See the file COPYING for distribution information.
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 This file contains the stroke recognition algorithm.
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 #include "config.h"
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 #include <unistd.h>
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 #include <stdlib.h>
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 #include <stdio.h>
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 #include <math.h>
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 #include <glib.h>
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 #include <gtk/gtk.h>
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 #include "gstroke.h"
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 #include "gstroke-internal.h"
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 void
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 _gstroke_init (struct gstroke_metrics *metrics)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 if (metrics->pointList != NULL) {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 /* FIXME: does this free the data too?*/
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27 g_slist_free (metrics->pointList);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28 metrics->pointList = NULL;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
29 metrics->point_count = 0;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
30 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
32
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
33 /* figure out which bin the point falls in */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 static gint
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 _gstroke_bin (p_point point_p, gint bound_x_1, gint bound_x_2,
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36 gint bound_y_1, gint bound_y_2)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
38
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39 gint bin_num = 1;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
41 if (point_p->x > bound_x_1) bin_num += 1;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
42 if (point_p->x > bound_x_2) bin_num += 1;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
43 if (point_p->y > bound_y_1) bin_num += 3;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
44 if (point_p->y > bound_y_2) bin_num += 3;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
45
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
46 return bin_num;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
47 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
48
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
49 gint
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50 _gstroke_trans (gchar *sequence, struct gstroke_metrics *metrics)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51 {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
52 GSList *crt_elem;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
53 /* number of bins recorded in the stroke */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
54 guint sequence_count = 0;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
55
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
56 /* points-->sequence translation scratch variables */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
57 gint prev_bin = 0;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
58 gint current_bin = 0;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59 gint bin_count = 0;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
61 /* flag indicating the start of a stroke - always count it in the sequence */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62 gint first_bin = TRUE;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64 /* bin boundary and size variables */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65 gint delta_x, delta_y;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
66 gint bound_x_1, bound_x_2;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67 gint bound_y_1, bound_y_2;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70 /* determine size of grid */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
71 delta_x = metrics->max_x - metrics->min_x;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
72 delta_y = metrics->max_y - metrics->min_y;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
74 /* calculate bin boundary positions */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 bound_x_1 = metrics->min_x + (delta_x / 3);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
76 bound_x_2 = metrics->min_x + 2 * (delta_x / 3);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
78 bound_y_1 = metrics->min_y + (delta_y / 3);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79 bound_y_2 = metrics->min_y + 2 * (delta_y / 3);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
80
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
81 if (delta_x > GSTROKE_SCALE_RATIO * delta_y) {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82 bound_y_1 = (metrics->max_y + metrics->min_y - delta_x) / 2 + (delta_x / 3);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
83 bound_y_2 = (metrics->max_y + metrics->min_y - delta_x) / 2 + 2 * (delta_x / 3);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84 } else if (delta_y > GSTROKE_SCALE_RATIO * delta_x) {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85 bound_x_1 = (metrics->max_x + metrics->min_x - delta_y) / 2 + (delta_y / 3);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
86 bound_x_2 = (metrics->max_x + metrics->min_x - delta_y) / 2 + 2 * (delta_y / 3);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 #if 0
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 printf ("DEBUG:: point count: %d\n", metrics->point_count);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 printf ("DEBUG:: metrics->min_x: %d\n", metrics->min_x);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 printf ("DEBUG:: metrics->max_x: %d\n", metrics->max_x);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93 printf ("DEBUG:: metrics->min_y: %d\n", metrics->min_y);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94 printf ("DEBUG:: metrics->max_y: %d\n", metrics->max_y);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95 printf ("DEBUG:: delta_x: %d\n", delta_x);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
96 printf ("DEBUG:: delta_y: %d\n", delta_y);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97 printf ("DEBUG:: bound_x_1: %d\n", bound_x_1);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
98 printf ("DEBUG:: bound_x_2: %d\n", bound_x_2);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
99 printf ("DEBUG:: bound_y_1: %d\n", bound_y_1);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
100 printf ("DEBUG:: bound_y_2: %d\n", bound_y_2);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 #endif
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
103 /*
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
104 build string by placing points in bins, collapsing bins and
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105 discarding those with too few points... */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 crt_elem = metrics->pointList;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108 while (crt_elem != NULL)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109 {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110 /* figure out which bin the point falls in */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
112 /*printf ("X = %d Y = %d\n", ((p_point)crt_elem->data)->x,
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
113 ((p_point)crt_elem->data)->y); */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
114
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
115
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
116 current_bin = _gstroke_bin ((p_point)crt_elem->data, bound_x_1,
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
117 bound_x_2, bound_y_1, bound_y_2);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
118
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
119 /* if this is the first point, consider it the previous bin, too. */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
120 if (prev_bin == 0)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
121 prev_bin = current_bin;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
122
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
123 /*printf ("DEBUG:: current bin: %d x=%d y = %d\n", current_bin,
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
124 ((p_point)crt_elem->data)->x,
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
125 ((p_point)crt_elem->data)->y); */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
126
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
127 if (prev_bin == current_bin)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
128 bin_count++;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
129 else {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
130 /* we are moving to a new bin -- consider adding to the sequence */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
131 if ((bin_count > (metrics->point_count * GSTROKE_BIN_COUNT_PERCENT))
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
132 || (first_bin == TRUE)) {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
133
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
134 /*
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
135 gchar val = '0' + prev_bin;
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
136 printf ("%c", val);fflush (stdout);
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
137 g_string_append (&sequence, &val);
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
138 */
4390
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
139
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
140 first_bin = FALSE;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
141 sequence[sequence_count++] = '0' + prev_bin;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
142 /* printf ("DEBUG:: adding sequence: %d\n", prev_bin); */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
143
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
144 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
145
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
146 /* restart counting points in the new bin */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
147 bin_count=0;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
148 prev_bin = current_bin;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
149 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
150
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
151 /* move to next point, freeing current point from list */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
152
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
153 free (crt_elem->data);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
154 crt_elem = g_slist_next (crt_elem);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
155 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
156 /* add the last run of points to the sequence */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
157 sequence[sequence_count++] = '0' + current_bin;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
158 /* printf ("DEBUG:: adding final sequence: %d\n", current_bin); */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
159
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
160 _gstroke_init (metrics);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
161
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
162 {
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
163 /* FIXME: get rid of this block
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
164 gchar val = '0' + current_bin;
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
165 printf ("%c\n", val);fflush (stdout);
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
166 g_string_append (&sequence, '\0');
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 4390
diff changeset
167 */
4390
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
168 sequence[sequence_count] = '\0';
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
169 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
170
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
171 return TRUE;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
172 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
173
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
174 /* my plan is to make a stroke training program where you can enter all of
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
175 the variations of slop that map to a canonical set of strokes. When the
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
176 application calls gstroke_canonical, it gets one of the recognized strokes,
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
177 or "", if it's not a recognized variation. I will probably use a hash
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
178 table. Right now, it just passes the values through to gstroke_trans */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
179 gint
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
180 _gstroke_canonical (gchar *sequence, struct gstroke_metrics *metrics)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
181 {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
182 return _gstroke_trans (sequence, metrics);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
183 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
184
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
185
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
186 void
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
187 _gstroke_record (gint x, gint y, struct gstroke_metrics *metrics)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
188 {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
189 p_point new_point_p;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
190 gint delx, dely;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
191 float ix, iy;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
192
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
193 #if 0
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
194 printf ("%d:%d ", x, y); fflush (stdout);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
195 #endif
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
196
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
197 if (metrics->point_count < GSTROKE_MAX_POINTS) {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
198 new_point_p = (p_point) g_malloc (sizeof (struct s_point));
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
199
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
200 if (metrics->pointList == NULL) {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
201
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
202 /* first point in list - initialize metrics */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
203 metrics->min_x = 10000;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
204 metrics->min_y = 10000;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
205 metrics->max_x = -1;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
206 metrics->max_y = -1;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
207
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
208 metrics->pointList = (GSList*) g_malloc (sizeof (GSList));
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
209
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
210 metrics->pointList->data = new_point_p;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
211 metrics->pointList->next = NULL;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
212 metrics->point_count = 0;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
213
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
214 } else {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
215
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
216 #define LAST_POINT ((p_point)(g_slist_last (metrics->pointList)->data))
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
217
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
218 /* interpolate between last and current point */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
219 delx = x - LAST_POINT->x;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
220 dely = y - LAST_POINT->y;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
221
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
222 if (abs(delx) > abs(dely)) { /* step by the greatest delta direction */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
223 iy = LAST_POINT->y;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
224
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
225 /* go from the last point to the current, whatever direction it may be */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
226 for (ix = LAST_POINT->x; (delx > 0) ? (ix < x) : (ix > x); ix += (delx > 0) ? 1 : -1) {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
227
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
228 /* step the other axis by the correct increment */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
229 iy += fabs(((float) dely / (float) delx)) * (float) ((dely < 0) ? -1.0 : 1.0);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
230
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
231 /* add the interpolated point */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
232 new_point_p->x = ix;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
233 new_point_p->y = iy;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
234 g_slist_append (metrics->pointList, new_point_p);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
235
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
236 /* update metrics */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
237 if (((gint) ix) < metrics->min_x) metrics->min_x = (gint) ix;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
238 if (((gint) ix) > metrics->max_x) metrics->max_x = (gint) ix;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
239 if (((gint) iy) < metrics->min_y) metrics->min_y = (gint) iy;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
240 if (((gint) iy) > metrics->max_y) metrics->max_y = (gint) iy;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
241 metrics->point_count++;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
242
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
243 new_point_p = (p_point) malloc (sizeof(struct s_point));
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
244 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
245 } else { /* same thing, but for dely larger than delx case... */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
246 ix = LAST_POINT->x;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
247
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
248 /* go from the last point to the current, whatever direction it may be
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
249 */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
250 for (iy = LAST_POINT->y; (dely > 0) ? (iy < y) : (iy > y); iy += (dely > 0) ? 1 : -1) {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
251
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
252 /* step the other axis by the correct increment */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
253 ix += fabs(((float) delx / (float) dely)) * (float) ((delx < 0) ? -1.0 : 1.0);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
254
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
255 /* add the interpolated point */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
256 new_point_p->y = iy;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
257 new_point_p->x = ix;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
258 g_slist_append(metrics->pointList, new_point_p);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
259
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
260 /* update metrics */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
261 if (((gint) ix) < metrics->min_x) metrics->min_x = (gint) ix;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
262 if (((gint) ix) > metrics->max_x) metrics->max_x = (gint) ix;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
263 if (((gint) iy) < metrics->min_y) metrics->min_y = (gint) iy;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
264 if (((gint) iy) > metrics->max_y) metrics->max_y = (gint) iy;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
265 metrics->point_count++;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
266
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
267 new_point_p = (p_point) malloc (sizeof(struct s_point));
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
268 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
269 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
270
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
271 /* add the sampled point */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
272 g_slist_append(metrics->pointList, new_point_p);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
273 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
274
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
275 /* record the sampled point values */
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
276 new_point_p->x = x;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
277 new_point_p->y = y;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
279 #if 0
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
280 {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281 GSList *crt = metrics->pointList;
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
282 printf ("Record ");
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
283 while (crt != NULL)
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
284 {
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
285 printf ("(%d,%d)", ((p_point)crt->data)->x, ((p_point)crt->data)->y);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
286 crt = g_slist_next (crt);
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
287 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
288 printf ("\n");
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
289 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
290 #endif
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291 }
16540914c963 [gaim-migrate @ 4656]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
292 }