Esempio n. 1
0
        public ValidSetOfPointsCollection Validate(List<TouchPoint2> points)
        {
            ValidSetOfPointsCollection list = new ValidSetOfPointsCollection();

            if (_data.Type == TouchLimitType.FixedValue)
            {
                List<TouchPoint2> analyze = PointTranslator.removeHandRedundancy(points);

                if (analyze.Count == _data.Min)
                {
                    list.Add(new ValidSetOfTouchPoints(analyze));
                }
                else if (analyze.Count > _data.Min)
                {
                    // Generate possible valid combinitions
                    Combinations c = new Combinations(analyze.ToArray(), _data.Min);
                    while (c.MoveNext())
                    {
                        TouchPoint2[] arr = c.Current as TouchPoint2[];
                        ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(arr);
                        list.Add(set);
                    }
                }
            }
            else if (_data.Type == TouchLimitType.Range)
            {
                if (points.Count == _data.Min)
                {
                    list.Add(new ValidSetOfTouchPoints(points));
                }
                else if (points.Count > _data.Min && points.Count <= _data.Max)
                {
                    // All possible combinitions of size between min & max-1
                    for (int size = _data.Min; size < points.Count; size++)
                    {
                        // Generate possible valid combinitions
                        Combinations c = new Combinations(points.ToArray(), size);
                        while (c.MoveNext())
                        {
                            TouchPoint2[] arr = c.Current as TouchPoint2[];
                            ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(arr);
                            list.Add(set);
                        }
                    }
                }
            }

            return list;
        }
        public ValidSetOfPointsCollection Validate(List<TouchPoint2> points)
        {
            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();

            bool result = false;
            if (points == null)
            {
                return sets;
            }

            if (points.Count > 2)
            {
                // Assumption: If there are more that 2 points, then each point should
                // match the condition with another point in at least one condition

                Dictionary<TouchPoint2, bool> resultSet = new Dictionary<TouchPoint2, bool>(points.Count);

                Combinations combinationGen = new Combinations(points.ToArray(), 2);
                while (combinationGen.MoveNext())
                {
                    TouchPoint2[] arr = combinationGen.Current as TouchPoint2[];
                    if (IsValid(arr))
                    {
                        // First item of the combinition set
                        if (!resultSet.ContainsKey(arr[0]))
                            resultSet.Add(arr[0], true);

                        // Second item of the combinition set
                        if (!resultSet.ContainsKey(arr[1]))
                            resultSet.Add(arr[1], true);

                        if (resultSet.Count == points.Count)
                        {
                            // All points have been validated at least once
                            result = true;
                            break;
                        }
                    }
                }
            }
            else if (points.Count == 2)
            {
                result = IsValid(points.ToArray());
            }

            if (result)
            {
                ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(points);
                sets.Add(set);
            }

            return sets;
        }