src/FingersDance.GestureControl/GestureVector.cs
changeset 209 09c4d30fe8d1
parent 189 b37888f59cf2
child 215 d13dbcf861d7
equal deleted inserted replaced
208:0699cab5cbb3 209:09c4d30fe8d1
    35         /// </summary>
    35         /// </summary>
    36         /// <param name="list"></param>
    36         /// <param name="list"></param>
    37         /// <param name="precision"></param>
    37         /// <param name="precision"></param>
    38         public SurfaceGesture(List<SurfaceGesturePoint> list, int precision)
    38         public SurfaceGesture(List<SurfaceGesturePoint> list, int precision)
    39         {
    39         {
    40             this.Precision = precision;
    40             this.Precision = 20;
    41             this.Generate(list);
    41             this.Generate(list);
    42         }
    42         }
    43         #endregion
    43         #endregion
    44 
    44 
    45         #region GenerateVector
    45         #region GenerateVector
    91             }
    91             }
    92             Console.Write(this);
    92             Console.Write(this);
    93             /*if (this.GetPattern() != "None")
    93             /*if (this.GetPattern() != "None")
    94                 return true;
    94                 return true;
    95             else*/
    95             else*/
    96             return false;
    96                 return false;
    97         }
    97         }
    98         /// <summary>
    98         /// <summary>
    99         /// Get distance between two points
    99         /// Get distance between two points
   100         /// </summary>
   100         /// </summary>
   101         /// <param name="p1"></param>
   101         /// <param name="p1"></param>
   122         /// <summary>
   122         /// <summary>
   123         /// generate list of vector
   123         /// generate list of vector
   124         /// </summary>
   124         /// </summary>
   125         /// <param name="list"></param>
   125         /// <param name="list"></param>
   126         private void Generate(List<SurfaceGesturePoint> list)
   126         private void Generate(List<SurfaceGesturePoint> list)
   127         {
   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;
   128             this.Clear();
   135             this.Clear();
   129             if (list.Count < 2)
   136             ///////////////////////
   130             {
   137 
   131                 this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 });
   138             for (int i = 0; i < list.Count - 1; i++)
   132                 return;
   139             {
   133             }
   140                 if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UP && lastDirection != SurfaceGestureVectorDirection.UP)
   134 
   141                 {
   135             List<SurfaceGesturePoint> Points = new List<SurfaceGesturePoint>();
   142                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
   136             List<SurfaceGestureVector> Vectors = new List<SurfaceGestureVector>();
   143                     LastChange = list[i + 1];
   137             
   144                     lastDirection = SurfaceGestureVectorDirection.UP;
   138             for (int index = 1; index <= list.Count; index++)
   145                 }
   139             {
   146                 else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWN && lastDirection != SurfaceGestureVectorDirection.DOWN)
   140                 if (index == list.Count / 2 || index == list.Count)
   147                 {
   141                 {
   148                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
   142                     SurfaceGestureVector verctorTemp = AnalysePoints(Points);
   149                     LastChange = list[i + 1];
   143                     if (Vectors.Count == 0 || !Vectors[Vectors.Count - 1].Direction.Equals(verctorTemp.Direction))
   150                     lastDirection = SurfaceGestureVectorDirection.DOWN;
   144                         Vectors.Add(verctorTemp);
   151                 }
   145                     Points.Clear();
   152                 else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT)
   146                 }
   153                 {
   147                 else
   154                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
   148                     Points.Add(list[index]);
   155                     LastChange = list[i + 1];
   149             }
   156                     lastDirection = SurfaceGestureVectorDirection.UPLEFT;
   150             foreach (SurfaceGestureVector elt in Vectors)
   157                 }
   151                 this.Add(elt);
   158                 else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT)
   152         }
   159                 {
   153 
   160                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)), Origin = list[lastPoint] });
   154         SurfaceGestureVector AnalysePoints(List<SurfaceGesturePoint> list)
   161                     LastChange = list[i + 1];
   155         {
   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;
       
   213             }
       
   214 
       
   215             //  Analyse des extrémités de la gesture
       
   216             /*
       
   217 
   156             double diffX = Math.Abs(list[0].X - list[list.Count - 1].X);
   218             double diffX = Math.Abs(list[0].X - list[list.Count - 1].X);
   157             double diffY = Math.Abs(list[0].Y - list[list.Count - 1].Y);
   219             double diffY = Math.Abs(list[0].Y - list[list.Count - 1].Y);
   158 
   220 
   159             if (diffX < 10 && diffY > 10)
   221             if (diffX < 10 && diffY > 10)
   160             {
   222             {
   161                 if (list[0].Y > list[list.Count - 1].Y)
   223                 this.Clear();
   162                     return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = 0, Origin = list[0] });
   224                 if (up > down)
   163                 else
   225                     return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UP, Lenght = up });
   164                     return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = 0, Origin = list[0] });
   226                 else
       
   227                     return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = down });
   165             }
   228             }
   166             else if (diffY < 10 && diffX > 10)
   229             else if (diffY < 10 && diffX > 10)
   167             {
   230             {
   168                 if (list[list.Count - 1].X > list[0].X)
   231                 this.Clear();
   169                     return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = 0, Origin = list[0] });
   232                 if (left > right)
   170                 else
   233                     return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = left });
   171                     return (new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = 0, Origin = list[0] });
   234                 else
       
   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 });
   172             }
   700             }
   173             else if (diffX > 10 && diffY > 10)
   701             else if (diffX > 10 && diffY > 10)
   174             {
   702             {
   175                 if (list[0].Y > list[list.Count - 1].Y && list[list.Count - 1].X > list[0].X)
   703                 if (list[0].Origin.Y > list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X > list[0].Origin.X)
   176                     return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = 0, Origin = list[0] };
   704                     return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = upleft, Origin = list[0].Origin };
   177                 else if (list[0].Y > list[list.Count - 1].Y && list[list.Count - 1].X < list[0].X)
   705                 else if (list[0].Origin.Y > list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X < list[0].Origin.X)
   178                     return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = 0, Origin = list[0] };
   706                     return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin };
   179                 else if (list[0].Y < list[list.Count - 1].Y && list[list.Count - 1].X > list[0].X)
   707                 else if (list[0].Origin.Y < list[list.Count - 1].Origin.Y && list[list.Count - 1].Origin.X > list[0].Origin.X)
   180                     return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = 0, Origin = list[0] };
   708                     return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = downleft, Origin = list[0].Origin };
   181                 else
   709                 else
   182                     return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = 0, Origin = list[0] };
   710                     return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = upright, Origin = list[0].Origin };
   183             }
   711             }
   184             else
   712             else
   185                 return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 };
   713                 return new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.TAP, Lenght = 0 };
   186         }
   714         }
   187 
   715 
   188         private SurfaceGestureVectorDirection GetHorizontal(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
   716         private SurfaceGestureVectorDirection GetHorizontal(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
   189         {
   717         {
   190             if (p1.Y < p2.Y)
   718             if (p1.Y < p2.Y)
   191             {
   719             {
   192                 // go up
   720                 // go up
   193                 if (Math.Abs(p2.X - p1.X) < Math.Abs(p2.Y - p1.Y))
   721                 if (Math.Abs(p2.Y - p1.Y) > this.Precision)
   194                     return SurfaceGestureVectorDirection.DOWN;
   722                 {
   195                 else
   723                     if (Math.Abs(p2.X - p1.X) < Math.Abs(p2.Y - p1.Y))
   196                 {
   724                         return SurfaceGestureVectorDirection.DOWN;
   197                     if (p1.X < p2.X)
   725                     else
   198                         return SurfaceGestureVectorDirection.DOWNRIGHT;
   726                     {
   199                     else
   727                         if (p1.X < p2.X)
   200                         return SurfaceGestureVectorDirection.DOWNLEFT;
   728                             return SurfaceGestureVectorDirection.DOWNRIGHT;
   201                 }
   729                         else
       
   730                             return SurfaceGestureVectorDirection.DOWNLEFT;
       
   731                     }
       
   732                 }
       
   733                     else
       
   734                     {
       
   735                         if (p1.X < p2.X)
       
   736                             return SurfaceGestureVectorDirection.DOWNRIGHT;
       
   737                         else
       
   738                             return SurfaceGestureVectorDirection.DOWNLEFT;
       
   739                     }
   202             }
   740             }
   203             else
   741             else
   204             {
   742             {
   205                 // go down
   743                 // go down
   206                 if (Math.Abs(p1.X - p2.X) < Math.Abs(p1.Y - p2.Y))
   744                 if (Math.Abs(p1.Y - p2.Y) > this.Precision)
   207                     return SurfaceGestureVectorDirection.UP;
   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                 }
   208                 else
   756                 else
   209                 {
   757                 {
   210                     if (p1.X < p2.X)
   758                     if (p1.X < p2.X)
   211                         return SurfaceGestureVectorDirection.UPRIGHT;
   759                         return SurfaceGestureVectorDirection.UPRIGHT;
   212                     else
   760                     else
   218         private SurfaceGestureVectorDirection GetVertical(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
   766         private SurfaceGestureVectorDirection GetVertical(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
   219         {
   767         {
   220             if (p1.X < p2.X)
   768             if (p1.X < p2.X)
   221             {
   769             {
   222                 // go left
   770                 // go left
   223                 if (Math.Abs(p2.Y - p1.Y) < Math.Abs(p2.X - p1.X))
   771                 if (Math.Abs(p2.X - p1.X) > this.Precision)
   224                     return SurfaceGestureVectorDirection.RIGHT;
   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                 }
   225                 else
   783                 else
   226                 {
   784                 {
   227                     if (p1.Y < p2.Y)
   785                     if (p1.Y < p2.Y)
   228                         return SurfaceGestureVectorDirection.DOWNRIGHT;
   786                         return SurfaceGestureVectorDirection.DOWNRIGHT;
   229                     else
   787                     else
   230                         return SurfaceGestureVectorDirection.UPRIGHT;
   788                         return SurfaceGestureVectorDirection.UPRIGHT;
   231                 }
   789                 }
   232             }
   790             }
   233             else
   791             else
   234             {
   792             {
   235                 // go right=
   793                 // go right
   236                 if (Math.Abs(p1.Y - p2.Y) < Math.Abs(p1.X - p2.X))
   794                 if (Math.Abs(p1.X - p2.X) > this.Precision)
   237                     return SurfaceGestureVectorDirection.LEFT;
   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                 }
   238                 else
   806                 else
   239                 {
   807                 {
   240                     if (p1.Y < p2.Y)
   808                     if (p1.Y < p2.Y)
   241                         return SurfaceGestureVectorDirection.DOWNLEFT;
   809                         return SurfaceGestureVectorDirection.DOWNLEFT;
   242                     else
   810                     else