public void PositionChanged_Test()
        {
            PositionChangedCalculator target = new PositionChangedCalculator();
            int expectedY = 0;
            int expectedX = 0;

            //Setup preamble for 2 touchpoints to be used in calculate

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(3, 6);

            ValidSetOfTouchPoints test = new ValidSetOfTouchPoints();
            test.Add(new TouchPoint2(ti1, new UIElement()));
            test.Add(new TouchPoint2(ti2, new UIElement()));

            PositionChanged actualP = target.Calculate(test) as PositionChanged;

            //Assert that both X and Y of position are correct after calculation
            Assert.AreEqual(expectedX, actualP.X);
            Assert.AreEqual(expectedY, actualP.Y);
        }
예제 #2
0
        public void SlopeChangedCalculator_Calculate_No_History_Test()
        {
            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(3, 6);

            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();
            vp.Add(new TouchPoint2(ti1, new UIElement()));
            vp.Add(new TouchPoint2(ti2, new UIElement()));

            SlopeChangedCalculator sc = new SlopeChangedCalculator();

            SlopeChanged actualP = sc.Calculate(vp) as SlopeChanged;

            double expectedSlope = 26.58;
            double expectedDelta = 0;
            Console.Out.WriteLine(actualP.Delta);
            Assert.IsTrue(expectedDelta == actualP.Delta);
            Assert.IsTrue(expectedSlope == Math.Round(actualP.NewSlope, 2));
        }
        public void DistanceChangedCalculator_Calculate_Test_For_Distance()
        {
            //Setup preamble for 2 touchpoints to be used in calculate

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(2, 6);

            ValidSetOfTouchPoints test = new ValidSetOfTouchPoints();
            test.Add(new TouchPoint2(ti1, new UIElement()));
            test.Add(new TouchPoint2(ti2, new UIElement()));

            //Call appropriate methods
            DistanceChangedCalculator target = new DistanceChangedCalculator();

            DistanceChanged result = target.Calculate(test) as DistanceChanged;
            result.Distance = Math.Round(result.Distance, 2);
            bool actual = result.Distance.Equals(1.41);

            Assert.AreEqual(true, actual);
        }
예제 #4
0
        /// <summary>
        /// Only checks if system has the number of history data as mentioned
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        public ValidSetOfPointsCollection Validate(List<TouchPoint2> points)
        {
            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();

            //Algo: For each point, we need to check if a point has n more touch points in the history.
            //For example, for a point p1 in points collections, we need to check if there is another point
            //p2 where p2.endTime is less than p1.start time. In the same way, is there any p3... and go on
            //upto nth level where n = _data.TouchCount

            ValidSetOfTouchPoints set = new ValidSetOfTouchPoints();

            // Check if enough history data is recorded
            if (TouchHistoryTracker.Count >= _data.TouchCount)
            {
                foreach (var point in points)
                {
                    DateTime earliestValidTime = GetEarliestValidTime(point);
                    Rect location = RuleValidationHelper.GetBoundingBox(point);

                    if (RuleValidationHelper.HasPreviousTouchPoints(location, point, _data.TouchCount, earliestValidTime))
                        set.Add(point);
                }

            }

            if (set.Count > 0)
                sets.Add(set);

            return sets;
        }
예제 #5
0
        public static List<TouchPoint2> analyzeTags(ValidSetOfTouchPoints allpoints)
        {
            var tagTouch = from p in allpoints
                           where p.Tag != null
                           select p;

            List<TouchPoint2> tagTouchList = tagTouch.ToList();
            List<TouchPoint2> pointsList = allpoints.ToList();
            if (tagTouch != null)
            {
                foreach (TouchPoint2 point in pointsList)
                {
                    foreach (TouchPoint2 tagPoint in tagTouchList)
                    {
                        if (point.Tag == tagPoint.Tag)
                            continue;

                        if (pointsSimilar(point, tagPoint))
                            allpoints.Remove(point);

                    }

                }

            }

            return allpoints;
        }
        public void PositionChanged_Exception_Test()
        {
            PositionChangedCalculator target = new PositionChangedCalculator();

            ValidSetOfTouchPoints tps = new ValidSetOfTouchPoints();

            target.Calculate(tps);
        }
 public void DistanceChangedCalculator_Calculate_Test_With_1_Input()
 {
     DistanceChangedCalculator target = new DistanceChangedCalculator();
     TouchPoint2 t2 = new TouchPoint2(new TouchInfo(), new System.Windows.UIElement());
     ValidSetOfTouchPoints set = new ValidSetOfTouchPoints();
     set.Add(t2);
     target.Calculate(set);
 }
