--- a/src/FingersDance.GestureControl/GestureVector.cs Thu Nov 19 18:37:26 2009 +0100
+++ b/src/FingersDance.GestureControl/GestureVector.cs Thu Nov 19 18:05:52 2009 +0100
@@ -37,7 +37,7 @@
/// <param name="precision"></param>
public SurfaceGesture(List<SurfaceGesturePoint> list, int precision)
{
- this.Precision = 20;
+ this.Precision = precision;
this.Generate(list);
}
#endregion
@@ -124,590 +124,62 @@
/// </summary>
/// <param name="list"></param>
private void Generate(List<SurfaceGesturePoint> list)
- {
- SurfaceGestureVectorDirection lastDirection = SurfaceGestureVectorDirection.NONE;
- int lastPoint = 0;
- SurfaceGesturePoint LastChange = list[0];
-
- /////// TEST///////////
- if (this.GenerateCourb(list, 5) == true)
- return;
+ {
this.Clear();
- ///////////////////////
-
- for (int i = 0; i < list.Count - 1; i++)
+ if (list.Count < 2)
{
- if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UP && lastDirection != SurfaceGestureVectorDirection.UP)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.UP;
- }
- else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWN && lastDirection != SurfaceGestureVectorDirection.DOWN)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.DOWN;
- }
- else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.UPLEFT;
- }
- else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.UPRIGHT;
- }
- else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNLEFT && lastDirection != SurfaceGestureVectorDirection.DOWNLEFT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.DOWNLEFT;
- }
- else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT;
- }
- else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.LEFT && lastDirection != SurfaceGestureVectorDirection.LEFT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.LEFT;
- }
- else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.RIGHT && lastDirection != SurfaceGestureVectorDirection.RIGHT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.RIGHT;
- }
- else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.UPLEFT;
- }
- else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.UPRIGHT;
- }
- else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNLEFT && lastDirection != SurfaceGestureVectorDirection.DOWNLEFT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.DOWNLEFT;
- }
- else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT)
- {
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT;
- }
- ++lastPoint;
+ this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 });
+ return;
}
- // Analyse des extrémités de la gesture
- /*
+ List<SurfaceGesturePoint> Points = new List<SurfaceGesturePoint>();
+ List<SurfaceGestureVector> Vectors = new List<SurfaceGestureVector>();
+ for (int index = 1; index <= list.Count; index++)
+ {
+ if (index == list.Count / 2 || index == list.Count)
+ {
+ SurfaceGestureVector verctorTemp = AnalysePoints(Points);
+ if (Vectors.Count == 0 || !Vectors[Vectors.Count - 1].Direction.Equals(verctorTemp.Direction))
+ Vectors.Add(verctorTemp);
+ Points.Clear();
+ }
+ else
+ Points.Add(list[index]);
+ }
+ foreach (SurfaceGestureVector elt in Vectors)
+ this.Add(elt);
+ }
+
+ SurfaceGestureVector AnalysePoints(List<SurfaceGesturePoint> list)
+ {
double diffX = Math.Abs(list[0].X - list[list.Count - 1].X);
double diffY = Math.Abs(list[0].Y - list[list.Count - 1].Y);
if (diffX < 10 && diffY > 10)
{
- this.Clear();
- if (up > down)
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up });
+ if (list[0].Y > list[list.Count - 1].Y)
+ return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = 0, Origin = list[0] });
else
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down });
+ return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = 0, Origin = list[0] });
}
else if (diffY < 10 && diffX > 10)
{
- this.Clear();
- if (left > right)
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left });
+ if (list[list.Count - 1].X > list[0].X)
+ return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = 0, Origin = list[0] });
else
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right });
- }
-
- */
-
- // Analyse détaillée de la gesture
-
- List<SurfaceGestureVector> ThisTemp = new List<SurfaceGestureVector>();
- List<SurfaceGestureVector> temp = new List<SurfaceGestureVector>();
- List<SurfaceGestureVector> Tempo = new List<SurfaceGestureVector>();
-
- if ((this.Count / 10) >= 1)
- {
- /*
- for (int i = 1; i < this.Count + 1; i++)
- {
- temp.Add(this[i-1]);
- if (i % 7 == 0)
- {
- SurfaceGestureVector result = Analyse(temp);
- if (ThisTemp.Count == 0 || !ThisTemp[ThisTemp.Count - 1].Direction.Equals(result.Direction))
- ThisTemp.Add(result);
- else
- ThisTemp[ThisTemp.Count - 1].Lenght += result.Lenght;
- temp.Clear();
- }
- }
- if (temp.Count > 0)
- {
- SurfaceGestureVector result = Analyse(temp);
- if (ThisTemp[ThisTemp.Count - 1].Direction.Equals(result.Direction))
- ThisTemp[ThisTemp.Count - 1].Lenght += result.Lenght;
- else
- ThisTemp.Add(result);
- temp.Clear();
- }
- this.Clear();
- foreach(SurfaceGestureVector elt in ThisTemp)
- this.Add(elt);
- */
- switch (this.Count / 10)
- {
- case 1:
- ThisTemp.Add(Analyse(this));
- this.Clear();
- if (ThisTemp.Count > 1)
- {
- double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
- foreach (SurfaceGestureVector elt in ThisTemp)
- {
- switch (elt.Direction)
- {
- case SurfaceGestureVectorDirection.DOWN:
- down += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNLEFT:
- downleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNRIGHT:
- downright += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.LEFT:
- left += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.RIGHT:
- right += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UP:
- up += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPLEFT:
- upleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPRIGHT:
- upright += elt.Lenght;
- break;
- default:
- break;
- }
- }
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
- }
- else
- this.Add(ThisTemp[0]);
- break;
- case 2:
- for (int index = 1; index <= this.Count; index++)
- {
- if (index == this.Count / 2 || index == this.Count)
- {
- ThisTemp.Add(Analyse(temp));
- if (ThisTemp.Count > 1)
- {
- double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
- foreach (SurfaceGestureVector elt in ThisTemp)
- {
-
- switch (elt.Direction)
- {
- case SurfaceGestureVectorDirection.DOWN:
- down += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNLEFT:
- downleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNRIGHT:
- downright += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.LEFT:
- left += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.RIGHT:
- right += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UP:
- up += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPLEFT:
- upleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPRIGHT:
- upright += elt.Lenght;
- break;
- }
- }
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
- }
- else
- Tempo.Add(ThisTemp[0]);
- }
- else
- ThisTemp.Add(this[index]);
- }
- this.Clear();
- if (Tempo[0].Direction.Equals(Tempo[1].Direction))
- this.Add(Tempo[0]);
- else
- foreach (SurfaceGestureVector elt in Tempo)
- this.Add(elt);
- break;
- case 3:
- for (int index = 1; index <= this.Count; index++)
- {
- if (index == this.Count / 3 || index == this.Count)
- {
- ThisTemp.Add(Analyse(temp));
- if (ThisTemp.Count > 1)
- {
- double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
- foreach (SurfaceGestureVector elt in ThisTemp)
- {
-
- switch (elt.Direction)
- {
- case SurfaceGestureVectorDirection.DOWN:
- down += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNLEFT:
- downleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNRIGHT:
- downright += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.LEFT:
- left += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.RIGHT:
- right += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UP:
- up += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPLEFT:
- upleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPRIGHT:
- upright += elt.Lenght;
- break;
- }
- }
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
- }
- else
- Tempo.Add(ThisTemp[0]);
- }
- else
- ThisTemp.Add(this[index]);
- }
- this.Clear();
- if (Tempo[0].Direction.Equals(Tempo[1].Direction) && Tempo[0].Direction.Equals(Tempo[2].Direction))
- this.Add(Tempo[0]);
- else
- foreach (SurfaceGestureVector elt in Tempo)
- this.Add(elt);
- break;
- default:
- for (int index = 1; index <= this.Count; index++)
- {
- if (index == this.Count / 4 || index == this.Count)
- {
- ThisTemp.Add(Analyse(temp));
- if (ThisTemp.Count > 1)
- {
- double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
- foreach (SurfaceGestureVector elt in ThisTemp)
- {
-
- switch (elt.Direction)
- {
- case SurfaceGestureVectorDirection.DOWN:
- down += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNLEFT:
- downleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNRIGHT:
- downright += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.LEFT:
- left += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.RIGHT:
- right += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UP:
- up += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPLEFT:
- upleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPRIGHT:
- upright += elt.Lenght;
- break;
- }
- }
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
- 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))
- Tempo.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
- }
- else
- Tempo.Add(ThisTemp[0]);
- }
- else
- ThisTemp.Add(this[index]);
- }
- this.Clear();
- if (Tempo[0].Direction.Equals(Tempo[1].Direction) && Tempo[0].Direction.Equals(Tempo[2].Direction) && Tempo[0].Direction.Equals(Tempo[3].Direction))
- this.Add(Tempo[0]);
- else
- foreach (SurfaceGestureVector elt in Tempo)
- this.Add(elt);
- break;
- }
- }
- else
- {
- ThisTemp.Add(Analyse(this));
- this.Clear();
- if (ThisTemp.Count > 1)
- {
- double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
- foreach (SurfaceGestureVector elt in ThisTemp)
- {
-
- switch (elt.Direction)
- {
- case SurfaceGestureVectorDirection.DOWN:
- down += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNLEFT:
- downleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNRIGHT:
- downright += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.LEFT:
- left += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.RIGHT:
- right += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UP:
- up += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPLEFT:
- upleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPRIGHT:
- upright += elt.Lenght;
- break;
- }
- }
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = null });
- 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))
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = null });
- }
- else
- this.Add(ThisTemp[0]);
- }
- }
-
- private SurfaceGestureVector Analyse(List<SurfaceGestureVector> list)
- {
- // Analyse de la forme
-
- double up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
- foreach (SurfaceGestureVector elt in list)
- {
-
- switch (elt.Direction)
- {
- case SurfaceGestureVectorDirection.DOWN:
- down += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNLEFT:
- downleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.DOWNRIGHT:
- downright += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.LEFT:
- left += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.RIGHT:
- right += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UP:
- up += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPLEFT:
- upleft += elt.Lenght;
- break;
- case SurfaceGestureVectorDirection.UPRIGHT:
- upright += elt.Lenght;
- break;
- }
- }
- /*
- //double cupleft = 0, cupright = 0, cdownleft = 0, cdownright = 0;
-
-
- if (list.Count > 2)
- {
- double min = 180;
- for (int i = 1; i < list.Count - 2; i++)
- {
- double a = GetDistancePoints(list[list.Count - 1].Origin, list[0].Origin);
- double b = GetDistancePoints(list[i].Origin, list[0].Origin);
- double c = GetDistancePoints(list[i].Origin, list[list.Count - 1].Origin);
- double angle = 180 * (Math.Acos((b * b + c * c - a * a) / (2 * b * c))) / Math.PI ;
- min = Math.Min(angle > 0 ? angle : 180, min);
- }
- if(min<130)
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.NONE, Lenght = up, Origin = list[0].Origin };
- }
-
- if (up < 4 && upleft < 4 && upright < 4 && down < 4 && downleft < 4 && downright < 4 && right < 4 && left < 4)
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 };
- 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))
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = list[0].Origin };
- 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))
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = list[0].Origin };
- 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))
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin };
- 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))
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = list[0].Origin };
- 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))
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = list[0].Origin };
- 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))
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = downright, Origin = list[0].Origin };
- 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))
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = list[0].Origin };
- 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))
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = list[0].Origin };
- else
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.NONE, Lenght = 0, Origin = list[0].Origin });
- */
-
- double diffX = Math.Abs(list[0].Origin.X - list[list.Count - 1].Origin.X);
- double diffY = Math.Abs(list[0].Origin.Y - list[list.Count - 1].Origin.Y);
-
- if (diffX < 10 && diffY > 10)
- {
- if (list[0].Origin.Y > list[list.Count - 1].Origin.Y)
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up, Origin = list[0].Origin });
- else
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down, Origin = list[0].Origin });
- }
- else if (diffY < 10 && diffX > 10)
- {
- if (list[list.Count - 1].Origin.X > list[0].Origin.X)
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left, Origin = list[0].Origin });
- else
- return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right, Origin = list[0].Origin });
+ return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = 0, Origin = list[0] });
}
else if (diffX > 10 && diffY > 10)
{
- if (list[0].Origin.Y > list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X > list[0].Origin.X)
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = list[0].Origin };
- else if (list[0].Origin.Y > list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X < list[0].Origin.X)
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin };
- else if (list[0].Origin.Y < list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X > list[0].Origin.X)
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = list[0].Origin };
+ if (list[0].Y > list[list.Count - 1].Y && list[list.Count - 1].X > list[0].X)
+ return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = 0, Origin = list[0] };
+ else if (list[0].Y > list[list.Count - 1].Y && list[list.Count - 1].X < list[0].X)
+ return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = 0, Origin = list[0] };
+ else if (list[0].Y < list[list.Count - 1].Y && list[list.Count - 1].X > list[0].X)
+ return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = 0, Origin = list[0] };
else
- return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin };
+ return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = 0, Origin = list[0] };
}
else
return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 };
@@ -718,41 +190,21 @@
if (p1.Y < p2.Y)
{
// go up
- if (Math.Abs(p2.Y - p1.Y) > this.Precision)
+ if (Math.Abs(p2.X - p1.X) < Math.Abs(p2.Y - p1.Y))
+ return SurfaceGestureVectorDirection.DOWN;
+ else
{
- if (Math.Abs(p2.X - p1.X) < Math.Abs(p2.Y - p1.Y))
- return SurfaceGestureVectorDirection.DOWN;
+ if (p1.X < p2.X)
+ return SurfaceGestureVectorDirection.DOWNRIGHT;
else
- {
- if (p1.X < p2.X)
- return SurfaceGestureVectorDirection.DOWNRIGHT;
- else
- return SurfaceGestureVectorDirection.DOWNLEFT;
- }
+ return SurfaceGestureVectorDirection.DOWNLEFT;
}
- else
- {
- if (p1.X < p2.X)
- return SurfaceGestureVectorDirection.DOWNRIGHT;
- else
- return SurfaceGestureVectorDirection.DOWNLEFT;
- }
}
else
{
// go down
- if (Math.Abs(p1.Y - p2.Y) > this.Precision)
- {
- if (Math.Abs(p1.X - p2.X) < Math.Abs(p1.Y - p2.Y))
- return SurfaceGestureVectorDirection.UP;
- else
- {
- if (p1.X < p2.X)
- return SurfaceGestureVectorDirection.UPRIGHT;
- else
- return SurfaceGestureVectorDirection.UPLEFT;
- }
- }
+ if (Math.Abs(p1.X - p2.X) < Math.Abs(p1.Y - p2.Y))
+ return SurfaceGestureVectorDirection.UP;
else
{
if (p1.X < p2.X)
@@ -768,18 +220,8 @@
if (p1.X < p2.X)
{
// go left
- if (Math.Abs(p2.X - p1.X) > this.Precision)
- {
- if (Math.Abs(p2.Y - p1.Y) < Math.Abs(p2.X - p1.X))
- return SurfaceGestureVectorDirection.RIGHT;
- else
- {
- if (p1.Y < p2.Y)
- return SurfaceGestureVectorDirection.DOWNRIGHT;
- else
- return SurfaceGestureVectorDirection.UPRIGHT;
- }
- }
+ if (Math.Abs(p2.Y - p1.Y) < Math.Abs(p2.X - p1.X))
+ return SurfaceGestureVectorDirection.RIGHT;
else
{
if (p1.Y < p2.Y)
@@ -790,19 +232,9 @@
}
else
{
- // go right
- if (Math.Abs(p1.X - p2.X) > this.Precision)
- {
- if (Math.Abs(p1.Y - p2.Y) < Math.Abs(p1.X - p2.X))
- return SurfaceGestureVectorDirection.LEFT;
- else
- {
- if (p1.Y < p2.Y)
- return SurfaceGestureVectorDirection.DOWNLEFT;
- else
- return SurfaceGestureVectorDirection.UPLEFT;
- }
- }
+ // go right=
+ if (Math.Abs(p1.Y - p2.Y) < Math.Abs(p1.X - p2.X))
+ return SurfaceGestureVectorDirection.LEFT;
else
{
if (p1.Y < p2.Y)
@@ -829,4 +261,4 @@
}
#endregion
}
-}
+}
\ No newline at end of file