예제 #1
0
        //[Benchmark(Description = "from Ienumerable")]
        //[Arguments(10, 4)]
        //[Arguments(20, 4)]
        //[Arguments(10, 4000)]
        //[Arguments(20, 10000)]
        //[Theory]
        //[InlineData(10, 4)]
        //[InlineData(20, 4)]
        //[InlineData(10, 4000)]
        //[InlineData(2, 10000)]
        public void Area(double radius, int numSides)
        {
            var area = 0.5 * radius * radius * numSides * Math.Sin(2 * Math.PI / numSides);

            var polygon = TestCases.MakeCircularPolygon(numSides, radius);

            Assert.Equal(area, polygon.Area(), 10);
        }
예제 #2
0
        //[Benchmark(Description = "from Ienumerable")]
        //[Arguments(10, 4)]
        //[Arguments(20, 4)]
        //[Arguments(10, 4000)]
        //[Arguments(20, 10000)]
        //[Theory]
        //[InlineData(10, 4)]
        //[InlineData(20, 4)]
        //[InlineData(10, 4000)]
        //[InlineData(2, 10000)]
        public void Perimeter(double radius, int numSides)
        {
            var perimeter = 2 * radius * numSides * Math.Sin(Math.PI / numSides);

            var polygon = TestCases.MakeCircularPolygon(numSides, radius);

            Assert.Equal(perimeter, polygon.Perimeter(), 10);
        }
예제 #3
0
        internal static void DebugBoolean()
        {
            Vector2[][] coords1, coords2;
            (coords1, coords2) = TestCases.MakeBumpyRings(12, 25, 0);
            Presenter.ShowAndHang(coords1, coords2);

            var result = TestCases.C2Poly(coords1).Intersect(TestCases.C2Poly(coords2));

            Presenter.ShowAndHang(result);
        }
예제 #4
0
        public static void TestTriangulate()
        {
            //var testcase = new Polygon(TestCases.EdgeCases["hand"].Item1[0]);
            var testcase = new Polygon(TestCases.MakeStarryCircularPolygon(13, 10, 7));

            //testcase.Transform(Matrix3x3.CreateRotation(Math.PI));
            Presenter.ShowAndHang(testcase);
            var triangles = testcase.TriangulateToCoordinates();

            Presenter.ShowAndHang(triangles);
        }
예제 #5
0
 internal static void TestRemoveSelfIntersect()
 {
     for (int i = 0; i < 20; i++)
     {
         Console.WriteLine(i);
         //var coords = MakeWavyCircularPolygon(rand(500), rand(30), rand(300), rand(15.0)).ToList();
         var coords = TestCases.MakeRandomComplexPolygon(100, 30).ToList();
         Presenter.ShowAndHang(coords);
         var polygon  = new Polygon(coords);
         var polygons = polygon.RemoveSelfIntersections(ResultType.BothPermitted);
         Presenter.ShowAndHang(polygons);
         //Presenter.ShowAndHang(polygons.Path);
         //Presenter.ShowAndHang(new[] { coords }, new[] { polygon.Path });
     }
 }
예제 #6
0
        private static void Run()
        {
            #region Polygon Functions
            var    poly1 = new Polygon(TestCases.MakeCircularPolygon(4, 4));
            double area  = poly1.Area;
            var    poly2 = new Polygon(TestCases.MakeCircularPolygon(3, 3));
            poly1.AddInnerPolygon(new Polygon(TestCases.MakeCircularPolygon(3, 3)));
            poly1.BoundingRectangle();
            poly1.ConvertTo3DLocations(Vector3.UnitX, 1.0);
            poly1.ConvexHull2D();
            poly1.ConvertTo3DLocations(Vector3.UnitX, 1.0);
            var tessFaces = poly1.ExtrusionFacesFrom2DPolygons(Vector3.UnitX, 1.0, 4.3);
            poly1.GetPolygonInteraction(poly2);

            bool isItTrueThat = poly1.IsCircular(out var minCircle);
            isItTrueThat = poly1.IsConvex();
            isItTrueThat = poly1.IsPositive;
            var           poly3         = new Polygon(TestCases.MakeCircularPolygon(5, 5));
            var           intersections = poly1.GetPolygonInteraction(poly2);
            PolygonEdge[] lines         = poly1.Edges;
            var           extrema       = poly1.MaxX;
            extrema = poly1.MaxY;
            extrema = poly1.MinX;
            extrema = poly1.MinY;
            List <Vertex2D> points = poly1.Vertices;
            poly1.Reverse();
            #endregion

            List <Vector2> a = poly1.Path;

            #region IEnumerable<Vector2>
            a.Area();
            a.BoundingRectangle();
            a.ConvertTo3DLocations(Vector3.UnitX, 1.0);
            a.ConvexHull2D();
            var b = TestCases.MakeCircularPolygon(5, 5);
            //a.Difference(b);
            var length = a.GetLengthAndExtremePoints(new Vector2(1, 1), out List <Vector2> bottomPoints,
                                                     out List <Vector2> topPoints);
            //a.Intersection(b);
            a.IsRectangular(out var dimensions);
            a.MinimumCircle();
            //a.OffsetMiter(5.0);
            //a.OffsetRound(5.0);
            //a.OffsetSquare(5.0);
            a.Perimeter();
            a.Simplify();
            a.Simplify(10);
            //a.Union(b);
            //a.Xor(b);
            #endregion

            #region IEnumerable<IEnumerable<Vector2>>
            var c = (IEnumerable <IEnumerable <Vector2> >)(new[] { TestCases.MakeCircularPolygon(4, 4) });
            var d = (IEnumerable <IEnumerable <Vector2> >)(new[] { TestCases.MakeCircularPolygon(5, 5) });
            c.Area();
            c.Create2DMedialAxis();
            //c.Difference(d);
            //c.Intersection(d);
            //c.OffsetMiter(5.0);
            //c.OffsetRound(5.0);
            //c.OffsetSquare(5.0);
            c.Perimeter();
            c.ExtrusionFacesFrom2DPolygons(Vector3.UnitX, 1.0, 4.0);
            c.Simplify();
            c.Simplify(10);
            c.SliceAtLine(Vector2.UnitX, 1.0, out var negativeSidePolys, out var positiveSidePolys);
            //c.Triangulate(out var groupOfLoops, out var isPositive);
            //c.Union(b);
            //c.Xor(b);
            #endregion
        }