예제 #8
0
        public void TouchPointsCalculator_Null_Calculate_Test()
        {
            TouchPointsCalculator tpCalc = new TouchPointsCalculator();
            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();

            TouchPoints returned = tpCalc.Calculate(vp) as TouchPoints;

            Assert.IsTrue(returned.Count == 0);
        }
예제 #9
0
        public IReturnType Calculate(ValidSetOfTouchPoints set)
        {
            TouchPoints points = new TouchPoints();
            foreach (var touchPoint in set)
            {
                points.Add(new TouchInfo() { ActionType = touchPoint.Action.ToTouchAction(), Position = touchPoint.Position, TouchDeviceId = touchPoint.TouchDeviceId });
            }

            return points;
        }
예제 #10
0
        /// <summary>
        /// Creates a copy of the list
        /// </summary>
        /// <param name="self"></param>
        /// <returns></returns>
        public static ValidSetOfTouchPoints Copy(this List<TouchPoint2> self)
        {
            ValidSetOfTouchPoints copy = new ValidSetOfTouchPoints(self.Count);

            foreach (var item in self)
            {
                copy.Add(item);
            }

            return copy;
        }
예제 #11
0
        public IReturnType Calculate(ValidSetOfTouchPoints set)
        {
            TouchPaths paths = new TouchPaths();

            foreach (var item in set)
            {
                paths.Add(item.Stroke.StylusPoints.ToTouchPath(item.TouchDeviceId));
            }

            return paths;
        }
예제 #12
0
        public void SlopeChangedCalculator_Calculate_Low_Count_Test()
        {
            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();
            vp.Add(new TouchPoint2(ti1, new UIElement()));

            SlopeChangedCalculator sc = new SlopeChangedCalculator();

            Assert.AreEqual(null, sc.Calculate(vp));
        }
예제 #13
0
        /// <summary>
        /// Returns top-left position
        /// </summary>
        /// <param name="relatedTouches"></param>
        /// <returns></returns>
        public IReturnType Calculate(ValidSetOfTouchPoints set)
        {
            if (set.Count > 0)
            {
                int len = set[0].Stroke.StylusPoints.Count;
                Position p = new Position();
                p.X = set[0].Stroke.StylusPoints[len - 1].X;
                p.Y = set[0].Stroke.StylusPoints[len - 1].Y;

                return p;
            }
            else
            {
                return null;
            }
        }
예제 #14
0
        public ValidSetOfPointsCollection Validate(System.Collections.Generic.List<TouchPoint2> points)
        {
            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();
            ValidSetOfTouchPoints set = new ValidSetOfTouchPoints();

            foreach (var point in points)
            {
                if (IsEnclosedAreaWithinRange(point.Stroke.StylusPoints))
                    set.Add(point);
            }

            if (set.Count > 0)
                sets.Add(set);

            return sets;
        }
예제 #15
0
        public void TouchPointsCalculator_Calculate_With_A_Count()
        {
            TouchPointsCalculator tpCalc = new TouchPointsCalculator();

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);

            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();
            vp.Add(new TouchPoint2(ti1, new UIElement()));

            TouchPoints returned = tpCalc.Calculate(vp) as TouchPoints;

            Assert.IsTrue(returned.Count == 1);
            Assert.AreEqual(returned[0].ToString(), "1,5");
        }
예제 #16
0
        public IReturnType Calculate(ValidSetOfTouchPoints set)
        {
            if (set.Count != 2)
                throw new InvalidDataSetException(string.Format("Distance can only be calculated between two points. The parameter contains {0} touch point(s)!", set.Count));

            Point p1 = set[0].Position;
            Point p2 = set[1].Position;

            DistanceChanged value = new DistanceChanged();
            value.Distance = TrigonometricCalculationHelper.GetDistanceBetweenPoints(p1, p2);

            if (set[0].Stroke.StylusPoints.Count > 1 && set[1].Stroke.StylusPoints.Count > 1)
            {
                p1 = set[0].Stroke.StylusPoints[set[0].Stroke.StylusPoints.Count - 2].ToPoint();
                p2 = set[1].Stroke.StylusPoints[set[1].Stroke.StylusPoints.Count - 2].ToPoint();
                double prevDistance = TrigonometricCalculationHelper.GetDistanceBetweenPoints(p1, p2);

                value.Delta = value.Distance - prevDistance;
            }

            return value as IReturnType;
        }
