public string GetGestureSetNameMatch(PointF[] Points)
        {
            // Update gesture analyzer with latest gestures and get gesture match from current points array
            // Comparison results are sorted descending from highest to lowest probability
            gestureAnalyzer.PointPatternSet = Gestures.ToArray();
            PointPatternMatchResult[] comparisonResults = gestureAnalyzer.GetPointPatternMatchResults(Points);

            // Exit if we didn't find a high probability match
            if (comparisonResults == null || comparisonResults.Where(ppmr => ppmr.Probability >= 75).Count() <= 0)
            {
                return(null);                           // No close enough match. Do nothing with drawn gesture
            }
            // Grab top result from gesture comparison
            return(comparisonResults.First().Name);
        }
        public string GetGestureSetNameMatch(List <List <Point> > points, List <IGesture> sourceGestures, out List <IGesture> matchResult)//PointF[]
        {
            if (points.Count == 0 || sourceGestures == null || sourceGestures.Count == 0)
            {
                matchResult = null; return(null);
            }
            // Update gesture analyzer with latest gestures and get gesture match from current points array
            // Comparison results are sorted descending from highest to lowest probability
            var gestures = sourceGestures.Where(g => g.PointPatterns.Length > _gestureLevel && g.PointPatterns[_gestureLevel].Points != null && g.PointPatterns[_gestureLevel].Points.Count == points.Count).ToList();

            List <PointPatternMatchResult>[] comparisonResults = new List <PointPatternMatchResult> [points.Count];
            for (int i = 0; i < points.Count; i++)
            {
                gestureAnalyzer.PointPatternSet = gestures.Select(gesture => new PointPatternAnalyzer.PointsPatternSet(gesture.Name, gesture.PointPatterns[_gestureLevel].Points[i].ToArray()));
                comparisonResults[i]            = new List <PointPatternMatchResult>(gestures.Count);
                comparisonResults[i].AddRange(gestureAnalyzer.GetPointPatternMatchResults(points[i].ToArray()));
            }

            List <int> numbers = new List <int>(gestures.Count);

            for (int j = 0; j < gestures.Count; j++)
            {
                numbers.Add(j);
            }

            numbers = comparisonResults.Aggregate(numbers, (current, matchResultsList) => current.Where(i => matchResultsList[i].Probability > ProbabilityThreshold).ToList());

            List <IGesture> result = new List <IGesture>();
            List <KeyValuePair <string, double> > recognizedResult = new List <KeyValuePair <string, double> >();

            foreach (var number in numbers)
            {
                var gesture = gestures[number];
                if (gesture.PointPatterns.Length > _gestureLevel + 1)
                {
                    result.Add(gesture);
                }
                else
                {
                    double probability = comparisonResults.Sum(matchResultsList => matchResultsList[number].Probability);

                    recognizedResult.Add(new KeyValuePair <string, double>(gesture.Name, probability));
                }
            }

            matchResult = result.Count == 0 ? null : result;
            return(recognizedResult.Count == 0 ? null : recognizedResult.OrderByDescending(r => r.Value).First().Key);
        }