Exemple #1
0
    private void MatchGesture()
    {
        int bestCost = 1000000;
        int cost     = 0;

        int[] gest;
        int[] imoves = new int[moves.Count];
        for (int i = 0; i < imoves.Length; i++)
        {
            imoves[i] = (int)moves[i];
        }
        Vector2[] ppoints = new Vector2[points.Count];
        for (int i = 0; i < ppoints.Length; i++)
        {
            ppoints[i] = (Vector2)points[i];
        }
        string       bestGesture = string.Empty;
        Rect         irect       = new Rect(rect.xMin, rect.yMin, rect.xMax - rect.xMin, rect.yMax - rect.yMin);
        GestureInfos infos       = new GestureInfos(new GestureData(imoves, ppoints, lastPoint, irect));

        for (int i = 0; i < gestures.Count; i++)
        {
            gest          = (gestures[i] as GestureProperties).Moves;
            infos.Present = (gestures[i] as GestureProperties).Present;
            cost          = CostLeven(gest, imoves);
            if (cost <= DEFAULT_FIABILITY)
            {
                if ((gestures[i] as GestureProperties).match != null)
                {
                    infos.Cost = cost;
                    cost       = (gestures[i] as GestureProperties).match(infos);
                }
                if (cost < bestCost)
                {
                    bestCost    = cost;
                    bestGesture = (gestures[i] as GestureProperties).Present;
                }
            }
        }
        if (!string.IsNullOrEmpty(bestGesture))
        {
            GestureEventArgs args = new GestureEventArgs();
            args.Present   = bestGesture;
            args.Fiability = cost;
            if (GestureMatchEvent != null)
            {
                GestureMatchEvent(args);
            }
            ClearData();
        }
        else
        {
            if (GestureNoMatchEvent != null)
            {
                GestureNoMatchEvent();
            }
            ClearData();
        }
    }
Exemple #2
0
    private int oMatch(GestureInfos infos)
    {
        if (infos.Data.Rect.height == 0)
        {
            return(10000);
        }
        double py = (infos.Data.LastPoint.y - infos.Data.Rect.y) / (infos.Data.Rect.height);

        return(py > 0.3 ? infos.Cost : 10000);
    }
Exemple #3
0
    private int sMatch(GestureInfos infos)
    {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < infos.Data.Moves.Length; i++)
        {
            sb.Append(infos.Data.Moves[i]);
        }
        string s   = sb.ToString();
        int    pos = s.IndexOf("111");

        return(pos > -1 ? infos.Cost : 10000);
    }
Exemple #4
0
 private int rightMatch(GestureInfos infos)
 {
     return(-1);
 }