예제 #17
0
        public IReturnType Calculate(ValidSetOfTouchPoints set)
        {
            if (set.Count < 1)
            {
                throw new InvalidDataSetException(string.Format("At least one touch point required to calculate position change. The parameter contains {0} touch point(s)!", set.Count));
            }
            else
            {
                PositionChanged val = new PositionChanged();

                if (set[0].Stroke.StylusPoints.Count > 1)
                {
                    Point p1 = set[0].Position;
                    Point p2 = set[0].Stroke.StylusPoints[set[0].Stroke.StylusPoints.Count - 2].ToPoint();

                    val.X = p1.X - p2.X;
                    val.Y = p1.Y - p2.Y;
                }

                return val;
            }
        }
        public ValidSetOfPointsCollection Validate(System.Collections.Generic.List<TouchPoint2> points)
        {
            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();

            if (points.Count > 0)
            {
                Rect parent = points[0].Stroke.GetBounds();
                for (int i = 1; i < points.Count; i++)
                {
                    Rect rect = points[i].Stroke.GetBounds();
                    parent.Union(rect);
                }

                if (parent.Height >= _data.MinHeight && parent.Height <= _data.MaxHeight
                    && parent.Width >= _data.MinWidth && parent.Width <= _data.MaxWidth)
                {
                    ValidSetOfTouchPoints set = new ValidSetOfTouchPoints(points);
                    sets.Add(set);
                }
            }
            return sets;
        }
예제 #19
0
        public IReturnType Calculate(ValidSetOfTouchPoints set)
        {
            SlopeChanged sc = new SlopeChanged();

            if (set.Count != 2)
                throw new InvalidDataSetException("Slope can only be calculated for two touch points!");

            // Calculate current slope
            sc.NewSlope = TrigonometricCalculationHelper.GetSlopeBetweenPoints(set[0].Position, set[1].Position) * 180 / 3.14;

            // Check if enough history data is available
            if (set[0].Stroke.StylusPoints.Count > 1 && set[1].Stroke.StylusPoints.Count > 1)
            {
                // Calculate slope for last position
                double prevSlope = TrigonometricCalculationHelper.GetSlopeBetweenPoints(
                    set[0].Stroke.StylusPoints[set[0].Stroke.StylusPoints.Count - 2],
                    set[1].Stroke.StylusPoints[set[1].Stroke.StylusPoints.Count - 2]) * 180 / 3.14;

                sc.Delta = sc.NewSlope - prevSlope;
            }

            return sc;
        }
예제 #20
0
        public void InfoCalculator_Valid_Input_Test()
        {
            //Setup preamble for 2 touchpoints to be used in calculate

            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 6);

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(2, 5);

            ValidSetOfTouchPoints test = new ValidSetOfTouchPoints();
            test.Add(new TouchPoint2(ti1, new UIElement()));
            test.Add(new TouchPoint2(ti2, new UIElement()));

            //Call appropriate methods to test the calculate
            InfoCalculator target = new InfoCalculator();
            Info result = target.Calculate(test) as Info;

            Assert.IsTrue(result.Message == string.Empty);
        }
예제 #21
0
        public ValidSetOfPointsCollection Validate(System.Collections.Generic.List<TouchPoint2> points)
        {
            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();
            ValidSetOfTouchPoints set = new ValidSetOfTouchPoints();

            foreach (var point in points)
            {
                if (IsClosedLoop(point))
                    set.Add(point);
            }

            if (set.Count > 0)
                sets.Add(set);

            return sets;
        }
예제 #22
0
        public void SlopeChangedCalculator_Calculate_With_History_Test()
        {
            TouchInfo ti1 = new TouchInfo();
            ti1.TouchDeviceId = 2;
            ti1.ActionType = TouchAction2.Down;
            ti1.Position = new Point(1, 5);
            TouchPoint2 tp1 = new TouchPoint2(ti1, new UIElement());
            tp1.Stroke.StylusPoints.Add(new System.Windows.Input.StylusPoint());
            tp1.Stroke.StylusPoints.Add(new System.Windows.Input.StylusPoint());

            TouchInfo ti2 = new TouchInfo();
            ti2.TouchDeviceId = 2;
            ti2.ActionType = TouchAction2.Down;
            ti2.Position = new Point(3, 6);
            TouchPoint2 tp2 = new TouchPoint2(ti1, new UIElement());
            tp2.Stroke.StylusPoints.Add(new System.Windows.Input.StylusPoint());
            tp2.Stroke.StylusPoints.Add(new System.Windows.Input.StylusPoint());

            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();
            vp.Add(tp1);
            vp.Add(tp2);

            SlopeChangedCalculator sc = new SlopeChangedCalculator();

            SlopeChanged actualP = sc.Calculate(vp) as SlopeChanged;

            double expectedSlope = 0;
            double expectedDelta = 0;

            Assert.IsTrue(expectedDelta == actualP.Delta);
            Assert.AreEqual(expectedSlope, Math.Round(actualP.NewSlope, 2));
        }
