コード例 #1
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PointPolygonTest. Input is not PointPolygonTest.");
            }

            var inp = input as PointSet;

            Point a = inp[0]; Point c = inp[1]; Point d = inp[2];
            var   b = new ConvexPolygon(new Point(c.X, c.Y), new Point(d.X, c.Y), new Point(d.X, d.Y), new Point(c.X, d.Y));

            var x = Intersect.IsIntersected(a, b);

            //var x = Intersect.GetIntersection(b, a);
            if (x)
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(), new PolygonSet(b), DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(), new PolygonSet(b), DrawableElement.Text(0, 0, "Vse ploho")
                }));
            }
            //return new PointSet(x.ToArray());
        }
コード例 #2
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("SegmentCircleTest. Input is not SegmentCircleTest.");
            }

            var inp = input as PointSet;

            Point a = inp[0];
            Point b = inp[1];
            Point c = inp[2];

            Circle  d = new Circle(b.X, b.Y, c.X);
            Segment e = new Segment(new Point(0, 0), a);

            bool x = Intersect.IsIntersected(a, d);

            if (x)
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new SegmentSet(e), new CircleSet(d), DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new SegmentSet(e), new CircleSet(d), DrawableElement.Text(0, 0, "Vse Ploho")
                }));
            }
        }
コード例 #3
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PolygonTest. Input is not PolygonTest.");
            }
            var   inp = input as PointSet;
            Point c = inp[0]; Point d = inp[1]; Point e = inp[2]; Point fe = inp[3];

            ConvexPolygon f1 = new ConvexPolygon(new Point((c.X + d.X) / 2, c.Y), new Point(d.X, (c.Y + d.Y) / 3), new Point(d.X, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2, d.Y), new Point(c.X, 2 * ((d.Y + c.Y) / 3)), new Point(c.X, ((d.Y + c.Y) / 3)));
            ConvexPolygon f2 = new ConvexPolygon(new Point((e.X + fe.X) / 2, e.Y), new Point(fe.X, (e.Y + fe.Y) / 3), new Point(fe.X, 2 * ((fe.Y + e.Y) / 3)), new Point((e.X + fe.X) / 2, fe.Y), new Point(e.X, 2 * ((fe.Y + e.Y) / 3)), new Point(e.X, ((fe.Y + e.Y) / 3)));
            var           x  = Intersect.GetIntersection(f1, f2);

            if (x.Count > 0)
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(x.ToArray()), new PolygonSet(f1, f2), DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(x.ToArray()), new PolygonSet(f1, f2), DrawableElement.Text(0, 0, "Vse ploho")
                }));
            }
        }
コード例 #4
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PointSegmentTest. Input is not PointSegmentTest.");
            }

            var inp = input as PointSet;

            Point   a = inp[0];
            Point   b = inp[1];
            Point   c = inp[2];
            Segment d = new Segment(b, c);

            bool x = Intersect.IsIntersected(a, d);

            if (x)
            {
                return
                    (new DrawableSet(new List <IDrawable>()
                {
                    new SegmentSet(d), DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new SegmentSet(d), DrawableElement.Text(0, 0, "Vse ploho")
                }));
            }
        }
コード例 #5
0
        public void PopulatePort(Port port, string prefix)
        {
            List <string> str = new List <String>();

            foreach (var item in data)
            {
                str.Add(item.Name + " = \t" + item.Value);
            }
            var it = DrawableElement.Text(5, 5, str.ToArray());

            port[prefix + ".Variables"].Populate(it);
        }
コード例 #6
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("SegmentPolygonTest. Input is not SegmentPolygonTest.");
            }

            var inp = input as PointSet;

            Point a = inp[0]; Point c = inp[1]; Point d = inp[2]; Point e = inp[3];

            //a = new Point(10, 10); e = new Point(40, 10); Point ee = new Point(60, 40);
            //Segment b = new Segment(a, e); //Segment bbb = new Segment(e, ee);
            Segment b  = new Segment(10, (c.Y + d.Y) / 2.5, 100, (c.Y + d.Y) / 2.5);
            var     f  = new ConvexPolygon(new Point((c.X + d.X) / 2, c.Y), new Point(d.X, (c.Y + d.Y) / 3), new Point(d.X, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2, d.Y), new Point(c.X, 2 * ((d.Y + c.Y) / 3)), new Point(c.X, ((d.Y + c.Y) / 3)));
            var     fa = new ConvexPolygon(new Point((c.X + d.X) / 2 + 40, c.Y), new Point(d.X + 40, (c.Y + d.Y) / 3), new Point(d.X + 40, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2 + 40, d.Y), new Point(c.X + 40, 2 * ((d.Y + c.Y) / 3)), new Point(c.X + 40, ((d.Y + c.Y) / 3)));
            //var f = new ConvexPolygon(new Point(c.X, c.Y), new Point(d.X, c.Y), new Point(d.X, d.Y), new Point(c.X, d.Y));

            //var f = new ConvexPolygon(new Point(40,40), new Point(70,40), new Point(70,70), new Point(40,70));
            //b = new Segment(30,50,40,50);

            var x  = Intersect.GetIntersection(b, f);// var y = Intersect.GetIntersection(f);
            var xx = Intersect.GetIntersection(b, fa);

            if (x.Count + xx.Count > 0)
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(x.Concat(xx).ToArray()),
                    new SegmentSet(b),
                    new PolygonSet(f, fa),
                    DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(x.Concat(xx).ToArray()),
                    new SegmentSet(b),
                    new PolygonSet(f, fa),
                    DrawableElement.Text(0, 0, "Vse ploho")
                }));
            }
            //return new PointSet(x.ToArray());
        }
