src/FingersDance.GestureControl/GestureVector.cs
changeset 177 89cbcb52b674
parent 176 0896f36b9d57
child 178 56041bd3761e
equal deleted inserted replaced
176:0896f36b9d57 177:89cbcb52b674
    49         /// <param name="list"></param>
    49         /// <param name="list"></param>
    50         /// <param name="pas"></param>
    50         /// <param name="pas"></param>
    51         /// <returns></returns>
    51         /// <returns></returns>
    52         private bool GenerateCourb(List<SurfaceGesturePoint> list, int pas)
    52         private bool GenerateCourb(List<SurfaceGesturePoint> list, int pas)
    53         {
    53         {
    54             //List<SurfaceGesturePattern> tmp = new List<SurfaceGesturePattern>();
       
    55             int sep = list.Count / pas;
    54             int sep = list.Count / pas;
    56             double count = 0; ;
    55             double count = 0; ;
    57             SurfaceGesturePoint past = new SurfaceGesturePoint() { X = 0, Y = 0 };
    56             SurfaceGesturePoint past = new SurfaceGesturePoint() { X = 0, Y = 0 };
    58             double y = 0;
    57             double y = 0;
    59 
    58 
   150                 {
   149                 {
   151                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
   150                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWN, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
   152                     LastChange = list[i + 1];
   151                     LastChange = list[i + 1];
   153                     lastDirection = SurfaceGestureVectorDirection.DOWN;
   152                     lastDirection = SurfaceGestureVectorDirection.DOWN;
   154                 }
   153                 }
       
   154                 else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT)
       
   155                 {
       
   156                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
       
   157                     LastChange = list[i + 1];
       
   158                     lastDirection = SurfaceGestureVectorDirection.UPLEFT;
       
   159                 }
       
   160                 else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT)
       
   161                 {
       
   162                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
       
   163                     LastChange = list[i + 1];
       
   164                     lastDirection = SurfaceGestureVectorDirection.UPRIGHT;
       
   165                 }
       
   166                 else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNLEFT && lastDirection != SurfaceGestureVectorDirection.DOWNLEFT)
       
   167                 {
       
   168                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
       
   169                     LastChange = list[i + 1];
       
   170                     lastDirection = SurfaceGestureVectorDirection.DOWNLEFT;
       
   171                 }
       
   172                 else if (GetHorizontal(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT)
       
   173                 {
       
   174                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
       
   175                     LastChange = list[i + 1];
       
   176                     lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT;
       
   177                 }
   155                 else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.LEFT && lastDirection != SurfaceGestureVectorDirection.LEFT)
   178                 else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.LEFT && lastDirection != SurfaceGestureVectorDirection.LEFT)
   156                 {
   179                 {
   157                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)) });
   180                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.LEFT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)) });
   158                     LastChange = list[i + 1];
   181                     LastChange = list[i + 1];
   159                     lastDirection = SurfaceGestureVectorDirection.LEFT;
   182                     lastDirection = SurfaceGestureVectorDirection.LEFT;
   162                 {
   185                 {
   163                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)) });
   186                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.RIGHT, Lenght = (Math.Abs(LastChange.X - list[i + 1].X)) });
   164                     LastChange = list[i + 1];
   187                     LastChange = list[i + 1];
   165                     lastDirection = SurfaceGestureVectorDirection.RIGHT;
   188                     lastDirection = SurfaceGestureVectorDirection.RIGHT;
   166                 }
   189                 }
       
   190                 else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPLEFT && lastDirection != SurfaceGestureVectorDirection.UPLEFT)
       
   191                 {
       
   192                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
       
   193                     LastChange = list[i + 1];
       
   194                     lastDirection = SurfaceGestureVectorDirection.UPLEFT;
       
   195                 }
       
   196                 else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.UPRIGHT && lastDirection != SurfaceGestureVectorDirection.UPRIGHT)
       
   197                 {
       
   198                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.UPRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
       
   199                     LastChange = list[i + 1];
       
   200                     lastDirection = SurfaceGestureVectorDirection.UPRIGHT;
       
   201                 }
       
   202                 else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNLEFT && lastDirection != SurfaceGestureVectorDirection.DOWNLEFT)
       
   203                 {
       
   204                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNLEFT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
       
   205                     LastChange = list[i + 1];
       
   206                     lastDirection = SurfaceGestureVectorDirection.DOWNLEFT;
       
   207                 }
       
   208                 else if (GetVertical(list[lastPoint], list[i + 1]) == SurfaceGestureVectorDirection.DOWNRIGHT && lastDirection != SurfaceGestureVectorDirection.DOWNRIGHT)
       
   209                 {
       
   210                     this.Add(new SurfaceGestureVector { Direction = SurfaceGestureVectorDirection.DOWNRIGHT, Lenght = (Math.Abs(LastChange.Y - list[i + 1].Y)) });
       
   211                     LastChange = list[i + 1];
       
   212                     lastDirection = SurfaceGestureVectorDirection.DOWNRIGHT;
       
   213                 }
   167                 ++lastPoint;
   214                 ++lastPoint;
   168             }
   215             }
       
   216 
       
   217             //  Analyse de la forme
       
   218 
       
   219             int up = 0, down = 0, left = 0, right = 0, upleft = 0, upright = 0, downleft = 0, downright = 0;
       
   220             foreach (SurfaceGestureVector elt in this)
       
   221             {
       
   222                 switch (elt.Direction)
       
   223                 {
       
   224                     case SurfaceGestureVectorDirection.DOWN:
       
   225                         down++;
       
   226                         break;
       
   227                     case SurfaceGestureVectorDirection.DOWNLEFT:
       
   228                         downleft++;
       
   229                         break;
       
   230                     case SurfaceGestureVectorDirection.DOWNRIGHT:
       
   231                         downright++;
       
   232                         break;
       
   233                     case SurfaceGestureVectorDirection.LEFT:
       
   234                         left++;
       
   235                         break;
       
   236                     case SurfaceGestureVectorDirection.RIGHT:
       
   237                         right++;
       
   238                         break;
       
   239                     case SurfaceGestureVectorDirection.UP:
       
   240                         up++;
       
   241                         break;
       
   242                     case SurfaceGestureVectorDirection.UPLEFT:
       
   243                         upleft++;
       
   244                         break;
       
   245                     case SurfaceGestureVectorDirection.UPRIGHT:
       
   246                         upright++;
       
   247                         break;
       
   248                 }
       
   249             }
   169         }
   250         }
   170         private SurfaceGestureVectorDirection GetHorizontal(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
   251         private SurfaceGestureVectorDirection GetHorizontal(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
   171         {
   252         {
   172             if (p1.Y < p2.Y)
   253             if (p1.Y < p2.Y)
   173             {
   254             {
   174                 // go up
   255                 // go up
   175                 if (Math.Abs(p2.Y - p1.Y) > this.Precision && Math.Abs(p2.X - p1.X) < Math.Abs(p2.Y - p1.Y))
   256                 if (Math.Abs(p2.Y - p1.Y) > this.Precision)
   176                     return SurfaceGestureVectorDirection.DOWN;
   257                 {
       
   258                     if (Math.Abs(p2.X - p1.X) < Math.Abs(p2.Y - p1.Y))
       
   259                         return SurfaceGestureVectorDirection.DOWN;
       
   260                     else
       
   261                     {
       
   262                         if (p1.X < p2.X)
       
   263                             return SurfaceGestureVectorDirection.DOWNRIGHT;
       
   264                         else
       
   265                             return SurfaceGestureVectorDirection.DOWNLEFT;
       
   266                     }
       
   267                 }
       
   268                     else
       
   269                     {
       
   270                         if (p1.X < p2.X)
       
   271                             return SurfaceGestureVectorDirection.DOWNRIGHT;
       
   272                         else
       
   273                             return SurfaceGestureVectorDirection.DOWNLEFT;
       
   274                     }
   177             }
   275             }
   178             else
   276             else
   179             {
   277             {
   180                 // go down
   278                 // go down
   181                 if (Math.Abs(p1.Y - p2.Y) > this.Precision && Math.Abs(p1.X - p2.X) < Math.Abs(p1.Y - p2.Y))
   279                 if (Math.Abs(p1.Y - p2.Y) > this.Precision)
   182                     return SurfaceGestureVectorDirection.UP;
   280                 {
       
   281                     if (Math.Abs(p1.X - p2.X) < Math.Abs(p1.Y - p2.Y))
       
   282                         return SurfaceGestureVectorDirection.UP;
       
   283                     else
       
   284                     {
       
   285                         if (p1.X < p2.X)
       
   286                             return SurfaceGestureVectorDirection.UPRIGHT;
       
   287                         else
       
   288                             return SurfaceGestureVectorDirection.UPLEFT;
       
   289                     }
       
   290                 }
       
   291                 else
       
   292                 {
       
   293                     if (p1.X < p2.X)
       
   294                         return SurfaceGestureVectorDirection.UPRIGHT;
       
   295                     else
       
   296                         return SurfaceGestureVectorDirection.UPLEFT;
       
   297                 }
   183             }
   298             }
   184             return SurfaceGestureVectorDirection.NONE;
   299             return SurfaceGestureVectorDirection.NONE;
   185         }
   300         }
   186         private SurfaceGestureVectorDirection GetVertical(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
   301         private SurfaceGestureVectorDirection GetVertical(SurfaceGesturePoint p1, SurfaceGesturePoint p2)
   187         {
   302         {
   188             if (p1.X < p2.X)
   303             if (p1.X < p2.X)
   189             {
   304             {
   190                 // go left
   305                 // go left
   191                 if (Math.Abs(p2.X - p1.X) > this.Precision && Math.Abs(p2.Y - p1.Y) < Math.Abs(p2.X - p1.X))
   306                 if (Math.Abs(p2.X - p1.X) > this.Precision)
   192                     return SurfaceGestureVectorDirection.RIGHT;
   307                 {
       
   308                     if (Math.Abs(p2.Y - p1.Y) < Math.Abs(p2.X - p1.X))
       
   309                         return SurfaceGestureVectorDirection.RIGHT;
       
   310                     else
       
   311                     {
       
   312                         if (p1.Y < p2.Y)
       
   313                             return SurfaceGestureVectorDirection.DOWNRIGHT;
       
   314                         else
       
   315                             return SurfaceGestureVectorDirection.UPRIGHT;
       
   316                     }
       
   317                 }
       
   318                 else
       
   319                 {
       
   320                     if (p1.Y < p2.Y)
       
   321                         return SurfaceGestureVectorDirection.DOWNRIGHT;
       
   322                     else
       
   323                         return SurfaceGestureVectorDirection.UPRIGHT;
       
   324                 }
   193             }
   325             }
   194             else
   326             else
   195             {
   327             {
   196                 // go right
   328                 // go right
   197                 if (Math.Abs(p1.X - p2.X) > this.Precision && Math.Abs(p1.Y - p2.Y) < Math.Abs(p1.X - p2.X))
   329                 if (Math.Abs(p1.X - p2.X) > this.Precision)
   198                     return SurfaceGestureVectorDirection.LEFT;
   330                 {
       
   331                     if (Math.Abs(p1.Y - p2.Y) < Math.Abs(p1.X - p2.X))
       
   332                         return SurfaceGestureVectorDirection.LEFT;
       
   333                     else
       
   334                     {
       
   335                         if (p1.Y < p2.Y)
       
   336                             return SurfaceGestureVectorDirection.DOWNLEFT;
       
   337                         else
       
   338                             return SurfaceGestureVectorDirection.UPLEFT;
       
   339                     }
       
   340                 }
       
   341                 else
       
   342                 {
       
   343                     if (p1.Y < p2.Y)
       
   344                         return SurfaceGestureVectorDirection.DOWNLEFT;
       
   345                     else
       
   346                         return SurfaceGestureVectorDirection.UPLEFT;
       
   347                 }
   199             }
   348             }
   200             return SurfaceGestureVectorDirection.NONE;
   349             return SurfaceGestureVectorDirection.NONE;
   201         }
   350         }
   202         #endregion
   351         #endregion
   203 
   352