195
|
1 |
for (int i = 0; i < list.Count - 1; i++)
|
|
2 |
{
|
|
3 |
if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UP && lastDirection != SurfaceGestureVectorDirection.UP)
|
|
4 |
{
|
|
5 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
6 |
LastChange = list[i + 1];
|
|
7 |
lastDirection = SurfaceGestureVectorDirection.UP;
|
|
8 |
}
|
|
9 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWN && lastDirection != SurfaceGestureVectorDirection.DOWN)
|
|
10 |
{
|
|
11 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
12 |
LastChange = list[i + 1];
|
|
13 |
lastDirection = SurfaceGestureVectorDirection.DOWN;
|
|
14 |
}
|
|
15 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT)
|
|
16 |
{
|
|
17 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
18 |
LastChange = list[i + 1];
|
|
19 |
lastDirection = SurfaceGestureVectorDirection.UPLEFT;
|
|
20 |
}
|
|
21 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT)
|
|
22 |
{
|
|
23 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
24 |
LastChange = list[i + 1];
|
|
25 |
lastDirection = SurfaceGestureVectorDirection.UPRIGHT;
|
|
26 |
}
|
|
27 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNLEFT && lastDirection != SurfaceGestureVectorDirection.DOWNLEFT)
|
|
28 |
{
|
|
29 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
30 |
LastChange = list[i + 1];
|
|
31 |
lastDirection = SurfaceGestureVectorDirection.DOWNLEFT;
|
|
32 |
}
|
|
33 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT)
|
|
34 |
{
|
|
35 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
36 |
LastChange = list[i + 1];
|
|
37 |
lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT;
|
|
38 |
}
|
|
39 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.LEFT && lastDirection != SurfaceGestureVectorDirection.LEFT)
|
|
40 |
{
|
|
41 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)), Origin = list[lastPoint] });
|
|
42 |
LastChange = list[i + 1];
|
|
43 |
lastDirection = SurfaceGestureVectorDirection.LEFT;
|
|
44 |
}
|
|
45 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.RIGHT && lastDirection != SurfaceGestureVectorDirection.RIGHT)
|
|
46 |
{
|
|
47 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)), Origin = list[lastPoint] });
|
|
48 |
LastChange = list[i + 1];
|
|
49 |
lastDirection = SurfaceGestureVectorDirection.RIGHT;
|
|
50 |
}
|
|
51 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT)
|
|
52 |
{
|
|
53 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
54 |
LastChange = list[i + 1];
|
|
55 |
lastDirection = SurfaceGestureVectorDirection.UPLEFT;
|
|
56 |
}
|
|
57 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT)
|
|
58 |
{
|
|
59 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
60 |
LastChange = list[i + 1];
|
|
61 |
lastDirection = SurfaceGestureVectorDirection.UPRIGHT;
|
|
62 |
}
|
|
63 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNLEFT && lastDirection != SurfaceGestureVectorDirection.DOWNLEFT)
|
|
64 |
{
|
|
65 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
66 |
LastChange = list[i + 1];
|
|
67 |
lastDirection = SurfaceGestureVectorDirection.DOWNLEFT;
|
|
68 |
}
|
|
69 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT)
|
|
70 |
{
|
|
71 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
|
|
72 |
LastChange = list[i + 1];
|
|
73 |
lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT;
|
|
74 |
}
|
|
75 |
++lastPoint;
|
|
76 |
}
|
|
77 |
|
|
78 |
// Analyse des extrémités de la gesture
|
|
79 |
/*
|
|
80 |
|
|
81 |
double diffX = Math.Abs(list[0].X - list[list.Count - 1].X);
|
|
82 |
double diffY = Math.Abs(list[0].Y - list[list.Count - 1].Y);
|
|
83 |
|
|
84 |
if (diffX < 10 && diffY > 10)
|
|
85 |
{
|
|
86 |
this.Clear();
|
|
87 |
if (up > down)
|
|
88 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up });
|
|
89 |
else
|
|
90 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down });
|
|
91 |
}
|
|
92 |
else if (diffY < 10 && diffX > 10)
|
|
93 |
{
|
|
94 |
this.Clear();
|
|
95 |
if (left > right)
|
|
96 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left });
|
|
97 |
else
|
|
98 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right });
|
|
99 |
}
|
|
100 |
|
|
101 |
*/
|
|
102 |
|
|
103 |
// Analyse détaillée de la gesture
|
|
104 |
|
|
105 |
List<SurfaceGestureVector> ThisTemp = new List<SurfaceGestureVector>();
|
|
106 |
List<SurfaceGestureVector> temp = new List<SurfaceGestureVector>();
|
|
107 |
List<SurfaceGestureVector> Tempo = new List<SurfaceGestureVector>();
|
|
108 |
|
|
109 |
if ((this.Count / 10) >= 1)
|
|
110 |
{
|
|
111 |
/*
|
|
112 |
for (int i = 1; i < this.Count + 1; i++)
|
|
113 |
{
|
|
114 |
temp.Add(this[i-1]);
|
|
115 |
if (i % 7 == 0)
|
|
116 |
{
|
|
117 |
SurfaceGestureVector result = Analyse(temp);
|
|
118 |
if (ThisTemp.Count == 0 || !ThisTemp[ThisTemp.Count - 1].Direction.Equals(result.Direction))
|
|
119 |
ThisTemp.Add(result);
|
|
120 |
else
|
|
121 |
ThisTemp[ThisTemp.Count - 1].Lenght += result.Lenght;
|
|
122 |
temp.Clear();
|
|
123 |
}
|
|
124 |
}
|
|
125 |
if (temp.Count > 0)
|
|
126 |
{
|
|
127 |
SurfaceGestureVector result = Analyse(temp);
|
|
128 |
if (ThisTemp[ThisTemp.Count - 1].Direction.Equals(result.Direction))
|
|
129 |
ThisTemp[ThisTemp.Count - 1].Lenght += result.Lenght;
|
|
130 |
else
|
|
131 |
ThisTemp.Add(result);
|
|
132 |
temp.Clear();
|
|
133 |
}
|
|
134 |
this.Clear();
|
|
135 |
foreach(SurfaceGestureVector elt in ThisTemp)
|
|
136 |
this.Add(elt);
|
|
137 |
*/
|
|
138 |
switch (this.Count / 10)
|
|
139 |
{
|
|
140 |
case 1:
|
|
141 |
ThisTemp.Add(Analyse(this));
|
|
142 |
this.Clear();
|
|
143 |
if (ThisTemp.Count > 1)
|
|
144 |
{
|
|
145 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
|
|
146 |
foreach (SurfaceGestureVector elt in ThisTemp)
|
|
147 |
{
|
|
148 |
switch (elt.Direction)
|
|
149 |
{
|
|
150 |
case SurfaceGestureVectorDirection.DOWN:
|
|
151 |
down += elt.Lenght;
|
|
152 |
break;
|
|
153 |
case SurfaceGestureVectorDirection.DOWNLEFT:
|
|
154 |
downleft += elt.Lenght;
|
|
155 |
break;
|
|
156 |
case SurfaceGestureVectorDirection.DOWNRIGHT:
|
|
157 |
downright += elt.Lenght;
|
|
158 |
break;
|
|
159 |
case SurfaceGestureVectorDirection.LEFT:
|
|
160 |
left += elt.Lenght;
|
|
161 |
break;
|
|
162 |
case SurfaceGestureVectorDirection.RIGHT:
|
|
163 |
right += elt.Lenght;
|
|
164 |
break;
|
|
165 |
case SurfaceGestureVectorDirection.UP:
|
|
166 |
up += elt.Lenght;
|
|
167 |
break;
|
|
168 |
case SurfaceGestureVectorDirection.UPLEFT:
|
|
169 |
upleft += elt.Lenght;
|
|
170 |
break;
|
|
171 |
case SurfaceGestureVectorDirection.UPRIGHT:
|
|
172 |
upright += elt.Lenght;
|
|
173 |
break;
|
|
174 |
default:
|
|
175 |
break;
|
|
176 |
}
|
|
177 |
}
|
|
178 |
if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(up))
|
|
179 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
|
|
180 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upleft))
|
|
181 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
|
|
182 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upright))
|
|
183 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
|
|
184 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(down))
|
|
185 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
|
|
186 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downleft))
|
|
187 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
|
|
188 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downright))
|
|
189 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
|
|
190 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(left))
|
|
191 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
|
|
192 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(right))
|
|
193 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
|
|
194 |
}
|
|
195 |
else
|
|
196 |
this.Add(ThisTemp[0]);
|
|
197 |
break;
|
|
198 |
case 2:
|
|
199 |
for (int index = 1; index <= this.Count; index++)
|
|
200 |
{
|
|
201 |
if (index == this.Count / 2 || index == this.Count)
|
|
202 |
{
|
|
203 |
ThisTemp.Add(Analyse(temp));
|
|
204 |
if (ThisTemp.Count > 1)
|
|
205 |
{
|
|
206 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
|
|
207 |
foreach (SurfaceGestureVector elt in ThisTemp)
|
|
208 |
{
|
|
209 |
|
|
210 |
switch (elt.Direction)
|
|
211 |
{
|
|
212 |
case SurfaceGestureVectorDirection.DOWN:
|
|
213 |
down += elt.Lenght;
|
|
214 |
break;
|
|
215 |
case SurfaceGestureVectorDirection.DOWNLEFT:
|
|
216 |
downleft += elt.Lenght;
|
|
217 |
break;
|
|
218 |
case SurfaceGestureVectorDirection.DOWNRIGHT:
|
|
219 |
downright += elt.Lenght;
|
|
220 |
break;
|
|
221 |
case SurfaceGestureVectorDirection.LEFT:
|
|
222 |
left += elt.Lenght;
|
|
223 |
break;
|
|
224 |
case SurfaceGestureVectorDirection.RIGHT:
|
|
225 |
right += elt.Lenght;
|
|
226 |
break;
|
|
227 |
case SurfaceGestureVectorDirection.UP:
|
|
228 |
up += elt.Lenght;
|
|
229 |
break;
|
|
230 |
case SurfaceGestureVectorDirection.UPLEFT:
|
|
231 |
upleft += elt.Lenght;
|
|
232 |
break;
|
|
233 |
case SurfaceGestureVectorDirection.UPRIGHT:
|
|
234 |
upright += elt.Lenght;
|
|
235 |
break;
|
|
236 |
}
|
|
237 |
}
|
|
238 |
if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(up))
|
|
239 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
|
|
240 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upleft))
|
|
241 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
|
|
242 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upright))
|
|
243 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
|
|
244 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(down))
|
|
245 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
|
|
246 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downleft))
|
|
247 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
|
|
248 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downright))
|
|
249 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
|
|
250 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(left))
|
|
251 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
|
|
252 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(right))
|
|
253 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
|
|
254 |
}
|
|
255 |
else
|
|
256 |
Tempo.Add(ThisTemp[0]);
|
|
257 |
}
|
|
258 |
else
|
|
259 |
ThisTemp.Add(this[index]);
|
|
260 |
}
|
|
261 |
this.Clear();
|
|
262 |
if (Tempo[0].Direction.Equals(Tempo[1].Direction))
|
|
263 |
this.Add(Tempo[0]);
|
|
264 |
else
|
|
265 |
foreach (SurfaceGestureVector elt in Tempo)
|
|
266 |
this.Add(elt);
|
|
267 |
break;
|
|
268 |
case 3:
|
|
269 |
for (int index = 1; index <= this.Count; index++)
|
|
270 |
{
|
|
271 |
if (index == this.Count / 3 || index == this.Count)
|
|
272 |
{
|
|
273 |
ThisTemp.Add(Analyse(temp));
|
|
274 |
if (ThisTemp.Count > 1)
|
|
275 |
{
|
|
276 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
|
|
277 |
foreach (SurfaceGestureVector elt in ThisTemp)
|
|
278 |
{
|
|
279 |
|
|
280 |
switch (elt.Direction)
|
|
281 |
{
|
|
282 |
case SurfaceGestureVectorDirection.DOWN:
|
|
283 |
down += elt.Lenght;
|
|
284 |
break;
|
|
285 |
case SurfaceGestureVectorDirection.DOWNLEFT:
|
|
286 |
downleft += elt.Lenght;
|
|
287 |
break;
|
|
288 |
case SurfaceGestureVectorDirection.DOWNRIGHT:
|
|
289 |
downright += elt.Lenght;
|
|
290 |
break;
|
|
291 |
case SurfaceGestureVectorDirection.LEFT:
|
|
292 |
left += elt.Lenght;
|
|
293 |
break;
|
|
294 |
case SurfaceGestureVectorDirection.RIGHT:
|
|
295 |
right += elt.Lenght;
|
|
296 |
break;
|
|
297 |
case SurfaceGestureVectorDirection.UP:
|
|
298 |
up += elt.Lenght;
|
|
299 |
break;
|
|
300 |
case SurfaceGestureVectorDirection.UPLEFT:
|
|
301 |
upleft += elt.Lenght;
|
|
302 |
break;
|
|
303 |
case SurfaceGestureVectorDirection.UPRIGHT:
|
|
304 |
upright += elt.Lenght;
|
|
305 |
break;
|
|
306 |
}
|
|
307 |
}
|
|
308 |
if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(up))
|
|
309 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
|
|
310 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upleft))
|
|
311 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
|
|
312 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upright))
|
|
313 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
|
|
314 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(down))
|
|
315 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
|
|
316 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downleft))
|
|
317 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
|
|
318 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downright))
|
|
319 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
|
|
320 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(left))
|
|
321 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
|
|
322 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(right))
|
|
323 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
|
|
324 |
}
|
|
325 |
else
|
|
326 |
Tempo.Add(ThisTemp[0]);
|
|
327 |
}
|
|
328 |
else
|
|
329 |
ThisTemp.Add(this[index]);
|
|
330 |
}
|
|
331 |
this.Clear();
|
|
332 |
if (Tempo[0].Direction.Equals(Tempo[1].Direction) && Tempo[0].Direction.Equals(Tempo[2].Direction))
|
|
333 |
this.Add(Tempo[0]);
|
|
334 |
else
|
|
335 |
foreach (SurfaceGestureVector elt in Tempo)
|
|
336 |
this.Add(elt);
|
|
337 |
break;
|
|
338 |
default:
|
|
339 |
for (int index = 1; index <= this.Count; index++)
|
|
340 |
{
|
|
341 |
if (index == this.Count / 4 || index == this.Count)
|
|
342 |
{
|
|
343 |
ThisTemp.Add(Analyse(temp));
|
|
344 |
if (ThisTemp.Count > 1)
|
|
345 |
{
|
|
346 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
|
|
347 |
foreach (SurfaceGestureVector elt in ThisTemp)
|
|
348 |
{
|
|
349 |
|
|
350 |
switch (elt.Direction)
|
|
351 |
{
|
|
352 |
case SurfaceGestureVectorDirection.DOWN:
|
|
353 |
down += elt.Lenght;
|
|
354 |
break;
|
|
355 |
case SurfaceGestureVectorDirection.DOWNLEFT:
|
|
356 |
downleft += elt.Lenght;
|
|
357 |
break;
|
|
358 |
case SurfaceGestureVectorDirection.DOWNRIGHT:
|
|
359 |
downright += elt.Lenght;
|
|
360 |
break;
|
|
361 |
case SurfaceGestureVectorDirection.LEFT:
|
|
362 |
left += elt.Lenght;
|
|
363 |
break;
|
|
364 |
case SurfaceGestureVectorDirection.RIGHT:
|
|
365 |
right += elt.Lenght;
|
|
366 |
break;
|
|
367 |
case SurfaceGestureVectorDirection.UP:
|
|
368 |
up += elt.Lenght;
|
|
369 |
break;
|
|
370 |
case SurfaceGestureVectorDirection.UPLEFT:
|
|
371 |
upleft += elt.Lenght;
|
|
372 |
break;
|
|
373 |
case SurfaceGestureVectorDirection.UPRIGHT:
|
|
374 |
upright += elt.Lenght;
|
|
375 |
break;
|
|
376 |
}
|
|
377 |
}
|
|
378 |
if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(up))
|
|
379 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
|
|
380 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upleft))
|
|
381 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
|
|
382 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upright))
|
|
383 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
|
|
384 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(down))
|
|
385 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
|
|
386 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downleft))
|
|
387 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
|
|
388 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downright))
|
|
389 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
|
|
390 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(left))
|
|
391 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
|
|
392 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(right))
|
|
393 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
|
|
394 |
}
|
|
395 |
else
|
|
396 |
Tempo.Add(ThisTemp[0]);
|
|
397 |
}
|
|
398 |
else
|
|
399 |
ThisTemp.Add(this[index]);
|
|
400 |
}
|
|
401 |
this.Clear();
|
|
402 |
if (Tempo[0].Direction.Equals(Tempo[1].Direction) && Tempo[0].Direction.Equals(Tempo[2].Direction) && Tempo[0].Direction.Equals(Tempo[3].Direction))
|
|
403 |
this.Add(Tempo[0]);
|
|
404 |
else
|
|
405 |
foreach (SurfaceGestureVector elt in Tempo)
|
|
406 |
this.Add(elt);
|
|
407 |
break;
|
|
408 |
}
|
|
409 |
}
|
|
410 |
else
|
|
411 |
{
|
|
412 |
ThisTemp.Add(Analyse(this));
|
|
413 |
this.Clear();
|
|
414 |
if (ThisTemp.Count > 1)
|
|
415 |
{
|
|
416 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
|
|
417 |
foreach (SurfaceGestureVector elt in ThisTemp)
|
|
418 |
{
|
|
419 |
|
|
420 |
switch (elt.Direction)
|
|
421 |
{
|
|
422 |
case SurfaceGestureVectorDirection.DOWN:
|
|
423 |
down += elt.Lenght;
|
|
424 |
break;
|
|
425 |
case SurfaceGestureVectorDirection.DOWNLEFT:
|
|
426 |
downleft += elt.Lenght;
|
|
427 |
break;
|
|
428 |
case SurfaceGestureVectorDirection.DOWNRIGHT:
|
|
429 |
downright += elt.Lenght;
|
|
430 |
break;
|
|
431 |
case SurfaceGestureVectorDirection.LEFT:
|
|
432 |
left += elt.Lenght;
|
|
433 |
break;
|
|
434 |
case SurfaceGestureVectorDirection.RIGHT:
|
|
435 |
right += elt.Lenght;
|
|
436 |
break;
|
|
437 |
case SurfaceGestureVectorDirection.UP:
|
|
438 |
up += elt.Lenght;
|
|
439 |
break;
|
|
440 |
case SurfaceGestureVectorDirection.UPLEFT:
|
|
441 |
upleft += elt.Lenght;
|
|
442 |
break;
|
|
443 |
case SurfaceGestureVectorDirection.UPRIGHT:
|
|
444 |
upright += elt.Lenght;
|
|
445 |
break;
|
|
446 |
}
|
|
447 |
}
|
|
448 |
if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(up))
|
|
449 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
|
|
450 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upleft))
|
|
451 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
|
|
452 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upright))
|
|
453 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
|
|
454 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(down))
|
|
455 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
|
|
456 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downleft))
|
|
457 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
|
|
458 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downright))
|
|
459 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
|
|
460 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(left))
|
|
461 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
|
|
462 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(right))
|
|
463 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
|
|
464 |
}
|
|
465 |
else
|
|
466 |
this.Add(ThisTemp[0]);
|
|
467 |
}
|
|
468 |
}
|
|
469 |
|
|
470 |
private SurfaceGestureVector Analyse(List<SurfaceGestureVector> list)
|
|
471 |
{
|
|
472 |
// Analyse de la forme
|
|
473 |
if (list.Count == 1)
|
|
474 |
return list[0];
|
|
475 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
|
|
476 |
foreach (SurfaceGestureVector elt in list)
|
|
477 |
{
|
|
478 |
|
|
479 |
switch (elt.Direction)
|
|
480 |
{
|
|
481 |
case SurfaceGestureVectorDirection.DOWN:
|
|
482 |
down += elt.Lenght;
|
|
483 |
break;
|
|
484 |
case SurfaceGestureVectorDirection.DOWNLEFT:
|
|
485 |
downleft += elt.Lenght;
|
|
486 |
break;
|
|
487 |
case SurfaceGestureVectorDirection.DOWNRIGHT:
|
|
488 |
downright += elt.Lenght;
|
|
489 |
break;
|
|
490 |
case SurfaceGestureVectorDirection.LEFT:
|
|
491 |
left += elt.Lenght;
|
|
492 |
break;
|
|
493 |
case SurfaceGestureVectorDirection.RIGHT:
|
|
494 |
right += elt.Lenght;
|
|
495 |
break;
|
|
496 |
case SurfaceGestureVectorDirection.UP:
|
|
497 |
up += elt.Lenght;
|
|
498 |
break;
|
|
499 |
case SurfaceGestureVectorDirection.UPLEFT:
|
|
500 |
upleft += elt.Lenght;
|
|
501 |
break;
|
|
502 |
case SurfaceGestureVectorDirection.UPRIGHT:
|
|
503 |
upright += elt.Lenght;
|
|
504 |
break;
|
|
505 |
}
|
|
506 |
}
|
|
507 |
/*
|
|
508 |
//double cupleft = 0, cupright = 0, cdownleft = 0, cdownright = 0;
|
|
509 |
|
|
510 |
|
|
511 |
if (list.Count > 2)
|
|
512 |
{
|
|
513 |
double min = 180;
|
|
514 |
for (int i = 1; i < list.Count - 2; i++)
|
|
515 |
{
|
|
516 |
double a = GetDistancePoints(list[list.Count - 1].Origin, list[0].Origin);
|
|
517 |
double b = GetDistancePoints(list[i].Origin, list[0].Origin);
|
|
518 |
double c = GetDistancePoints(list[i].Origin, list[list.Count - 1].Origin);
|
|
519 |
double angle = 180 * (Math.Acos((b * b + c * c - a * a) / (2 * b * c))) / Math.PI ;
|
|
520 |
min = Math.Min(angle > 0 ? angle : 180, min);
|
|
521 |
}
|
|
522 |
if(min<130)
|
|
523 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.NONE, Lenght = up, Origin = list[0].Origin };
|
|
524 |
}
|
|
525 |
|
|
526 |
if (up < 4 && upleft < 4 && upright < 4 && down < 4 && downleft < 4 && downright < 4 && right < 4 && left < 4)
|
|
527 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 };
|
|
528 |
if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(up))
|
|
529 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = list[0].Origin };
|
|
530 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upleft))
|
|
531 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = list[0].Origin };
|
|
532 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(upright))
|
|
533 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin };
|
|
534 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(down))
|
|
535 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = list[0].Origin };
|
|
536 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downleft))
|
|
537 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = list[0].Origin };
|
|
538 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(downright))
|
|
539 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = list[0].Origin };
|
|
540 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(left))
|
|
541 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = list[0].Origin };
|
|
542 |
else if (Math.Max(up, Math.Max(upleft, Math.Max(upright, Math.Max(down, Math.Max(downleft, Math.Max(left, Math.Max(downright, right))))))).Equals(right))
|
|
543 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = list[0].Origin };
|
|
544 |
else
|
|
545 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.NONE, Lenght = 0, Origin = list[0].Origin });
|
|
546 |
*/
|
|
547 |
|
|
548 |
double diffX = Math.Abs(list[0].Origin.X - list[list.Count - 1].Origin.X);
|
|
549 |
double diffY = Math.Abs(list[0].Origin.Y - list[list.Count - 1].Origin.Y);
|
|
550 |
|
|
551 |
if (diffX < 10 && diffY > 10)
|
|
552 |
{
|
|
553 |
if (list[0].Origin.Y > list[list.Count - 1].Origin.Y)
|
|
554 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = list[0].Origin });
|
|
555 |
else
|
|
556 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = list[0].Origin });
|
|
557 |
}
|
|
558 |
else if (diffY < 10 && diffX > 10)
|
|
559 |
{
|
|
560 |
if (list[list.Count - 1].Origin.X > list[0].Origin.X)
|
|
561 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = list[0].Origin });
|
|
562 |
else
|
|
563 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = list[0].Origin });
|
|
564 |
}
|
|
565 |
else if (diffX > 10 && diffY > 10)
|
|
566 |
{
|
|
567 |
if (list[0].Origin.Y > list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X > list[0].Origin.X)
|
|
568 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = list[0].Origin };
|
|
569 |
else if (list[0].Origin.Y > list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X < list[0].Origin.X)
|
|
570 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin };
|
|
571 |
else if (list[0].Origin.Y < list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X > list[0].Origin.X)
|
|
572 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = list[0].Origin };
|
|
573 |
else
|
|
574 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin };
|
|
575 |
}
|
|
576 |
else
|
|
577 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 }; |