예제 #23
0
 private ValidSetOfTouchPoints ValidateLine(TouchPoint2 points)
 {
     ValidSetOfTouchPoints ret = new ValidSetOfTouchPoints();
     Correlation recognizer = new Correlation(points);
     if (Math.Abs(recognizer.RSquared) > .1)
     {
         ret.Add(points);
     }
     return ret;
 }
예제 #24
0
        public ValidSetOfPointsCollection Validate(List<TouchPoint2> points)
        {
            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();
            ValidSetOfTouchPoints list = new ValidSetOfTouchPoints();
            List<Queue<int>> PointList = new List<Queue<int>>();
            Queue<int> AddQueue;

            foreach (var point in points)
            {

                int length = point.Stroke.StylusPoints.Count;
                bool continuous = true;
                int step = 1;
                AddQueue = new Queue<int>();
                for (int i = 0; i < length - step; i = i + step)
                {
                    var p1 = point.Stroke.StylusPoints[i];
                    var p2 = point.Stroke.StylusPoints[i + step];
                    double slope = TrigonometricCalculationHelper.GetSlopeBetweenPoints(p1, p2);
                    String stringSlope = TouchPointExtensions.SlopeToDirection(slope);
                    double dist = TrigonometricCalculationHelper.GetDistanceBetweenPoints(p1, p2);
                    if (dist == 0)
                    {

                        continue;
                    }
                    if (stringSlope.Equals(_data.Values))
                    {
                        if (!continuous)
                        {
                            continuous = true;
                            PointList.Add(AddQueue);
                            AddQueue = new Queue<int>();
                        }
                        AddQueue.Enqueue(i);
                    }
                    else
                    {
                        continuous = false;
                    }
                }

                if (AddQueue.Count > 0)
                {
                    PointList.Add(AddQueue);
                }

                //Add seperate points for each queue made
                foreach (var queue in PointList)
                {
                    TouchPoint2 p = point.GetEmptyCopy();
                    while (queue.Count > 0)
                    {
                        int i = queue.Dequeue();
                        StylusPoint newPoint = point.Stroke.StylusPoints[i];
                        p.Stroke.StylusPoints.Add(newPoint);
                    }
                    if (p.Stroke.StylusPoints.Count > 1)
                    {
                        list.Add(p);
                    }
                }
            }
            if (list.Count > 0)
            {
                sets.Add(new ValidSetOfTouchPoints(points));
               // sets.Add(list);
            }
            return sets;
        }
예제 #25
0
        public static List<String> TouchPointsToGDL(ValidSetOfTouchPoints allpoints)
        {
            if (allpoints == null)
                return null;

            List<IPrimitiveConditionData> primitives;
            SetOfPrimitives setOfPrimitives = new SetOfPrimitives();
            List<TouchPoint2> simplegestures = new List<TouchPoint2>();
            primitives = GestureLanguageProcessor.GetAllPrimitives();

            SetOfPrimitives sample = new SetOfPrimitives();

            if ((allpoints.Count == 1) && (PointTranslator.BreakIntoSteps))
                simplegestures = PointTranslator.FindLines(allpoints[0]);
            else
            {
                simplegestures = PointTranslator.analyzeTags(allpoints);
                simplegestures = PointTranslator.removeHandRedundancy(simplegestures);
            }
            //=============================

            var simplePrimitives = from p in primitives where p.isComplex() == false select p;
            var complexPrimitives = from p in primitives where p.isComplex() == true select p;
            sample.AddRange(loadPrimitives(simplegestures, simplePrimitives));
            sample.AddRange(loadPrimitives(simplegestures, complexPrimitives));

            Add(sample);
            return PrimitiveToGDL(sample);
        }
 public ValidSetOfTouchPoints Get(ValidSetOfTouchPoints points)
 {
     throw new NotImplementedException();
 }
예제 #27
0
 public IReturnType Calculate(ValidSetOfTouchPoints set)
 {
     return new Info() { Message = Message };
 }
예제 #28
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;
        }
예제 #29
0
        public void SlopeChangedCalculator_Calculate_Null_Test()
        {
            ValidSetOfTouchPoints vp = new ValidSetOfTouchPoints();

            SlopeChangedCalculator sc = new SlopeChangedCalculator();

            Assert.AreEqual(null, sc.Calculate(vp));
        }
        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;
        }