author | cavaliet |
Thu, 19 Nov 2009 12:15:12 +0100 | |
changeset 211 | 50e6fe2c2ea2 |
parent 209 | 09c4d30fe8d1 |
child 215 | d13dbcf861d7 |
permissions | -rw-r--r-- |
174 | 1 |
using System; |
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Windows.Input; |
|
6 |
using System.Windows; |
|
7 |
||
8 |
namespace GestureControl |
|
9 |
{ |
|
10 |
/// <summary> |
|
11 |
/// Take a list of points and try to recognize a pattern |
|
12 |
/// </summary> |
|
13 |
public class SurfaceGesture : List<SurfaceGestureVector> |
|
14 |
{ |
|
15 |
||
16 |
#region Prop |
|
17 |
/// <summary> |
|
18 |
/// Allow some variation without log a direction |
|
19 |
/// </summary> |
|
20 |
public int Precision { get; set; } |
|
21 |
#endregion |
|
176 | 22 |
|
174 | 23 |
#region Constructor |
24 |
/// <summary> |
|
25 |
/// load know patterns and generate the vector list from a list of points with a default 20 precision factor |
|
26 |
/// </summary> |
|
27 |
/// <param name="list"></param> |
|
28 |
public SurfaceGesture(List<SurfaceGesturePoint> list) |
|
29 |
{ |
|
30 |
this.Precision = 20; |
|
31 |
this.Generate(list); |
|
32 |
} |
|
33 |
/// <summary> |
|
34 |
/// load know patterns and generate the vector list from a list of points with a precision factor |
|
35 |
/// </summary> |
|
36 |
/// <param name="list"></param> |
|
37 |
/// <param name="precision"></param> |
|
38 |
public SurfaceGesture(List<SurfaceGesturePoint> list, int precision) |
|
39 |
{ |
|
209 | 40 |
this.Precision = 20; |
174 | 41 |
this.Generate(list); |
42 |
} |
|
43 |
#endregion |
|
176 | 44 |
|
174 | 45 |
#region GenerateVector |
46 |
/// <summary> |
|
47 |
/// Generate list of vector from courbe mouvements, filter with the pas value |
|
48 |
/// </summary> |
|
49 |
/// <param name="list"></param> |
|
50 |
/// <param name="pas"></param> |
|
51 |
/// <returns></returns> |
|
52 |
private bool GenerateCourb(List<SurfaceGesturePoint> list, int pas) |
|
53 |
{ |
|
54 |
int sep = list.Count / pas; |
|
55 |
double count = 0; ; |
|
56 |
SurfaceGesturePoint past = new SurfaceGesturePoint() { X = 0, Y = 0 }; |
|
57 |
double y = 0; |
|
58 |
||
59 |
for (int i = 0; i < list.Count - 1; i++) |
|
60 |
{ |
|
61 |
if (i % pas != 0) |
|
62 |
{ |
|
63 |
count += Math.Atan(list[i + 1].Y / list[i + 1].X) - Math.Atan(list[i].Y / list[i].X); |
|
64 |
} |
|
65 |
else |
|
66 |
{ |
|
67 |
count /= pas; |
|
68 |
if (count == 0 || this.GetDistancePoints(past, list[i + 1]) < 5) |
|
69 |
{ |
|
70 |
y = list[i + 1].Y; |
|
71 |
past.X = count; |
|
72 |
continue; |
|
73 |
} |
|
74 |
if (y > list[i + 1].Y) |
|
75 |
{ |
|
76 |
if (past.X > count) |
|
77 |
this.AddDirection(SurfaceGestureVectorDirection.UPRIGHT); |
|
78 |
else |
|
79 |
this.AddDirection(SurfaceGestureVectorDirection.UPLEFT); |
|
80 |
} |
|
81 |
else |
|
82 |
{ |
|
83 |
if (past.X > count) |
|
84 |
this.AddDirection(SurfaceGestureVectorDirection.DOWNRIGHT); |
|
85 |
else |
|
86 |
this.AddDirection(SurfaceGestureVectorDirection.DOWNLEFT); |
|
87 |
} |
|
88 |
y = list[i + 1].Y; |
|
89 |
past.X = count; |
|
90 |
} |
|
91 |
} |
|
92 |
Console.Write(this); |
|
176 | 93 |
/*if (this.GetPattern() != "None") |
174 | 94 |
return true; |
176 | 95 |
else*/ |
209 | 96 |
return false; |
174 | 97 |
} |
98 |
/// <summary> |
|
99 |
/// Get distance between two points |
|
100 |
/// </summary> |
|
101 |
/// <param name="p1"></param> |
|
102 |
/// <param name="p2"></param> |
|
103 |
/// <returns></returns> |
|
104 |
private int GetDistancePoints(SurfaceGesturePoint p1, SurfaceGesturePoint p2) |
|
105 |
{ |
|
106 |
return (int)Math.Sqrt(Math.Pow((p2.X - p1.X), 2) + Math.Pow((p1.Y - p2.Y), 2)); |
|
107 |
} |
|
108 |
/// <summary> |
|
109 |
/// add a direction in the vector list if past who not the same |
|
110 |
/// </summary> |
|
111 |
/// <param name="type"></param> |
|
112 |
private void AddDirection(SurfaceGestureVectorDirection type) |
|
113 |
{ |
|
114 |
if (this.Count == 0) |
|
115 |
{ |
|
176 | 116 |
this.Add(new SurfaceGestureVector { Direction = type, Lenght = 42 }); |
117 |
return; |
|
174 | 118 |
} |
119 |
if (this[this.Count - 1].Direction != type) |
|
120 |
this.Add(new SurfaceGestureVector { Direction = type, Lenght = 42 }); |
|
121 |
} |
|
122 |
/// <summary> |
|
123 |
/// generate list of vector |
|
124 |
/// </summary> |
|
125 |
/// <param name="list"></param> |
|
126 |
private void Generate(List<SurfaceGesturePoint> list) |
|
209 | 127 |
{ |
128 |
SurfaceGestureVectorDirection lastDirection = SurfaceGestureVectorDirection.NONE; |
|
129 |
int lastPoint = 0; |
|
130 |
SurfaceGesturePoint LastChange = list[0]; |
|
131 |
||
132 |
/////// TEST/////////// |
|
133 |
if (this.GenerateCourb(list, 5) == true) |
|
134 |
return; |
|
189 | 135 |
this.Clear(); |
209 | 136 |
/////////////////////// |
137 |
||
138 |
for (int i = 0; i < list.Count - 1; i++) |
|
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
139 |
{ |
209 | 140 |
if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UP && lastDirection != SurfaceGestureVectorDirection.UP) |
141 |
{ |
|
142 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
143 |
LastChange = list[i + 1]; |
|
144 |
lastDirection = SurfaceGestureVectorDirection.UP; |
|
145 |
} |
|
146 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWN && lastDirection != SurfaceGestureVectorDirection.DOWN) |
|
147 |
{ |
|
148 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
149 |
LastChange = list[i + 1]; |
|
150 |
lastDirection = SurfaceGestureVectorDirection.DOWN; |
|
151 |
} |
|
152 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT) |
|
153 |
{ |
|
154 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
155 |
LastChange = list[i + 1]; |
|
156 |
lastDirection = SurfaceGestureVectorDirection.UPLEFT; |
|
157 |
} |
|
158 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT) |
|
159 |
{ |
|
160 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
161 |
LastChange = list[i + 1]; |
|
162 |
lastDirection = SurfaceGestureVectorDirection.UPRIGHT; |
|
163 |
} |
|
164 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNLEFT && lastDirection != SurfaceGestureVectorDirection.DOWNLEFT) |
|
165 |
{ |
|
166 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
167 |
LastChange = list[i + 1]; |
|
168 |
lastDirection = SurfaceGestureVectorDirection.DOWNLEFT; |
|
169 |
} |
|
170 |
else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT) |
|
171 |
{ |
|
172 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
173 |
LastChange = list[i + 1]; |
|
174 |
lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT; |
|
175 |
} |
|
176 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.LEFT && lastDirection != SurfaceGestureVectorDirection.LEFT) |
|
177 |
{ |
|
178 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)), Origin = list[lastPoint] }); |
|
179 |
LastChange = list[i + 1]; |
|
180 |
lastDirection = SurfaceGestureVectorDirection.LEFT; |
|
181 |
} |
|
182 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.RIGHT && lastDirection != SurfaceGestureVectorDirection.RIGHT) |
|
183 |
{ |
|
184 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)), Origin = list[lastPoint] }); |
|
185 |
LastChange = list[i + 1]; |
|
186 |
lastDirection = SurfaceGestureVectorDirection.RIGHT; |
|
187 |
} |
|
188 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT) |
|
189 |
{ |
|
190 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
191 |
LastChange = list[i + 1]; |
|
192 |
lastDirection = SurfaceGestureVectorDirection.UPLEFT; |
|
193 |
} |
|
194 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT) |
|
195 |
{ |
|
196 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
197 |
LastChange = list[i + 1]; |
|
198 |
lastDirection = SurfaceGestureVectorDirection.UPRIGHT; |
|
199 |
} |
|
200 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNLEFT && lastDirection != SurfaceGestureVectorDirection.DOWNLEFT) |
|
201 |
{ |
|
202 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
203 |
LastChange = list[i + 1]; |
|
204 |
lastDirection = SurfaceGestureVectorDirection.DOWNLEFT; |
|
205 |
} |
|
206 |
else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT) |
|
207 |
{ |
|
208 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] }); |
|
209 |
LastChange = list[i + 1]; |
|
210 |
lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT; |
|
211 |
} |
|
212 |
++lastPoint; |
|
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
213 |
} |
174 | 214 |
|
209 | 215 |
// Analyse des extrémités de la gesture |
216 |
/* |
|
177
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
217 |
|
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
218 |
double diffX = Math.Abs(list[0].X - list[list.Count - 1].X); |
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
219 |
double diffY = Math.Abs(list[0].Y - list[list.Count - 1].Y); |
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
220 |
|
189 | 221 |
if (diffX < 10 && diffY > 10) |
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
222 |
{ |
209 | 223 |
this.Clear(); |
224 |
if (up > down) |
|
225 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up }); |
|
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
226 |
else |
209 | 227 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down }); |
189 | 228 |
} |
229 |
else if (diffY < 10 && diffX > 10) |
|
230 |
{ |
|
209 | 231 |
this.Clear(); |
232 |
if (left > right) |
|
233 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left }); |
|
189 | 234 |
else |
209 | 235 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right }); |
236 |
} |
|
237 |
||
238 |
*/ |
|
239 |
||
240 |
// Analyse détaillée de la gesture |
|
241 |
||
242 |
List<SurfaceGestureVector> ThisTemp = new List<SurfaceGestureVector>(); |
|
243 |
List<SurfaceGestureVector> temp = new List<SurfaceGestureVector>(); |
|
244 |
List<SurfaceGestureVector> Tempo = new List<SurfaceGestureVector>(); |
|
245 |
||
246 |
if ((this.Count / 10) >= 1) |
|
247 |
{ |
|
248 |
/* |
|
249 |
for (int i = 1; i < this.Count + 1; i++) |
|
250 |
{ |
|
251 |
temp.Add(this[i-1]); |
|
252 |
if (i % 7 == 0) |
|
253 |
{ |
|
254 |
SurfaceGestureVector result = Analyse(temp); |
|
255 |
if (ThisTemp.Count == 0 || !ThisTemp[ThisTemp.Count - 1].Direction.Equals(result.Direction)) |
|
256 |
ThisTemp.Add(result); |
|
257 |
else |
|
258 |
ThisTemp[ThisTemp.Count - 1].Lenght += result.Lenght; |
|
259 |
temp.Clear(); |
|
260 |
} |
|
261 |
} |
|
262 |
if (temp.Count > 0) |
|
263 |
{ |
|
264 |
SurfaceGestureVector result = Analyse(temp); |
|
265 |
if (ThisTemp[ThisTemp.Count - 1].Direction.Equals(result.Direction)) |
|
266 |
ThisTemp[ThisTemp.Count - 1].Lenght += result.Lenght; |
|
267 |
else |
|
268 |
ThisTemp.Add(result); |
|
269 |
temp.Clear(); |
|
270 |
} |
|
271 |
this.Clear(); |
|
272 |
foreach(SurfaceGestureVector elt in ThisTemp) |
|
273 |
this.Add(elt); |
|
274 |
*/ |
|
275 |
switch (this.Count / 10) |
|
276 |
{ |
|
277 |
case 1: |
|
278 |
ThisTemp.Add(Analyse(this)); |
|
279 |
this.Clear(); |
|
280 |
if (ThisTemp.Count > 1) |
|
281 |
{ |
|
282 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0; |
|
283 |
foreach (SurfaceGestureVector elt in ThisTemp) |
|
284 |
{ |
|
285 |
switch (elt.Direction) |
|
286 |
{ |
|
287 |
case SurfaceGestureVectorDirection.DOWN: |
|
288 |
down += elt.Lenght; |
|
289 |
break; |
|
290 |
case SurfaceGestureVectorDirection.DOWNLEFT: |
|
291 |
downleft += elt.Lenght; |
|
292 |
break; |
|
293 |
case SurfaceGestureVectorDirection.DOWNRIGHT: |
|
294 |
downright += elt.Lenght; |
|
295 |
break; |
|
296 |
case SurfaceGestureVectorDirection.LEFT: |
|
297 |
left += elt.Lenght; |
|
298 |
break; |
|
299 |
case SurfaceGestureVectorDirection.RIGHT: |
|
300 |
right += elt.Lenght; |
|
301 |
break; |
|
302 |
case SurfaceGestureVectorDirection.UP: |
|
303 |
up += elt.Lenght; |
|
304 |
break; |
|
305 |
case SurfaceGestureVectorDirection.UPLEFT: |
|
306 |
upleft += elt.Lenght; |
|
307 |
break; |
|
308 |
case SurfaceGestureVectorDirection.UPRIGHT: |
|
309 |
upright += elt.Lenght; |
|
310 |
break; |
|
311 |
default: |
|
312 |
break; |
|
313 |
} |
|
314 |
} |
|
315 |
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)) |
|
316 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null }); |
|
317 |
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)) |
|
318 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null }); |
|
319 |
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)) |
|
320 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null }); |
|
321 |
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)) |
|
322 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null }); |
|
323 |
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)) |
|
324 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null }); |
|
325 |
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)) |
|
326 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null }); |
|
327 |
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)) |
|
328 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null }); |
|
329 |
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)) |
|
330 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null }); |
|
331 |
} |
|
332 |
else |
|
333 |
this.Add(ThisTemp[0]); |
|
334 |
break; |
|
335 |
case 2: |
|
336 |
for (int index = 1; index <= this.Count; index++) |
|
337 |
{ |
|
338 |
if (index == this.Count / 2 || index == this.Count) |
|
339 |
{ |
|
340 |
ThisTemp.Add(Analyse(temp)); |
|
341 |
if (ThisTemp.Count > 1) |
|
342 |
{ |
|
343 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0; |
|
344 |
foreach (SurfaceGestureVector elt in ThisTemp) |
|
345 |
{ |
|
346 |
||
347 |
switch (elt.Direction) |
|
348 |
{ |
|
349 |
case SurfaceGestureVectorDirection.DOWN: |
|
350 |
down += elt.Lenght; |
|
351 |
break; |
|
352 |
case SurfaceGestureVectorDirection.DOWNLEFT: |
|
353 |
downleft += elt.Lenght; |
|
354 |
break; |
|
355 |
case SurfaceGestureVectorDirection.DOWNRIGHT: |
|
356 |
downright += elt.Lenght; |
|
357 |
break; |
|
358 |
case SurfaceGestureVectorDirection.LEFT: |
|
359 |
left += elt.Lenght; |
|
360 |
break; |
|
361 |
case SurfaceGestureVectorDirection.RIGHT: |
|
362 |
right += elt.Lenght; |
|
363 |
break; |
|
364 |
case SurfaceGestureVectorDirection.UP: |
|
365 |
up += elt.Lenght; |
|
366 |
break; |
|
367 |
case SurfaceGestureVectorDirection.UPLEFT: |
|
368 |
upleft += elt.Lenght; |
|
369 |
break; |
|
370 |
case SurfaceGestureVectorDirection.UPRIGHT: |
|
371 |
upright += elt.Lenght; |
|
372 |
break; |
|
373 |
} |
|
374 |
} |
|
375 |
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)) |
|
376 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null }); |
|
377 |
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)) |
|
378 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null }); |
|
379 |
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)) |
|
380 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null }); |
|
381 |
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)) |
|
382 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null }); |
|
383 |
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)) |
|
384 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null }); |
|
385 |
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)) |
|
386 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null }); |
|
387 |
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)) |
|
388 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null }); |
|
389 |
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)) |
|
390 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null }); |
|
391 |
} |
|
392 |
else |
|
393 |
Tempo.Add(ThisTemp[0]); |
|
394 |
} |
|
395 |
else |
|
396 |
ThisTemp.Add(this[index]); |
|
397 |
} |
|
398 |
this.Clear(); |
|
399 |
if (Tempo[0].Direction.Equals(Tempo[1].Direction)) |
|
400 |
this.Add(Tempo[0]); |
|
401 |
else |
|
402 |
foreach (SurfaceGestureVector elt in Tempo) |
|
403 |
this.Add(elt); |
|
404 |
break; |
|
405 |
case 3: |
|
406 |
for (int index = 1; index <= this.Count; index++) |
|
407 |
{ |
|
408 |
if (index == this.Count / 3 || index == this.Count) |
|
409 |
{ |
|
410 |
ThisTemp.Add(Analyse(temp)); |
|
411 |
if (ThisTemp.Count > 1) |
|
412 |
{ |
|
413 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0; |
|
414 |
foreach (SurfaceGestureVector elt in ThisTemp) |
|
415 |
{ |
|
416 |
||
417 |
switch (elt.Direction) |
|
418 |
{ |
|
419 |
case SurfaceGestureVectorDirection.DOWN: |
|
420 |
down += elt.Lenght; |
|
421 |
break; |
|
422 |
case SurfaceGestureVectorDirection.DOWNLEFT: |
|
423 |
downleft += elt.Lenght; |
|
424 |
break; |
|
425 |
case SurfaceGestureVectorDirection.DOWNRIGHT: |
|
426 |
downright += elt.Lenght; |
|
427 |
break; |
|
428 |
case SurfaceGestureVectorDirection.LEFT: |
|
429 |
left += elt.Lenght; |
|
430 |
break; |
|
431 |
case SurfaceGestureVectorDirection.RIGHT: |
|
432 |
right += elt.Lenght; |
|
433 |
break; |
|
434 |
case SurfaceGestureVectorDirection.UP: |
|
435 |
up += elt.Lenght; |
|
436 |
break; |
|
437 |
case SurfaceGestureVectorDirection.UPLEFT: |
|
438 |
upleft += elt.Lenght; |
|
439 |
break; |
|
440 |
case SurfaceGestureVectorDirection.UPRIGHT: |
|
441 |
upright += elt.Lenght; |
|
442 |
break; |
|
443 |
} |
|
444 |
} |
|
445 |
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)) |
|
446 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null }); |
|
447 |
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)) |
|
448 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null }); |
|
449 |
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)) |
|
450 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null }); |
|
451 |
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)) |
|
452 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null }); |
|
453 |
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)) |
|
454 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null }); |
|
455 |
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)) |
|
456 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null }); |
|
457 |
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)) |
|
458 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null }); |
|
459 |
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)) |
|
460 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null }); |
|
461 |
} |
|
462 |
else |
|
463 |
Tempo.Add(ThisTemp[0]); |
|
464 |
} |
|
465 |
else |
|
466 |
ThisTemp.Add(this[index]); |
|
467 |
} |
|
468 |
this.Clear(); |
|
469 |
if (Tempo[0].Direction.Equals(Tempo[1].Direction) && Tempo[0].Direction.Equals(Tempo[2].Direction)) |
|
470 |
this.Add(Tempo[0]); |
|
471 |
else |
|
472 |
foreach (SurfaceGestureVector elt in Tempo) |
|
473 |
this.Add(elt); |
|
474 |
break; |
|
475 |
default: |
|
476 |
for (int index = 1; index <= this.Count; index++) |
|
477 |
{ |
|
478 |
if (index == this.Count / 4 || index == this.Count) |
|
479 |
{ |
|
480 |
ThisTemp.Add(Analyse(temp)); |
|
481 |
if (ThisTemp.Count > 1) |
|
482 |
{ |
|
483 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0; |
|
484 |
foreach (SurfaceGestureVector elt in ThisTemp) |
|
485 |
{ |
|
486 |
||
487 |
switch (elt.Direction) |
|
488 |
{ |
|
489 |
case SurfaceGestureVectorDirection.DOWN: |
|
490 |
down += elt.Lenght; |
|
491 |
break; |
|
492 |
case SurfaceGestureVectorDirection.DOWNLEFT: |
|
493 |
downleft += elt.Lenght; |
|
494 |
break; |
|
495 |
case SurfaceGestureVectorDirection.DOWNRIGHT: |
|
496 |
downright += elt.Lenght; |
|
497 |
break; |
|
498 |
case SurfaceGestureVectorDirection.LEFT: |
|
499 |
left += elt.Lenght; |
|
500 |
break; |
|
501 |
case SurfaceGestureVectorDirection.RIGHT: |
|
502 |
right += elt.Lenght; |
|
503 |
break; |
|
504 |
case SurfaceGestureVectorDirection.UP: |
|
505 |
up += elt.Lenght; |
|
506 |
break; |
|
507 |
case SurfaceGestureVectorDirection.UPLEFT: |
|
508 |
upleft += elt.Lenght; |
|
509 |
break; |
|
510 |
case SurfaceGestureVectorDirection.UPRIGHT: |
|
511 |
upright += elt.Lenght; |
|
512 |
break; |
|
513 |
} |
|
514 |
} |
|
515 |
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)) |
|
516 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null }); |
|
517 |
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)) |
|
518 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null }); |
|
519 |
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)) |
|
520 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null }); |
|
521 |
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)) |
|
522 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null }); |
|
523 |
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)) |
|
524 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null }); |
|
525 |
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)) |
|
526 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null }); |
|
527 |
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)) |
|
528 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null }); |
|
529 |
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)) |
|
530 |
Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null }); |
|
531 |
} |
|
532 |
else |
|
533 |
Tempo.Add(ThisTemp[0]); |
|
534 |
} |
|
535 |
else |
|
536 |
ThisTemp.Add(this[index]); |
|
537 |
} |
|
538 |
this.Clear(); |
|
539 |
if (Tempo[0].Direction.Equals(Tempo[1].Direction) && Tempo[0].Direction.Equals(Tempo[2].Direction) && Tempo[0].Direction.Equals(Tempo[3].Direction)) |
|
540 |
this.Add(Tempo[0]); |
|
541 |
else |
|
542 |
foreach (SurfaceGestureVector elt in Tempo) |
|
543 |
this.Add(elt); |
|
544 |
break; |
|
545 |
} |
|
546 |
} |
|
547 |
else |
|
548 |
{ |
|
549 |
ThisTemp.Add(Analyse(this)); |
|
550 |
this.Clear(); |
|
551 |
if (ThisTemp.Count > 1) |
|
552 |
{ |
|
553 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0; |
|
554 |
foreach (SurfaceGestureVector elt in ThisTemp) |
|
555 |
{ |
|
556 |
||
557 |
switch (elt.Direction) |
|
558 |
{ |
|
559 |
case SurfaceGestureVectorDirection.DOWN: |
|
560 |
down += elt.Lenght; |
|
561 |
break; |
|
562 |
case SurfaceGestureVectorDirection.DOWNLEFT: |
|
563 |
downleft += elt.Lenght; |
|
564 |
break; |
|
565 |
case SurfaceGestureVectorDirection.DOWNRIGHT: |
|
566 |
downright += elt.Lenght; |
|
567 |
break; |
|
568 |
case SurfaceGestureVectorDirection.LEFT: |
|
569 |
left += elt.Lenght; |
|
570 |
break; |
|
571 |
case SurfaceGestureVectorDirection.RIGHT: |
|
572 |
right += elt.Lenght; |
|
573 |
break; |
|
574 |
case SurfaceGestureVectorDirection.UP: |
|
575 |
up += elt.Lenght; |
|
576 |
break; |
|
577 |
case SurfaceGestureVectorDirection.UPLEFT: |
|
578 |
upleft += elt.Lenght; |
|
579 |
break; |
|
580 |
case SurfaceGestureVectorDirection.UPRIGHT: |
|
581 |
upright += elt.Lenght; |
|
582 |
break; |
|
583 |
} |
|
584 |
} |
|
585 |
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)) |
|
586 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null }); |
|
587 |
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)) |
|
588 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null }); |
|
589 |
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)) |
|
590 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null }); |
|
591 |
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)) |
|
592 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null }); |
|
593 |
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)) |
|
594 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null }); |
|
595 |
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)) |
|
596 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null }); |
|
597 |
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)) |
|
598 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null }); |
|
599 |
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)) |
|
600 |
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null }); |
|
601 |
} |
|
602 |
else |
|
603 |
this.Add(ThisTemp[0]); |
|
604 |
} |
|
605 |
} |
|
606 |
||
607 |
private SurfaceGestureVector Analyse(List<SurfaceGestureVector> list) |
|
608 |
{ |
|
609 |
// Analyse de la forme |
|
610 |
|
|
611 |
double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0; |
|
612 |
foreach (SurfaceGestureVector elt in list) |
|
613 |
{ |
|
614 |
||
615 |
switch (elt.Direction) |
|
616 |
{ |
|
617 |
case SurfaceGestureVectorDirection.DOWN: |
|
618 |
down += elt.Lenght; |
|
619 |
break; |
|
620 |
case SurfaceGestureVectorDirection.DOWNLEFT: |
|
621 |
downleft += elt.Lenght; |
|
622 |
break; |
|
623 |
case SurfaceGestureVectorDirection.DOWNRIGHT: |
|
624 |
downright += elt.Lenght; |
|
625 |
break; |
|
626 |
case SurfaceGestureVectorDirection.LEFT: |
|
627 |
left += elt.Lenght; |
|
628 |
break; |
|
629 |
case SurfaceGestureVectorDirection.RIGHT: |
|
630 |
right += elt.Lenght; |
|
631 |
break; |
|
632 |
case SurfaceGestureVectorDirection.UP: |
|
633 |
up += elt.Lenght; |
|
634 |
break; |
|
635 |
case SurfaceGestureVectorDirection.UPLEFT: |
|
636 |
upleft += elt.Lenght; |
|
637 |
break; |
|
638 |
case SurfaceGestureVectorDirection.UPRIGHT: |
|
639 |
upright += elt.Lenght; |
|
640 |
break; |
|
641 |
} |
|
642 |
} |
|
643 |
/* |
|
644 |
//double cupleft = 0, cupright = 0, cdownleft = 0, cdownright = 0; |
|
645 |
||
646 |
|
|
647 |
if (list.Count > 2) |
|
648 |
{ |
|
649 |
double min = 180; |
|
650 |
for (int i = 1; i < list.Count - 2; i++) |
|
651 |
{ |
|
652 |
double a = GetDistancePoints(list[list.Count - 1].Origin, list[0].Origin); |
|
653 |
double b = GetDistancePoints(list[i].Origin, list[0].Origin); |
|
654 |
double c = GetDistancePoints(list[i].Origin, list[list.Count - 1].Origin); |
|
655 |
double angle = 180 * (Math.Acos((b * b + c * c - a * a) / (2 * b * c))) / Math.PI ; |
|
656 |
min = Math.Min(angle > 0 ? angle : 180, min); |
|
657 |
} |
|
658 |
if(min<130) |
|
659 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.NONE, Lenght = up, Origin = list[0].Origin }; |
|
660 |
} |
|
661 |
||
662 |
if (up < 4 && upleft < 4 && upright < 4 && down < 4 && downleft < 4 && downright < 4 && right < 4 && left < 4) |
|
663 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 }; |
|
664 |
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)) |
|
665 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = list[0].Origin }; |
|
666 |
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)) |
|
667 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = list[0].Origin }; |
|
668 |
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)) |
|
669 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin }; |
|
670 |
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)) |
|
671 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = list[0].Origin }; |
|
672 |
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)) |
|
673 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = list[0].Origin }; |
|
674 |
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)) |
|
675 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = list[0].Origin }; |
|
676 |
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)) |
|
677 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = list[0].Origin }; |
|
678 |
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)) |
|
679 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = list[0].Origin }; |
|
680 |
else |
|
681 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.NONE, Lenght = 0, Origin = list[0].Origin }); |
|
682 |
*/ |
|
683 |
||
684 |
double diffX = Math.Abs(list[0].Origin.X - list[list.Count - 1].Origin.X); |
|
685 |
double diffY = Math.Abs(list[0].Origin.Y - list[list.Count - 1].Origin.Y); |
|
686 |
||
687 |
if (diffX < 10 && diffY > 10) |
|
688 |
{ |
|
689 |
if (list[0].Origin.Y > list[list.Count - 1].Origin.Y) |
|
690 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = list[0].Origin }); |
|
691 |
else |
|
692 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = list[0].Origin }); |
|
693 |
} |
|
694 |
else if (diffY < 10 && diffX > 10) |
|
695 |
{ |
|
696 |
if (list[list.Count - 1].Origin.X > list[0].Origin.X) |
|
697 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = list[0].Origin }); |
|
698 |
else |
|
699 |
return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = list[0].Origin }); |
|
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
700 |
} |
189 | 701 |
else if (diffX > 10 && diffY > 10) |
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
702 |
{ |
209 | 703 |
if (list[0].Origin.Y > list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X > list[0].Origin.X) |
704 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = list[0].Origin }; |
|
705 |
else if (list[0].Origin.Y > list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X < list[0].Origin.X) |
|
706 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin }; |
|
707 |
else if (list[0].Origin.Y < list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X > list[0].Origin.X) |
|
708 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = list[0].Origin }; |
|
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
709 |
else |
209 | 710 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin }; |
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
711 |
} |
189 | 712 |
else |
713 |
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 }; |
|
174 | 714 |
} |
178
56041bd3761e
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
177
diff
changeset
|
715 |
|
174 | 716 |
private SurfaceGestureVectorDirection GetHorizontal(SurfaceGesturePoint p1, SurfaceGesturePoint p2) |
717 |
{ |
|
718 |
if (p1.Y < p2.Y) |
|
719 |
{ |
|
720 |
// go up |
|
209 | 721 |
if (Math.Abs(p2.Y - p1.Y) > this.Precision) |
177
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
722 |
{ |
209 | 723 |
if (Math.Abs(p2.X - p1.X) < Math.Abs(p2.Y - p1.Y)) |
724 |
return SurfaceGestureVectorDirection.DOWN; |
|
177
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
725 |
else |
209 | 726 |
{ |
727 |
if (p1.X < p2.X) |
|
728 |
return SurfaceGestureVectorDirection.DOWNRIGHT; |
|
729 |
else |
|
730 |
return SurfaceGestureVectorDirection.DOWNLEFT; |
|
731 |
} |
|
177
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
732 |
} |
209 | 733 |
else |
734 |
{ |
|
735 |
if (p1.X < p2.X) |
|
736 |
return SurfaceGestureVectorDirection.DOWNRIGHT; |
|
737 |
else |
|
738 |
return SurfaceGestureVectorDirection.DOWNLEFT; |
|
739 |
} |
|
174 | 740 |
} |
741 |
else |
|
742 |
{ |
|
743 |
// go down |
|
209 | 744 |
if (Math.Abs(p1.Y - p2.Y) > this.Precision) |
745 |
{ |
|
746 |
if (Math.Abs(p1.X - p2.X) < Math.Abs(p1.Y - p2.Y)) |
|
747 |
return SurfaceGestureVectorDirection.UP; |
|
748 |
else |
|
749 |
{ |
|
750 |
if (p1.X < p2.X) |
|
751 |
return SurfaceGestureVectorDirection.UPRIGHT; |
|
752 |
else |
|
753 |
return SurfaceGestureVectorDirection.UPLEFT; |
|
754 |
} |
|
755 |
} |
|
177
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
756 |
else |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
757 |
{ |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
758 |
if (p1.X < p2.X) |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
759 |
return SurfaceGestureVectorDirection.UPRIGHT; |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
760 |
else |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
761 |
return SurfaceGestureVectorDirection.UPLEFT; |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
762 |
} |
174 | 763 |
} |
764 |
} |
|
189 | 765 |
|
174 | 766 |
private SurfaceGestureVectorDirection GetVertical(SurfaceGesturePoint p1, SurfaceGesturePoint p2) |
767 |
{ |
|
768 |
if (p1.X < p2.X) |
|
769 |
{ |
|
770 |
// go left |
|
209 | 771 |
if (Math.Abs(p2.X - p1.X) > this.Precision) |
772 |
{ |
|
773 |
if (Math.Abs(p2.Y - p1.Y) < Math.Abs(p2.X - p1.X)) |
|
774 |
return SurfaceGestureVectorDirection.RIGHT; |
|
775 |
else |
|
776 |
{ |
|
777 |
if (p1.Y < p2.Y) |
|
778 |
return SurfaceGestureVectorDirection.DOWNRIGHT; |
|
779 |
else |
|
780 |
return SurfaceGestureVectorDirection.UPRIGHT; |
|
781 |
} |
|
782 |
} |
|
177
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
783 |
else |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
784 |
{ |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
785 |
if (p1.Y < p2.Y) |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
786 |
return SurfaceGestureVectorDirection.DOWNRIGHT; |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
787 |
else |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
788 |
return SurfaceGestureVectorDirection.UPRIGHT; |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
789 |
} |
174 | 790 |
} |
791 |
else |
|
792 |
{ |
|
209 | 793 |
// go right |
794 |
if (Math.Abs(p1.X - p2.X) > this.Precision) |
|
795 |
{ |
|
796 |
if (Math.Abs(p1.Y - p2.Y) < Math.Abs(p1.X - p2.X)) |
|
797 |
return SurfaceGestureVectorDirection.LEFT; |
|
798 |
else |
|
799 |
{ |
|
800 |
if (p1.Y < p2.Y) |
|
801 |
return SurfaceGestureVectorDirection.DOWNLEFT; |
|
802 |
else |
|
803 |
return SurfaceGestureVectorDirection.UPLEFT; |
|
804 |
} |
|
805 |
} |
|
177
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
806 |
else |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
807 |
{ |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
808 |
if (p1.Y < p2.Y) |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
809 |
return SurfaceGestureVectorDirection.DOWNLEFT; |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
810 |
else |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
811 |
return SurfaceGestureVectorDirection.UPLEFT; |
89cbcb52b674
Mise en place de la reconnaissance de formes
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
176
diff
changeset
|
812 |
} |
174 | 813 |
} |
814 |
} |
|
189 | 815 |
|
174 | 816 |
#endregion |
176 | 817 |
|
174 | 818 |
#region Override |
819 |
public override String ToString() |
|
820 |
{ |
|
821 |
String ret = ""; |
|
822 |
||
823 |
foreach (SurfaceGestureVector v in this) |
|
824 |
{ |
|
825 |
ret += (v.Direction + ", lenght:" + v.Lenght + ", precision:" + this.Precision + "\n"); |
|
826 |
//Console.WriteLine(v.Direction + ", lenght:" + v.Lenght + ", precision:" + this.Precision); |
|
827 |
} |
|
828 |
return ret; |
|
829 |
} |
|
830 |
#endregion |
|
831 |
} |
|
832 |
} |