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);
        }
        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);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 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;
        }
 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);
 }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
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");
        }
Exemplo n.º 11
0
        //TODO
        /*    private ValidSetOfTouchPoints ValidateHorizontalLine(TouchPoint2 points)
            {
                ValidSetOfTouchPoints ret = new ValidSetOfTouchPoints();
                Correlation recognizer = new Correlation(points);
                if (Math.Abs(recognizer.RSquared) > TOLERANCE - 0.1)
                {
                    ret.Add(points);
                }
                return ret;
            }*/
        private ValidSetOfTouchPoints ValidateCircle(TouchPoint2 points)
        {
            ValidSetOfTouchPoints ret = new ValidSetOfTouchPoints();
            CircleRecognizer recognizer = new CircleRecognizer(points);
            if (recognizer.R > TOLERANCE + 0.265)
            {
                ret.Add(points);
            }

            return ret;
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
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;
        }
Exemplo n.º 16
0
        public ValidSetOfPointsCollection Validate(ValidSetOfTouchPoints points, string gestureName)
        {
            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();
            ValidSetOfTouchPoints set = new ValidSetOfTouchPoints();
            double length = 0;

                // the length can be calculated for a single touch path. So, we check each
                // touchPoint individually

                foreach (var point in points)
                {
                    bool singlePoint = TrigonometricCalculationHelper.isASinglePoint(point);
                    if (singlePoint)
                    {
                        continue;
                    }  // A point can't be a closed loop

                    if (checkForVariable(point, gestureName))
                    {
                        set.Add(point);
                    }
                    else
                    {
                        length = TrigonometricCalculationHelper.CalculatePathLength(point);
                        if (length >= _data.Min && length <= _data.Max)
                        {
                            set.Add(point);
                        }
                    }

                }

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

            return sets;
        }
Exemplo n.º 17
0
        private ValidSetOfTouchPoints ValidateCheck(TouchPoint2 point)
        {
            ValidSetOfTouchPoints ret = new ValidSetOfTouchPoints();

            PointTranslator.NoiseReduction = PointTranslator.NoiseReductionType.Low;
            List<TouchPoint2> lines = PointTranslator.FindLines(point);

            if (lines.Count == 2)
            {
                // Calculate angle
                var stylusPoints1 = TrigonometricCalculationHelper.removeRedundancy(lines[0].Stroke.StylusPoints);
                var stylusPoints2 = TrigonometricCalculationHelper.removeRedundancy(lines[1].Stroke.StylusPoints);

                double length1 = TrigonometricCalculationHelper.CalculatePathLength(lines[0]);
                double length2 = TrigonometricCalculationHelper.CalculatePathLength(lines[1]);

                if (length1 > length2)
                    return ret;
                int avg1 = stylusPoints1.Count;
                int avg2 = stylusPoints2.Count;

                double set1Angle = TrigonometricCalculationHelper.GetSlopeBetweenPoints(stylusPoints1[avg1 / 4], stylusPoints1[avg1 * 3 / 4]);
                double set2Angle = TrigonometricCalculationHelper.GetSlopeBetweenPoints(stylusPoints2[avg2 / 4], stylusPoints2[avg2 * 3 / 4]);

                double angularDiff = (set1Angle - set2Angle) * 180 / 3.14;

                if (angularDiff < 0)
                    angularDiff = 180 + angularDiff;

                if (angularDiff > 180)
                    angularDiff = angularDiff - 180;

                if (angularDiff < 100 && angularDiff > 75)
                    ret.Add(point);

            }

            return ret;
        }
Exemplo n.º 18
0
        private ValidSetOfTouchPoints ValidateBox(TouchPoint2 points)
        {
            ValidSetOfTouchPoints output = new ValidSetOfTouchPoints();
            int length = points.Stroke.StylusPoints.Count;
            if (length < 1)
            {
                return output;
            }

            List<string> slopes = new List<string>();
            TouchPoint2 newPoints = points.GetEmptyCopy();

            for (int i = 0; i < length - 1; i++)
            {
                var point1 = points.Stroke.StylusPoints[i];
                var point2 = points.Stroke.StylusPoints[i + 1];
                double slope = TrigonometricCalculationHelper.GetSlopeBetweenPoints(point1, point2);
                double distance = TrigonometricCalculationHelper.GetDistanceBetweenPoints(point1, point2);
                string stringSlope = TouchPointExtensions.SlopeToDirection(slope);
                if (distance > 0)
                {
                    newPoints.Stroke.StylusPoints.Add(point1);
                    Correlation recognizer = new Correlation(newPoints);
                    if (Math.Abs(recognizer.RSquared) < TOLERANCE + 0.15)
                    {
                        int linelength = newPoints.Stroke.StylusPoints.Count;
                        double lineSlope = TrigonometricCalculationHelper.GetSlopeBetweenPoints(newPoints.Stroke.StylusPoints[1],
                            newPoints.Stroke.StylusPoints[linelength - 1]);
                        string lineStringSlope = TouchPointExtensions.SlopeToDirection(lineSlope);
                        slopes.Add(lineStringSlope);
                        newPoints = newPoints.GetEmptyCopy();
                    }
                }
            }
            RectangleParser parser = new RectangleParser();
            bool hasRect = parser.Advance(slopes);
            if (hasRect)
            {
                output.Add(points);
            }
            return output;
        }
Exemplo n.º 19
0
        public void DistanceChangedCalculator_Calculate_Test_With_Low_Counts()
        {
            //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;

            Assert.IsTrue(result.Delta == 0);
        }