--- a/src/FingersDance.GestureControl/GestureVector.cs Tue Oct 27 01:59:56 2009 +0100
+++ b/src/FingersDance.GestureControl/GestureVector.cs Tue Oct 27 10:10:26 2009 +0100
@@ -51,7 +51,6 @@
/// <returns></returns>
private bool GenerateCourb(List<SurfaceGesturePoint> list, int pas)
{
- //List<SurfaceGesturePattern> tmp = new List<SurfaceGesturePattern>();
int sep = list.Count / pas;
double count = 0; ;
SurfaceGesturePoint past = new SurfaceGesturePoint() { X = 0, Y = 0 };
@@ -152,6 +151,30 @@
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)
+ {
+ 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)) });
@@ -164,22 +187,114 @@
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;
+ }
+ 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;
}
+
+ // Analyse de la forme
+
+ int 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++;
+ break;
+ case SurfaceGestureVectorDirection.DOWNLEFT:
+ downleft++;
+ break;
+ case SurfaceGestureVectorDirection.DOWNRIGHT:
+ downright++;
+ break;
+ case SurfaceGestureVectorDirection.LEFT:
+ left++;
+ break;
+ case SurfaceGestureVectorDirection.RIGHT:
+ right++;
+ break;
+ case SurfaceGestureVectorDirection.UP:
+ up++;
+ break;
+ case SurfaceGestureVectorDirection.UPLEFT:
+ upleft++;
+ break;
+ case SurfaceGestureVectorDirection.UPRIGHT:
+ upright++;
+ break;
+ }
+ }
}
private SurfaceGestureVectorDirection GetHorizontal(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
{
if (p1.Y < p2.Y)
{
// go up
- if (Math.Abs(p2.Y - p1.Y) > this.Precision && Math.Abs(p2.X - p1.X) < Math.Abs(p2.Y - p1.Y))
- return SurfaceGestureVectorDirection.DOWN;
+ 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 (p1.X < p2.X)
+ return SurfaceGestureVectorDirection.DOWNRIGHT;
+ else
+ 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 && Math.Abs(p1.X - p2.X) < Math.Abs(p1.Y - p2.Y))
- return SurfaceGestureVectorDirection.UP;
+ 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;
+ }
+ }
+ else
+ {
+ if (p1.X < p2.X)
+ return SurfaceGestureVectorDirection.UPRIGHT;
+ else
+ return SurfaceGestureVectorDirection.UPLEFT;
+ }
}
return SurfaceGestureVectorDirection.NONE;
}
@@ -188,14 +303,48 @@
if (p1.X < p2.X)
{
// go left
- if (Math.Abs(p2.X - p1.X) > this.Precision && Math.Abs(p2.Y - p1.Y) < Math.Abs(p2.X - p1.X))
- return SurfaceGestureVectorDirection.RIGHT;
+ 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;
+ }
+ }
+ else
+ {
+ if (p1.Y < p2.Y)
+ return SurfaceGestureVectorDirection.DOWNRIGHT;
+ else
+ return SurfaceGestureVectorDirection.UPRIGHT;
+ }
}
else
{
// go right
- if (Math.Abs(p1.X - p2.X) > this.Precision && Math.Abs(p1.Y - p2.Y) < Math.Abs(p1.X - p2.X))
- return SurfaceGestureVectorDirection.LEFT;
+ 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;
+ }
+ }
+ else
+ {
+ if (p1.Y < p2.Y)
+ return SurfaceGestureVectorDirection.DOWNLEFT;
+ else
+ return SurfaceGestureVectorDirection.UPLEFT;
+ }
}
return SurfaceGestureVectorDirection.NONE;
}