示例#1
0
        public static Polygon2f FromTriangle(Vector2f A, Vector2f B, Vector2f C)
        {
            Polygon2f polygon = new Polygon2f(3);

            polygon.Positions[0] = A;
            polygon.Positions[1] = B;
            polygon.Positions[2] = C;

            polygon.CalculatePolygon();
            polygon.MakeCCW();
            return(polygon);
        }
示例#2
0
        public static Polygon2f FromBox(Vector2f min, Vector2f max)
        {
            Polygon2f polygon = new Polygon2f(4);

            polygon.Positions[0] = min;
            polygon.Positions[1] = new Vector2f(max.x, min.y);
            polygon.Positions[2] = max;
            polygon.Positions[3] = new Vector2f(min.x, max.y);

            polygon.CalculatePolygon();
            polygon.MakeCCW();
            return(polygon);
        }
示例#3
0
文件: Polygon2f.cs 项目: andybak/CGAL
        public void AddHole(Polygon2f hole)
        {
            if (hole.HasHoles)
            {
                throw new  NotImplementedException("Hole with holes not implemented.");
            }

            if (Holes == null)
            {
                Holes = new List <Polygon2f>();
            }

            Holes.Add(hole);
        }
示例#4
0
        public static void PushPolygon(Polygon2f polygon)
        {
            CGAL_PushPolygon(polygon.Positions, polygon.Positions.Length);

            if (polygon.HasHoles)
            {
                int numHoles = polygon.Holes.Count;
                for (int i = 0; i < numHoles; i++)
                {
                    Polygon2f hole = polygon.Holes[i];
                    CGAL_AddHole(hole.Positions, hole.Positions.Length);
                }
            }
        }
示例#5
0
        private static Polygon2f CreatePolygon(int index)
        {
            int numPoints = CGAL_NumPolygonPoints(index);

            Polygon2f polygon = new Polygon2f(numPoints);

            for (int i = 0; i < numPoints; i++)
            {
                polygon.Positions[i] = CGAL_GetPolygonPoint2f(index, i);
            }

            polygon.CalculatePolygon();

            return(polygon);
        }
示例#6
0
        public static Polygon2f FromStar4(Vector2f center, float scale)
        {
            Polygon2f polygon = new Polygon2f(8);

            polygon.Positions[0] = new Vector2f(0, -1) * scale;
            polygon.Positions[1] = new Vector2f(0.2f, -0.2f) * scale;
            polygon.Positions[2] = new Vector2f(1, 0) * scale;
            polygon.Positions[3] = new Vector2f(0.2f, 0.2f) * scale;
            polygon.Positions[4] = new Vector2f(0, 1) * scale;
            polygon.Positions[5] = new Vector2f(-0.2f, 0.2f) * scale;
            polygon.Positions[6] = new Vector2f(-1, 0) * scale;
            polygon.Positions[7] = new Vector2f(-0.2f, -0.2f) * scale;

            polygon.CalculatePolygon();
            polygon.MakeCCW();
            return(polygon);
        }
示例#7
0
        public static List <Polygon2f> Partition(Polygon2f polygon, PARTITION_METHOD method = PARTITION_METHOD.APPROX)
        {
            if (!polygon.IsSimple)
            {
                throw new ArgumentException("Polygon must be simple.");
            }

            if (!polygon.IsCCW)
            {
                throw new ArgumentException("Polygon must have counter clock wise orientation. Reverse polygon.");
            }

            if (polygon.HasHoles)
            {
                throw new NotImplementedException("Polygon with holes not implemented.");
            }

            CGAL_LoadPoints(polygon.Positions, polygon.Positions.Length);

            int numPolygons = PerformPartition(method);

            List <Polygon2f> partition = new List <Polygon2f>(numPolygons);

            for (int i = 0; i < numPolygons; i++)
            {
                int       numPoints = CGAL_GetPolygonSize(i);
                Polygon2f poly      = new Polygon2f(numPoints);

                for (int j = 0; j < numPoints; j++)
                {
                    poly.Positions[j] = CGAL_GetPolygonVector2f(i, j);
                }

                poly.CalculatePolygon();
                partition.Add(poly);
            }

            CGAL_Clear();

            return(partition);
        }
示例#8
0
        public static Polygon2f FromCircle(Vector2f center, float radius, int segments)
        {
            Polygon2f polygon = new Polygon2f(segments);

            float pi   = (float)Math.PI;
            float fseg = segments;

            for (int i = 0; i < segments; i++)
            {
                float theta = 2.0f * pi * i / fseg;

                float x = radius * (float)Math.Cos(theta);
                float y = radius * (float)Math.Sin(theta);

                polygon.Positions[i] = center + new Vector2f(x, y);
            }

            polygon.CalculatePolygon();
            polygon.MakeCCW();
            return(polygon);
        }
示例#9
0
        public static bool DoIntersect(Polygon2f A, Polygon2f B)
        {
            if (!A.IsSimple || !B.IsSimple)
            {
                throw new ArgumentException("Polygon must be simple.");
            }

            if (!A.IsCCW || !B.IsCCW)
            {
                throw new ArgumentException("Polygon must have counter clock wise orientation. Reverse polygon.");
            }

            LoadPoints(A, B);
            AddHoles(A, B);

            bool intersect = CGAL_DoIntersect();

            CGAL_Clear();

            return(intersect);
        }
示例#10
0
        public static Polygon2f Simplify(Polygon2f polygon, float threshold, SIMPLIFY_METHOD method = SIMPLIFY_METHOD.SQUARE_DIST)
        {
            if (!polygon.IsSimple)
            {
                throw new ArgumentException("Polygon must be simple.");
            }

            if (polygon.HasHoles)
            {
                throw new NotImplementedException("Polygon with holes not implemented.");
            }

            if (polygon.VerticesCount < 3)
            {
                Polygon2f simplified = new Polygon2f(polygon.Positions);
                simplified.CalculatePolygon();
                return(simplified);
            }
            else
            {
                CGAL_LoadPoints(polygon.Positions, polygon.Positions.Length);

                int size = PerformSimplification(threshold, method);

                Polygon2f simplified = new Polygon2f(size);

                for (int i = 0; i < size; i++)
                {
                    simplified.Positions[i] = CGAL_GetSimplifiedVector2f(i);
                }

                simplified.CalculatePolygon();

                CGAL_Clear();

                return(simplified);
            }
        }
示例#11
0
 private static void AddHoles(Polygon2f A, Polygon2f B)
 {
     AddHoles(A, CGAL_A_AddHole);
     AddHoles(B, CGAL_B_AddHole);
 }
示例#12
0
 private static void LoadPoints(Polygon2f A, Polygon2f B)
 {
     CGAL_A_LoadPoints(A.Positions, A.Positions.Length);
     CGAL_B_LoadPoints(B.Positions, B.Positions.Length);
 }
示例#13
0
 public static bool SymmetricDifference(Polygon2f A, Polygon2f B, out List <Polygon2f> polygons)
 {
     return(PerformBoolean(A, B, CGAL_SymmetricDifference, out polygons));
 }
示例#14
0
 public static bool Intersection(Polygon2f A, Polygon2f B, out List <Polygon2f> polygons)
 {
     return(PerformBoolean(A, B, CGAL_Intersection, out polygons));
 }