コード例 #7
0
        private /*IDrawable*/ Port GetTestInput()
        {
            var p = new Port(new VisualSettings("A", color: "Green", transformer: new TranslateTransformer(10, 20)));

            IDrawable input, output;

            try
            {
                if (SelectedInputMode == InputCreationMode.AutoGeneration)
                {
                    input = SelectedTest.MetaData.MakeInput(null, _currentTestNumber);
                }
                else if (SelectedInputMode == InputCreationMode.FromFile)
                {
                    string filename = FileNames[_currentTestNumber - 1];
                    input = SelectedTest.MetaData.FileReader(filename);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                throw new Exception("There was an error during input creation", e);
            }

            input.PopulatePort(p, "Input."); p.Update();
            try
            {
                output = SelectedTest.RunMethod(input);
                output.PopulatePort(p, "Output."); p.Update();
            }
            catch (Exception e)
            {
                //throw new Exception("There was an error during alogorithm invocation", e);
                p["Error"].Populate(
                    DrawableElement.Text(20, 20, "There was an error during alogorithm invocation\n",
                                         "Error messaage was:", "\t" + e.Message,
                                         "\nStackTrace was:", "\t" + e.StackTrace)
                    );
            }

            return(p);
        }
コード例 #8
0
ファイル: PointSet.cs プロジェクト: anhlehoang410/Game-5
        public void PopulatePort(Port port, string prefix)
        {
            // Form a list of DrawableElement's
            List <DrawableElement> list    = new List <DrawableElement>();
            List <string>          strings = new List <string>();

            foreach (var s in pts)
            {
                list.Add(DrawableElement.Point(s.X, s.Y, "A", "x:" + s.X + " y:" + s.Y));
                strings.Add("x:" + s.X + " y:" + s.Y);
            }

            // To a port's chart named "prefix+..." add a list of DrawableElement's
            port[prefix + "Point"].Populate(list);
            port[prefix + "Text"].Populate(DrawableElement.Text(40, 40, strings.ToArray()));
            port[prefix + "Point"].Settings.Color = "Black";
            //port.Settings.Transformer = new ChainTransformer(new ScaleTransformer(0.3, -0.3), new TranslateTransformer(50, 200));
        }
コード例 #9
0
        IDrawable run(IDrawable input)
        {
            if (!(input is CircleSet))
            {
                throw new Exception("CircleTest. Input is not Circles.");
            }

            var inp = input as CircleSet;

            Circle a = inp[0];
            Circle b = inp[1];

            bool x = Intersect.IsIntersected(a, b);

            if (x)
            {
                return(DrawableElement.Text(0, 0, "Vse horosho"));
            }
            else
            {
                return(DrawableElement.Text(0, 0, "Vse ploho"));
            }
        }
コード例 #10
0
        IDrawable run(IDrawable input)
        {
            if (!(input is PointSet))
            {
                throw new Exception("PolylinePoligonTest. Input is not PolylinePoligonTest.");
            }

            var inp = input as PointSet;

            Point a = inp[0]; Point c = inp[1]; Point d = inp[2]; Point e = inp[4];
            Point polyPoint1 = inp[4];

            Point    aa = new Point(20, 20); e = new Point(30, 20); Point ee = new Point(50, 30);
            Segment  b = new Segment(aa, e); Segment eee = new Segment(e, ee); Segment eae = new Segment(new Point(50, 30), a);
            Polyline polyline = new Polyline(20, 20, 30, 20, 50, 30, a.X, a.Y);

            //Segment b = new Segment(a,e);
            //Segment eee = new Segment(e,new Point(3*(a.X+e.X)/2,4*(a.Y+e.Y)/2));
            //var polyline = new Polyline(new List<Point>() { a, e, new Point((a.X + e.X) / 2, (a.Y + e.Y) / 2) });

            //var f = new ConvexPolygon(new Point(c.X, c.Y), new Point(d.X, c.Y), new Point(d.X, d.Y), new Point(c.X, d.Y));

            var f = new ConvexPolygon(new Point((c.X + d.X) / 2, c.Y), new Point(d.X, (c.Y + d.Y) / 3), new Point(d.X, 2 * ((d.Y + c.Y) / 3)), new Point((c.X + d.X) / 2, d.Y), new Point(c.X, 2 * ((d.Y + c.Y) / 3)), new Point(c.X, ((d.Y + c.Y) / 3)));


            var x = Intersect.GetIntersection(polyline, f);

            if (x.Count > 0)
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(x.ToArray()), new SegmentSet(b, eee, eae), new PolygonSet(f), DrawableElement.Text(0, 0, "Vse horosho")
                }));
            }
            else
            {
                return(new DrawableSet(new List <IDrawable>()
                {
                    new PointSet(x.ToArray()), new SegmentSet(b, eee, eae), new PolygonSet(f), DrawableElement.Text(0, 0, "Vse ploho")
                }));
            }
        }