示例#1
0
        public MainLayer() : base(CCColor4B.AliceBlue)
        {
            _canvasNode           = new CCDrawNode();
            _recognizerCanvasNode = new CCDrawNode();
            _lineRecognizer       = new LineRecognizer();
            _shapeNode            = new CCDrawNode();

            AddChild(_shapeNode);
            AddChild(_canvasNode);
            AddChild(_recognizerCanvasNode);

            if (_drawDebug)
            {
                _lineRecognizer.LineFound = (line) => _recognizerCanvasNode.DrawLine(line.P1.ToCCPoint(), line.P2.ToCCPoint(), 5, CCColor4B.Blue);
            }

            // Register patterns (concept)
            _patternEvaluator = new PatternEvaluator();
            _patternEvaluator.Add("button").When(Pattern.WideRectangle);
            _patternEvaluator.Add("image").When(Pattern.Cross);
            _patternEvaluator.Add("text").When(p => p.Repetitive(ip => ip.MovesRight().MovesLeftAndDown()).MovesRight());
            _patternEvaluator.Add("entry").When(p => p.MovesDown().MovesRight().MovesUp().Bounds(BoundsDescriptor.IsWide));
            _patternEvaluator.Add("lineoftext").When(p => p.MovesRight());
            _patternEvaluator.Add("delete").When(p => p.MovesRightAndUp());
        }
        public void ShadyRectangleTest3()
        {
            // Arrange
            var json    = "[{\"X\":188.64,\"Y\":760.510132,\"Magnitude\":783.55644978191685},{\"X\":344.16,\"Y\":760.510132,\"Magnitude\":834.75850923834139},{\"X\":491.04,\"Y\":760.510132,\"Magnitude\":905.26015631801226},{\"X\":594.720032,\"Y\":751.868,\"Magnitude\":958.64350878686128},{\"X\":650.88,\"Y\":751.868,\"Magnitude\":994.45977371870242},{\"X\":696.96,\"Y\":751.868,\"Magnitude\":1025.2115552492219},{\"X\":735.84,\"Y\":754.748657,\"Magnitude\":1054.0901672570312},{\"X\":741.6,\"Y\":754.748657,\"Magnitude\":1058.1191139821462},{\"X\":743.040039,\"Y\":746.106567,\"Magnitude\":1052.98789619908},{\"X\":741.6,\"Y\":679.85,\"Magnitude\":1006.0648652513728},{\"X\":732.959961,\"Y\":615.033752,\"Magnitude\":956.81598072965869},{\"X\":730.08,\"Y\":573.263367,\"Magnitude\":928.24981494920291},{\"X\":728.639954,\"Y\":553.098267,\"Magnitude\":914.78624526127294},{\"X\":718.56,\"Y\":545.8965,\"Magnitude\":902.403148124158},{\"X\":637.92,\"Y\":524.2911,\"Magnitude\":825.72576419871984},{\"X\":580.319946,\"Y\":524.2911,\"Magnitude\":782.08207569692217},{\"X\":478.080017,\"Y\":540.135,\"Magnitude\":721.32262650989753},{\"X\":336.960022,\"Y\":553.098267,\"Magnitude\":647.65712296358333},{\"X\":247.68,\"Y\":558.8597,\"Magnitude\":611.2851387838997},{\"X\":224.64,\"Y\":563.1808,\"Magnitude\":606.32971821852334},{\"X\":220.319992,\"Y\":609.272339,\"Magnitude\":647.8840033620246},{\"X\":200.159988,\"Y\":733.1433,\"Magnitude\":759.975746163816},{\"X\":197.28,\"Y\":782.11554,\"Magnitude\":806.612741732468},{\"X\":195.84,\"Y\":784.9963,\"Magnitude\":809.05652388604642}]";
            var points  = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Point> >(json);
            var lineRec = new LineRecognizer();

            lineRec.RegisterPoints(points);
            var path = lineRec.End();
        }
        public void ShadyRectangleTest1()
        {
            // Arrange
            var json    = "[{ \"X\":267.042267,\"Y\":921.1268} ,{ \"X\":322.8169,\"Y\":921.1268} ,{ \"X\":365.0704,\"Y\":921.1268} ,{ \"X\":417.4648,\"Y\":921.1268} ,{ \"X\":456.338,\"Y\":921.1268} ,{ \"X\":485.0704,\"Y\":921.1268} ,{ \"X\":498.591553,\"Y\":921.1268} ,{ \"X\":508.7324,\"Y\":921.1268} ,{ \"X\":520.563354,\"Y\":921.1268} ,{ \"X\":523.943665,\"Y\":921.1268} ,{ \"X\":527.324,\"Y\":921.1268} ,{ \"X\":527.324,\"Y\":917.74646} ,{ \"X\":527.324,\"Y\":907.605652} ,{ \"X\":527.324,\"Y\":890.7042} ,{ \"X\":530.7042,\"Y\":868.7324} ,{ \"X\":534.084534,\"Y\":843.3803} ,{ \"X\":537.4648,\"Y\":816.338} ,{ \"X\":537.4648,\"Y\":797.74646} ,{ \"X\":537.4648,\"Y\":774.0845} ,{ \"X\":537.4648,\"Y\":758.8732} ,{ \"X\":537.4648,\"Y\":748.7324} ,{ \"X\":537.4648,\"Y\":745.3521} ,{ \"X\":537.4648,\"Y\":741.971863} ,{ \"X\":537.4648,\"Y\":736.9014} ,{ \"X\":534.084534,\"Y\":736.9014} ,{ \"X\":508.7324,\"Y\":736.9014} ,{ \"X\":488.4507,\"Y\":736.9014} ,{ \"X\":427.605652,\"Y\":736.9014} ,{ \"X\":378.591553,\"Y\":736.9014} ,{ \"X\":329.577454,\"Y\":736.9014} ,{ \"X\":287.323944,\"Y\":736.9014} ,{ \"X\":258.591553,\"Y\":736.9014} ,{ \"X\":241.690155,\"Y\":736.9014} ,{ \"X\":234.929581,\"Y\":736.9014} ,{ \"X\":224.788742,\"Y\":736.9014} ,{ \"X\":221.408447,\"Y\":736.9014} ,{ \"X\":218.028168,\"Y\":736.9014} ,{ \"X\":214.647873,\"Y\":736.9014} ,{ \"X\":212.957748,\"Y\":747.0423} ,{ \"X\":209.577454,\"Y\":767.324} ,{ \"X\":206.197189,\"Y\":799.436646} ,{ \"X\":206.197189,\"Y\":848.450745} ,{ \"X\":206.197189,\"Y\":880.563354} ,{ \"X\":206.197189,\"Y\":905.9155} ,{ \"X\":206.197189,\"Y\":922.8169} ,{ \"X\":206.197189,\"Y\":932.9577} ,{ \"X\":206.197189,\"Y\":939.7183} ,{ \"X\":206.197189,\"Y\":944.788757} ,{ \"X\":206.197189,\"Y\":949.859131} ,{ \"X\":209.577454,\"Y\":949.859131} ]";
            var points  = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Point> >(json);
            var lineRec = new LineRecognizer();

            lineRec.RegisterPoints(points);
            var path = lineRec.End();

            var evaluator = new PatternEvaluator();

            evaluator.Add("rect").When(Pattern.WideRectangle);

            // Act
            var result = evaluator.Evaluate(path);

            // Assert
            Assert.True(result.IsValid);
        }