chingu-gesture 1.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/chingu_gesture/chingu_gesture.c +44 -35
- data/lib/chingu_gesture.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 617ecd8b10cff68b33eb2c25b9f6b3f8d533afbd
|
|
4
|
+
data.tar.gz: 994164f4f20be6efbf51cad9feae017858aa77e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8829456745022d217a349a168eb1b5577cbd74233d576a11fa97d218775e7bb85f0a2592d00933e20183fc5eba2fba90906b286c6af43bcba714453b4c52a360
|
|
7
|
+
data.tar.gz: ba7131efb16ca401b2c45a219c89044eacad6024f2f79b299a168782f113f216933f425d0b626f18de52b8f3aa15c36d8ea28f4254d44d2ada331bb006c8675b
|
|
@@ -6,6 +6,18 @@
|
|
|
6
6
|
const size_t INIT_BUFFER_SIZE = 255;
|
|
7
7
|
const size_t INIT_GESTURE_SIZE = 15;
|
|
8
8
|
|
|
9
|
+
// helpers
|
|
10
|
+
|
|
11
|
+
inline float max(float a, float b) {
|
|
12
|
+
return a > b ? a : b;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
inline float min(float a, float b) {
|
|
16
|
+
return a < b ? a : b;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// types
|
|
20
|
+
|
|
9
21
|
typedef struct {
|
|
10
22
|
unsigned int x, y;
|
|
11
23
|
} point_t;
|
|
@@ -16,6 +28,15 @@ typedef struct {
|
|
|
16
28
|
size_t n_skeleton;
|
|
17
29
|
} gesture_t;
|
|
18
30
|
|
|
31
|
+
point_t make_point(int x, int y) {
|
|
32
|
+
point_t p;
|
|
33
|
+
p.x = x;
|
|
34
|
+
p.y = y;
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* class handler */
|
|
39
|
+
|
|
19
40
|
typedef struct {
|
|
20
41
|
point_t* begin;
|
|
21
42
|
point_t* current;
|
|
@@ -25,13 +46,6 @@ typedef struct {
|
|
|
25
46
|
size_t max_gesture;
|
|
26
47
|
} handler_t;
|
|
27
48
|
|
|
28
|
-
point_t make_point(int x, int y) {
|
|
29
|
-
point_t p;
|
|
30
|
-
p.x = x;
|
|
31
|
-
p.y = y;
|
|
32
|
-
return p;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
49
|
void reset_handler(handler_t* handler) {
|
|
36
50
|
handler->begin = NULL;
|
|
37
51
|
handler->size = 0;
|
|
@@ -51,6 +65,16 @@ static void chingu_gesture_free(void* p) {
|
|
|
51
65
|
reset_handler(handler);
|
|
52
66
|
}
|
|
53
67
|
|
|
68
|
+
static void double_size(handler_t* handler) {
|
|
69
|
+
size_t c = handler->current - handler->begin;
|
|
70
|
+
point_t* new_points = calloc(2*handler->size, sizeof(point_t));
|
|
71
|
+
memcpy(new_points, handler->begin, handler->size*sizeof(point_t));
|
|
72
|
+
free(handler->begin);
|
|
73
|
+
handler->begin = new_points;
|
|
74
|
+
handler->size = 2*handler->size;
|
|
75
|
+
handler->current = new_points + c;
|
|
76
|
+
}
|
|
77
|
+
|
|
54
78
|
static VALUE chingu_gesture_alloc(VALUE klass) {
|
|
55
79
|
handler_t* ptr;
|
|
56
80
|
VALUE obj = Data_Make_Struct(klass, handler_t, NULL, chingu_gesture_free, ptr);
|
|
@@ -74,24 +98,6 @@ static VALUE chingu_gesture_init(VALUE self) {
|
|
|
74
98
|
return self;
|
|
75
99
|
}
|
|
76
100
|
|
|
77
|
-
static void double_size(handler_t* handler) {
|
|
78
|
-
size_t c = handler->current - handler->begin;
|
|
79
|
-
point_t* new_points = calloc(2*handler->size, sizeof(point_t));
|
|
80
|
-
memcpy(new_points, handler->begin, handler->size*sizeof(point_t));
|
|
81
|
-
free(handler->begin);
|
|
82
|
-
handler->begin = new_points;
|
|
83
|
-
handler->size = 2*handler->size;
|
|
84
|
-
handler->current = new_points + c;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static void double_size_gesture(handler_t* handler) {
|
|
88
|
-
gesture_t* new_gestures = calloc(2*handler->max_gesture, sizeof(gesture_t));
|
|
89
|
-
memcpy(new_gestures, handler->gestures, handler->max_gesture*sizeof(gesture_t));
|
|
90
|
-
free(handler->gestures);
|
|
91
|
-
handler->gestures = new_gestures;
|
|
92
|
-
handler->max_gesture = 2*handler->max_gesture;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
101
|
static VALUE chingu_gesture_add_point(VALUE self, VALUE x, VALUE y) {
|
|
96
102
|
handler_t* handler;
|
|
97
103
|
Data_Get_Struct(self, handler_t, handler);
|
|
@@ -140,6 +146,17 @@ static VALUE chingu_gesture_get_y(VALUE self, VALUE i) {
|
|
|
140
146
|
return UINT2NUM(handler->begin[ii].y);
|
|
141
147
|
}
|
|
142
148
|
|
|
149
|
+
|
|
150
|
+
// gesture
|
|
151
|
+
|
|
152
|
+
static void double_size_gesture(handler_t* handler) {
|
|
153
|
+
gesture_t* new_gestures = calloc(2*handler->max_gesture, sizeof(gesture_t));
|
|
154
|
+
memcpy(new_gestures, handler->gestures, handler->max_gesture*sizeof(gesture_t));
|
|
155
|
+
free(handler->gestures);
|
|
156
|
+
handler->gestures = new_gestures;
|
|
157
|
+
handler->max_gesture = 2*handler->max_gesture;
|
|
158
|
+
}
|
|
159
|
+
|
|
143
160
|
static VALUE chingu_gesture_add_gesture(VALUE self, VALUE list) {
|
|
144
161
|
handler_t* handler;
|
|
145
162
|
gesture_t g;
|
|
@@ -164,14 +181,6 @@ static VALUE chingu_gesture_add_gesture(VALUE self, VALUE list) {
|
|
|
164
181
|
return UINT2NUM(g.name);
|
|
165
182
|
}
|
|
166
183
|
|
|
167
|
-
inline float max(float a, float b) {
|
|
168
|
-
return a > b ? a : b;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
inline float min(float a, float b) {
|
|
172
|
-
return a < b ? a : b;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
184
|
static void min_and_range(point_t* first, size_t n_first, float* min_first_x, float* min_first_y, float* first_range) {
|
|
176
185
|
unsigned int i;
|
|
177
186
|
float max_first_x = FLT_MIN, max_first_y = FLT_MIN;
|
|
@@ -240,7 +249,6 @@ float sequence_dist(point_t* first, size_t n_first, point_t* second, size_t n_se
|
|
|
240
249
|
}
|
|
241
250
|
}
|
|
242
251
|
|
|
243
|
-
|
|
244
252
|
d = table[index2d(n_first-1, n_second-1, n_first, n_second)];
|
|
245
253
|
|
|
246
254
|
free(table);
|
|
@@ -267,9 +275,10 @@ static VALUE chingu_gesture_recognize(VALUE self) {
|
|
|
267
275
|
min_name = i;
|
|
268
276
|
}
|
|
269
277
|
}
|
|
270
|
-
return rb_ary_new3(2, UINT2NUM(min_name),
|
|
278
|
+
return rb_ary_new3(2, UINT2NUM(min_name), DBL2NUM(min_dist));
|
|
271
279
|
}
|
|
272
280
|
|
|
281
|
+
// ruby interface
|
|
273
282
|
void Init_chingu_gesture(void) {
|
|
274
283
|
VALUE klass;
|
|
275
284
|
klass = rb_const_get(rb_cObject, rb_intern("ChinguGesture"));
|
data/lib/chingu_gesture.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chingu-gesture
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- zombiecalypse
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Recognition for 2d gestures from a stream of points using dynamic time
|
|
14
14
|
warping
|
|
@@ -21,7 +21,7 @@ files:
|
|
|
21
21
|
- ext/chingu_gesture/chingu_gesture.c
|
|
22
22
|
- ext/chingu_gesture/extconf.rb
|
|
23
23
|
- lib/chingu_gesture.rb
|
|
24
|
-
homepage:
|
|
24
|
+
homepage: https://github.com/zombiecalypse/chingu-gesture
|
|
25
25
|
licenses:
|
|
26
26
|
- MIT
|
|
27
27
|
metadata: {}
|
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
41
41
|
version: '0'
|
|
42
42
|
requirements: []
|
|
43
43
|
rubyforge_project:
|
|
44
|
-
rubygems_version: 2.
|
|
44
|
+
rubygems_version: 2.4.5
|
|
45
45
|
signing_key:
|
|
46
46
|
specification_version: 4
|
|
47
47
|
summary: Recognize gestures fast
|