--- a/src/FingersDance.GestureControl/GestureVector.cs Thu Nov 05 22:40:36 2009 +0100
+++ b/src/FingersDance.GestureControl/GestureVector.cs Fri Nov 06 17:50:40 2009 +0100
@@ -93,7 +93,7 @@
/*if (this.GetPattern() != "None")
return true;
else*/
- return false;
+ return false;
}
/// <summary>
/// Get distance between two points
@@ -125,155 +125,64 @@
/// <param name="list"></param>
private void Generate(List<SurfaceGesturePoint> list)
{
+ this.Clear();
if (list.Count < 2)
{
this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 });
return;
}
- 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++)
+ List<SurfaceGesturePoint> Points = new List<SurfaceGesturePoint>();
+ List<SurfaceGestureVector> Vectors = new List<SurfaceGestureVector>();
+
+ for (int index = 1; index <= list.Count; index++)
{
- 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)) });
- 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)) });
- 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)) });
- 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)) });
- 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)) });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.DOWNLEFT;
- }
- else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT)
+ if (index == list.Count / 2 || index == list.Count)
{
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
- 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)) });
- 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)) });
- 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)) });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.UPLEFT;
+ SurfaceGestureVector verctorTemp = AnalysePoints(Points);
+ if (Vectors.Count == 0 || !Vectors[Vectors.Count - 1].Direction.Equals(verctorTemp.Direction))
+ Vectors.Add(verctorTemp);
+ Points.Clear();
}
- 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)) });
- 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)) });
- 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)) });
- LastChange = list[i + 1];
- lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT;
- }
- ++lastPoint;
+ else
+ Points.Add(list[index]);
}
- Analyse(list);
+ foreach (SurfaceGestureVector elt in Vectors)
+ this.Add(elt);
}
- private void Analyse(List<SurfaceGesturePoint> list)
+ SurfaceGestureVector AnalysePoints(List<SurfaceGesturePoint> 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 this)
- {
- 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 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 < 5)
+ if (diffX < 10 && diffY > 10)
{
- this.Clear();
- if (up > down)
- this.Add(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
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down });
+ return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = 0, Origin = list[0] });
+ }
+ else if (diffY < 10 && diffX > 10)
+ {
+ 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.LEFT, Lenght = 0, Origin = list[0] });
}
- else if (diffY < 5)
+ else if (diffX > 10 && diffY > 10)
{
- this.Clear();
- if (left > right)
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left });
+ 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
- this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = right });
+ return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = 0, Origin = list[0] };
}
+ else
+ return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 };
}
private SurfaceGestureVectorDirection GetHorizontal(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
@@ -281,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)
@@ -324,25 +213,15 @@
return SurfaceGestureVectorDirection.UPLEFT;
}
}
- return SurfaceGestureVectorDirection.NONE;
}
+
private SurfaceGestureVectorDirection GetVertical(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
{
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)
@@ -353,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)
@@ -374,8 +243,8 @@
return SurfaceGestureVectorDirection.UPLEFT;
}
}
- return SurfaceGestureVectorDirection.NONE;
}
+
#endregion
#region Override