Mon, 30 Jun 2025 23:04:59 -0500
Update metainfo.xml for the release
And prepare for the next release right away.
Testing Done:
Ran `meson dist`
Reviewed at https://reviews.imfreedom.org/r/4041/
| 4390 | 1 | /* |
| 2 | libgstroke - a GNOME stroke interface library | |
| 3 | Copyright (c) 1996,1997,1998,1999,2000,2001 Mark F. Willey, ETLA Technical | |
| 4 | ||
| 5 | See the file COPYING for distribution information. | |
| 6 | ||
| 7 | This file contains the stroke recognition algorithm. | |
| 8 | */ | |
| 9 | ||
|
42410
563e7a17c220
Fix possible clash of config headers
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42172
diff
changeset
|
10 | #include "purpleconfig.h" |
| 4390 | 11 | |
| 12 | #include <stdlib.h> | |
| 13 | #include <stdio.h> | |
| 14 | #include <math.h> | |
| 15 | #include <glib.h> | |
| 16 | #include <gtk/gtk.h> | |
| 17 | #include "gstroke.h" | |
| 18 | #include "gstroke-internal.h" | |
| 19 | ||
| 20 | ||
| 21 | void | |
|
42172
7c2d151b410d
Use g_clear_* helpers where useful
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40669
diff
changeset
|
22 | _gstroke_init(struct gstroke_metrics *metrics) { |
|
7c2d151b410d
Use g_clear_* helpers where useful
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40669
diff
changeset
|
23 | g_clear_slist(&metrics->pointList, g_free); |
|
7c2d151b410d
Use g_clear_* helpers where useful
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40669
diff
changeset
|
24 | metrics->point_count = 0; |
| 4390 | 25 | } |
| 26 | ||
| 27 | /* figure out which bin the point falls in */ | |
| 28 | static gint | |
| 29 | _gstroke_bin (p_point point_p, gint bound_x_1, gint bound_x_2, | |
| 30 | gint bound_y_1, gint bound_y_2) | |
| 31 | { | |
| 32 | ||
| 33 | gint bin_num = 1; | |
| 34 | ||
| 35 | if (point_p->x > bound_x_1) bin_num += 1; | |
| 36 | if (point_p->x > bound_x_2) bin_num += 1; | |
| 37 | if (point_p->y > bound_y_1) bin_num += 3; | |
| 38 | if (point_p->y > bound_y_2) bin_num += 3; | |
| 39 | ||
| 40 | return bin_num; | |
| 41 | } | |
| 42 | ||
| 43 | gint | |
| 44 | _gstroke_trans (gchar *sequence, struct gstroke_metrics *metrics) | |
| 45 | { | |
| 46 | GSList *crt_elem; | |
| 47 | /* number of bins recorded in the stroke */ | |
| 48 | guint sequence_count = 0; | |
| 49 | ||
| 50 | /* points-->sequence translation scratch variables */ | |
| 51 | gint prev_bin = 0; | |
| 52 | gint current_bin = 0; | |
| 53 | gint bin_count = 0; | |
| 54 | ||
| 55 | /* flag indicating the start of a stroke - always count it in the sequence */ | |
| 56 | gint first_bin = TRUE; | |
| 57 | ||
| 58 | /* bin boundary and size variables */ | |
| 59 | gint delta_x, delta_y; | |
| 60 | gint bound_x_1, bound_x_2; | |
| 61 | gint bound_y_1, bound_y_2; | |
| 62 | ||
| 63 | ||
| 64 | /* determine size of grid */ | |
| 65 | delta_x = metrics->max_x - metrics->min_x; | |
| 66 | delta_y = metrics->max_y - metrics->min_y; | |
| 67 | ||
| 68 | /* calculate bin boundary positions */ | |
| 69 | bound_x_1 = metrics->min_x + (delta_x / 3); | |
| 70 | bound_x_2 = metrics->min_x + 2 * (delta_x / 3); | |
| 71 | ||
| 72 | bound_y_1 = metrics->min_y + (delta_y / 3); | |
| 73 | bound_y_2 = metrics->min_y + 2 * (delta_y / 3); | |
| 74 | ||
| 75 | if (delta_x > GSTROKE_SCALE_RATIO * delta_y) { | |
| 76 | bound_y_1 = (metrics->max_y + metrics->min_y - delta_x) / 2 + (delta_x / 3); | |
| 77 | bound_y_2 = (metrics->max_y + metrics->min_y - delta_x) / 2 + 2 * (delta_x / 3); | |
| 78 | } else if (delta_y > GSTROKE_SCALE_RATIO * delta_x) { | |
| 79 | bound_x_1 = (metrics->max_x + metrics->min_x - delta_y) / 2 + (delta_y / 3); | |
| 80 | bound_x_2 = (metrics->max_x + metrics->min_x - delta_y) / 2 + 2 * (delta_y / 3); | |
| 81 | } | |
| 82 | ||
| 83 | #if 0 | |
| 84 | printf ("DEBUG:: point count: %d\n", metrics->point_count); | |
| 85 | printf ("DEBUG:: metrics->min_x: %d\n", metrics->min_x); | |
| 86 | printf ("DEBUG:: metrics->max_x: %d\n", metrics->max_x); | |
| 87 | printf ("DEBUG:: metrics->min_y: %d\n", metrics->min_y); | |
| 88 | printf ("DEBUG:: metrics->max_y: %d\n", metrics->max_y); | |
| 89 | printf ("DEBUG:: delta_x: %d\n", delta_x); | |
| 90 | printf ("DEBUG:: delta_y: %d\n", delta_y); | |
| 91 | printf ("DEBUG:: bound_x_1: %d\n", bound_x_1); | |
| 92 | printf ("DEBUG:: bound_x_2: %d\n", bound_x_2); | |
| 93 | printf ("DEBUG:: bound_y_1: %d\n", bound_y_1); | |
| 94 | printf ("DEBUG:: bound_y_2: %d\n", bound_y_2); | |
| 95 | #endif | |
| 96 | ||
| 97 | /* | |
| 98 | build string by placing points in bins, collapsing bins and | |
| 99 | discarding those with too few points... */ | |
| 100 | ||
| 101 | crt_elem = metrics->pointList; | |
| 102 | while (crt_elem != NULL) | |
| 103 | { | |
| 104 | /* figure out which bin the point falls in */ | |
| 105 | ||
| 106 | /*printf ("X = %d Y = %d\n", ((p_point)crt_elem->data)->x, | |
| 107 | ((p_point)crt_elem->data)->y); */ | |
| 108 | ||
| 109 | ||
| 110 | current_bin = _gstroke_bin ((p_point)crt_elem->data, bound_x_1, | |
| 111 | bound_x_2, bound_y_1, bound_y_2); | |
| 112 | ||
| 113 | /* if this is the first point, consider it the previous bin, too. */ | |
| 114 | if (prev_bin == 0) | |
| 115 | prev_bin = current_bin; | |
| 116 | ||
| 117 | /*printf ("DEBUG:: current bin: %d x=%d y = %d\n", current_bin, | |
| 118 | ((p_point)crt_elem->data)->x, | |
| 119 | ((p_point)crt_elem->data)->y); */ | |
| 120 | ||
| 121 | if (prev_bin == current_bin) | |
| 122 | bin_count++; | |
| 123 | else { | |
| 124 | /* we are moving to a new bin -- consider adding to the sequence */ | |
| 125 | if ((bin_count > (metrics->point_count * GSTROKE_BIN_COUNT_PERCENT)) | |
| 126 | || (first_bin == TRUE)) { | |
| 127 | ||
| 6063 | 128 | /* |
| 129 | gchar val = '0' + prev_bin; | |
| 130 | printf ("%c", val);fflush (stdout); | |
| 131 | g_string_append (&sequence, &val); | |
| 132 | */ | |
| 4390 | 133 | |
| 134 | first_bin = FALSE; | |
| 135 | sequence[sequence_count++] = '0' + prev_bin; | |
| 136 | /* printf ("DEBUG:: adding sequence: %d\n", prev_bin); */ | |
| 137 | ||
| 138 | } | |
| 139 | ||
| 140 | /* restart counting points in the new bin */ | |
| 141 | bin_count=0; | |
| 142 | prev_bin = current_bin; | |
| 143 | } | |
| 144 | ||
|
40497
2f45a03838e9
Fix gestures plugin
Elliott S <quantum.analyst@gmail.com>
parents:
39918
diff
changeset
|
145 | /* move to next point, freeing current point from list */ |
|
2f45a03838e9
Fix gestures plugin
Elliott S <quantum.analyst@gmail.com>
parents:
39918
diff
changeset
|
146 | g_free(crt_elem->data); |
|
2f45a03838e9
Fix gestures plugin
Elliott S <quantum.analyst@gmail.com>
parents:
39918
diff
changeset
|
147 | crt_elem = g_slist_next(crt_elem); |
| 4390 | 148 | } |
|
40497
2f45a03838e9
Fix gestures plugin
Elliott S <quantum.analyst@gmail.com>
parents:
39918
diff
changeset
|
149 | metrics->pointList = NULL; |
| 4390 | 150 | /* add the last run of points to the sequence */ |
| 151 | sequence[sequence_count++] = '0' + current_bin; | |
| 152 | /* printf ("DEBUG:: adding final sequence: %d\n", current_bin); */ | |
| 153 | ||
| 154 | _gstroke_init (metrics); | |
| 155 | ||
| 156 | { | |
| 6063 | 157 | /* FIXME: get rid of this block |
| 158 | gchar val = '0' + current_bin; | |
| 159 | printf ("%c\n", val);fflush (stdout); | |
| 160 | g_string_append (&sequence, '\0'); | |
| 161 | */ | |
| 4390 | 162 | sequence[sequence_count] = '\0'; |
| 163 | } | |
| 164 | ||
| 165 | return TRUE; | |
| 166 | } | |
| 167 | ||
| 168 | /* my plan is to make a stroke training program where you can enter all of | |
| 169 | the variations of slop that map to a canonical set of strokes. When the | |
| 170 | application calls gstroke_canonical, it gets one of the recognized strokes, | |
| 171 | or "", if it's not a recognized variation. I will probably use a hash | |
| 172 | table. Right now, it just passes the values through to gstroke_trans */ | |
| 173 | gint | |
| 174 | _gstroke_canonical (gchar *sequence, struct gstroke_metrics *metrics) | |
| 175 | { | |
| 176 | return _gstroke_trans (sequence, metrics); | |
| 177 | } | |
| 178 | ||
| 179 | ||
| 180 | void | |
| 181 | _gstroke_record (gint x, gint y, struct gstroke_metrics *metrics) | |
| 182 | { | |
| 183 | p_point new_point_p; | |
| 184 | gint delx, dely; | |
| 185 | float ix, iy; | |
| 186 | ||
|
9843
4daa0a6b2dd0
[gaim-migrate @ 10721]
Dave West <kat@users.sourceforge.net>
parents:
6063
diff
changeset
|
187 | g_return_if_fail( metrics != NULL ); |
|
4daa0a6b2dd0
[gaim-migrate @ 10721]
Dave West <kat@users.sourceforge.net>
parents:
6063
diff
changeset
|
188 | |
| 4390 | 189 | #if 0 |
| 190 | printf ("%d:%d ", x, y); fflush (stdout); | |
| 191 | #endif | |
| 192 | ||
| 193 | if (metrics->point_count < GSTROKE_MAX_POINTS) { | |
| 194 | if (metrics->pointList == NULL) { | |
| 195 | ||
| 196 | /* first point in list - initialize metrics */ | |
| 197 | metrics->min_x = 10000; | |
| 198 | metrics->min_y = 10000; | |
| 199 | metrics->max_x = -1; | |
| 200 | metrics->max_y = -1; | |
| 201 | ||
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
202 | new_point_p = g_new0(struct s_point, 1); |
|
28417
43c84621ba83
GSList internally doesn't use the same allocator as gmalloc. Refs #400.
Paul Aurich <darkrain42@pidgin.im>
parents:
15435
diff
changeset
|
203 | metrics->pointList = g_slist_prepend(metrics->pointList, new_point_p); |
| 4390 | 204 | metrics->point_count = 0; |
| 205 | ||
| 206 | } else { | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
207 | p_point last_point = (p_point)g_slist_last(metrics->pointList)->data; |
| 4390 | 208 | |
| 209 | /* interpolate between last and current point */ | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
210 | delx = x - last_point->x; |
|
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
211 | dely = y - last_point->y; |
| 4390 | 212 | |
| 213 | if (abs(delx) > abs(dely)) { /* step by the greatest delta direction */ | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
214 | iy = last_point->y; |
| 4390 | 215 | |
| 216 | /* go from the last point to the current, whatever direction it may be */ | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
217 | for (ix = last_point->x; (delx > 0) ? (ix < x) : (ix > x); ix += (delx > 0) ? 1 : -1) { |
| 4390 | 218 | |
| 219 | /* step the other axis by the correct increment */ | |
| 220 | iy += fabs(((float) dely / (float) delx)) * (float) ((dely < 0) ? -1.0 : 1.0); | |
| 221 | ||
| 222 | /* add the interpolated point */ | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
223 | new_point_p = g_new0(struct s_point, 1); |
| 4390 | 224 | new_point_p->x = ix; |
| 225 | new_point_p->y = iy; | |
| 12551 | 226 | metrics->pointList = g_slist_append (metrics->pointList, new_point_p); |
| 4390 | 227 | |
| 228 | /* update metrics */ | |
| 229 | if (((gint) ix) < metrics->min_x) metrics->min_x = (gint) ix; | |
| 230 | if (((gint) ix) > metrics->max_x) metrics->max_x = (gint) ix; | |
| 231 | if (((gint) iy) < metrics->min_y) metrics->min_y = (gint) iy; | |
| 232 | if (((gint) iy) > metrics->max_y) metrics->max_y = (gint) iy; | |
| 233 | metrics->point_count++; | |
| 234 | ||
| 235 | } | |
| 236 | } else { /* same thing, but for dely larger than delx case... */ | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
237 | p_point last_point = (p_point)g_slist_last(metrics->pointList)->data; |
|
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
238 | |
|
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
239 | ix = last_point->x; |
| 4390 | 240 | |
| 241 | /* go from the last point to the current, whatever direction it may be | |
| 242 | */ | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
243 | for (iy = last_point->y; (dely > 0) ? (iy < y) : (iy > y); iy += (dely > 0) ? 1 : -1) { |
| 4390 | 244 | |
| 245 | /* step the other axis by the correct increment */ | |
| 246 | ix += fabs(((float) delx / (float) dely)) * (float) ((delx < 0) ? -1.0 : 1.0); | |
| 247 | ||
| 248 | /* add the interpolated point */ | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
249 | new_point_p = g_new0(struct s_point, 1); |
| 4390 | 250 | new_point_p->y = iy; |
| 251 | new_point_p->x = ix; | |
| 12551 | 252 | metrics->pointList = g_slist_append(metrics->pointList, new_point_p); |
| 4390 | 253 | |
| 254 | /* update metrics */ | |
| 255 | if (((gint) ix) < metrics->min_x) metrics->min_x = (gint) ix; | |
| 256 | if (((gint) ix) > metrics->max_x) metrics->max_x = (gint) ix; | |
| 257 | if (((gint) iy) < metrics->min_y) metrics->min_y = (gint) iy; | |
| 258 | if (((gint) iy) > metrics->max_y) metrics->max_y = (gint) iy; | |
| 259 | metrics->point_count++; | |
| 260 | } | |
| 261 | } | |
| 262 | ||
| 263 | /* add the sampled point */ | |
|
39918
1c8e11f9274f
Fix several memory leaks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39916
diff
changeset
|
264 | new_point_p = g_new0(struct s_point, 1); |
| 12551 | 265 | metrics->pointList = g_slist_append(metrics->pointList, new_point_p); |
| 4390 | 266 | } |
| 267 | ||
| 268 | /* record the sampled point values */ | |
| 269 | new_point_p->x = x; | |
| 270 | new_point_p->y = y; | |
| 271 | ||
| 272 | #if 0 | |
| 273 | { | |
| 274 | GSList *crt = metrics->pointList; | |
| 275 | printf ("Record "); | |
| 276 | while (crt != NULL) | |
| 277 | { | |
| 278 | printf ("(%d,%d)", ((p_point)crt->data)->x, ((p_point)crt->data)->y); | |
| 279 | crt = g_slist_next (crt); | |
| 280 | } | |
| 281 | printf ("\n"); | |
| 282 | } | |
| 283 | #endif | |
| 284 | } | |
| 285 | } |