private static Polygon gpc_polygon_ToPolygon(gpc_polygon gpc_polygon)
        {
            Polygon polygon = null;

            if (gpc_polygon.num_contours > 0)
            {
                polygon = new Polygon(gpc_polygon.num_contours);
                int[]  holeInt = new int[polygon.NumContours];
                IntPtr ptr     = gpc_polygon.hole;
                if (polygon.NumContours > 0)
                {
                    Marshal.Copy(gpc_polygon.hole, holeInt, 0, polygon.NumContours);
                }
                for (int i = 0; i < polygon.NumContours; ++i)
                {
                    polygon.SetHole(i, holeInt[i] != 0);
                }
                ptr = gpc_polygon.contour;
                for (int i = 0; i < polygon.NumContours; ++i)
                {
                    gpc_vertex_list gpc_vtx_list = (gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(gpc_vertex_list));
                    int             numVertices  = gpc_vtx_list.num_vertices;
                    polygon[i].Capacity = numVertices;
                    IntPtr ptr2 = gpc_vtx_list.vertex;
                    for (int j = 0; j < numVertices; ++j)
                    {
                        gpc_vertex gpc_vtx = (gpc_vertex)Marshal.PtrToStructure(ptr2, typeof(gpc_vertex));
                        polygon[i].Add(new Vec2d(gpc_vtx.x, gpc_vtx.y));
                        ptr2 = (IntPtr)(((int)ptr2) + Marshal.SizeOf(gpc_vtx));
                    }
                    ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
                }
            }
            return(polygon);
        }
示例#2
0
        public static void SavePolygon(string filename, bool writeHoleFlags, Polygon polygon)
        {
            gpc_polygon gpc_polygon = GpcWrapper.PolygonTo_gpc_polygon(polygon);

            IntPtr fp = fopen(filename, "wb");

            gpc_write_polygon(fp, writeHoleFlags?((int)1):((int)0), ref gpc_polygon);
            fclose(fp);

            GpcWrapper.Free_gpc_polygon(gpc_polygon);
        }
示例#3
0
        private static void Free_gpc_polygon(gpc_polygon gpc_pol)
        {
            Marshal.FreeCoTaskMem(gpc_pol.hole);
            IntPtr ptr = gpc_pol.contour;

            for (int i = 0; i < gpc_pol.num_contours; i++)
            {
                gpc_vertex_list gpc_vtx_list = (gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(gpc_vertex_list));
                Marshal.FreeCoTaskMem(gpc_vtx_list.vertex);
                ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
            }
        }
示例#4
0
        public static Tristrip PolygonToTristrip(Polygon polygon)
        {
            gpc_tristrip gpc_strip = new gpc_tristrip();
            gpc_polygon  gpc_pol   = GpcWrapper.PolygonTo_gpc_polygon(polygon);

            gpc_polygon_to_tristrip(ref gpc_pol, ref gpc_strip);
            Tristrip tristrip = GpcWrapper.gpc_strip_ToTristrip(gpc_strip);

            GpcWrapper.Free_gpc_polygon(gpc_pol);
            GpcWrapper.gpc_free_tristrip(ref gpc_strip);

            return(tristrip);
        }
示例#5
0
        public static Polygon ReadPolygon(string filename, bool readHoleFlags)
        {
            gpc_polygon gpc_polygon = new gpc_polygon();

            IntPtr fp = fopen(filename, "rb");

            gpc_read_polygon(fp, readHoleFlags?((int)1):((int)0), ref gpc_polygon);
            Polygon polygon = gpc_polygon_ToPolygon(gpc_polygon);

            gpc_free_polygon(ref gpc_polygon);
            fclose(fp);

            return(polygon);
        }
        public static Polygon Clip( GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon )
        {
            gpc_polygon gpc_polygon         = new gpc_polygon();
            gpc_polygon gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon( subject_polygon );
            gpc_polygon gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon( clip_polygon );

            gpc_polygon_clip( operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_polygon );
            Polygon polygon = GpcWrapper.gpc_polygon_ToPolygon( gpc_polygon );

            GpcWrapper.Free_gpc_polygon( gpc_subject_polygon );
            GpcWrapper.Free_gpc_polygon( gpc_clip_polygon );
            GpcWrapper.gpc_free_polygon( ref gpc_polygon );

            return polygon;
        }
示例#7
0
        public static Tristrip ClipToTristrip(GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon)
        {
            gpc_tristrip gpc_strip           = new gpc_tristrip();
            gpc_polygon  gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon(subject_polygon);
            gpc_polygon  gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon(clip_polygon);

            gpc_tristrip_clip(operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_strip);
            Tristrip tristrip = GpcWrapper.gpc_strip_ToTristrip(gpc_strip);

            GpcWrapper.Free_gpc_polygon(gpc_subject_polygon);
            GpcWrapper.Free_gpc_polygon(gpc_clip_polygon);
            GpcWrapper.gpc_free_tristrip(ref gpc_strip);

            return(tristrip);
        }
示例#8
0
        public static Polygon Clip(GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon)
        {
            gpc_polygon gpc_polygon         = new gpc_polygon();
            gpc_polygon gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon(subject_polygon);
            gpc_polygon gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon(clip_polygon);

            gpc_polygon_clip(operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_polygon);
            Polygon polygon = GpcWrapper.gpc_polygon_ToPolygon(gpc_polygon);

            GpcWrapper.Free_gpc_polygon(gpc_subject_polygon);
            GpcWrapper.Free_gpc_polygon(gpc_clip_polygon);
            GpcWrapper.gpc_free_polygon(ref gpc_polygon);

            return(polygon);
        }
示例#9
0
        private static gpc_polygon PolygonTo_gpc_polygon(GpcPolygon polygon)
        {
            gpc_polygon gpc_pol = new gpc_polygon();

            gpc_pol.num_contours = polygon.NofContours;

            int[] hole = new int[polygon.NofContours];
            for (int i = 0; i < polygon.NofContours; i++)
            {
                hole[i] = (polygon.ContourIsHole[i] ? 1 : 0);
            }
            if (polygon.NofContours == 0)
            {
                //gpc_pol.hole = 0;
            }
            else
            {
                gpc_pol.hole = Marshal.AllocCoTaskMem(polygon.NofContours * Marshal.SizeOf(hole[0]));
            }
            if (polygon.NofContours > 0)
            {
                Marshal.Copy(hole, 0, gpc_pol.hole, polygon.NofContours);
                gpc_pol.contour = Marshal.AllocCoTaskMem(polygon.NofContours * Marshal.SizeOf(new gpc_vertex_list()));
            }
            IntPtr ptr = gpc_pol.contour;

            for (int i = 0; i < polygon.NofContours; i++)
            {
                gpc_vertex_list gpc_vtx_list = new gpc_vertex_list();
                gpc_vtx_list.num_vertices = polygon.Contour[i].NofVertices;
                gpc_vtx_list.vertex       = Marshal.AllocCoTaskMem(polygon.Contour[i].NofVertices * Marshal.SizeOf(new gpc_vertex()));
                IntPtr ptr2 = gpc_vtx_list.vertex;
                for (int j = 0; j < polygon.Contour[i].NofVertices; j++)
                {
                    gpc_vertex gpc_vtx = new gpc_vertex();
                    gpc_vtx.x = polygon.Contour[i].Vertex[j].X;
                    gpc_vtx.y = polygon.Contour[i].Vertex[j].Y;
                    Marshal.StructureToPtr(gpc_vtx, ptr2, false);
                    ptr2 = (IntPtr)(((int)ptr2) + Marshal.SizeOf(gpc_vtx));
                }
                Marshal.StructureToPtr(gpc_vtx_list, ptr, false);
                ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
            }

            return(gpc_pol);
        }
示例#10
0
        private static Polygon Gpc_polygon_ToPolygon(gpc_polygon gpc_polygon)
        {
            Polygon polygon = new Polygon()
            {
                NofContours = gpc_polygon.num_contours
            };

            polygon.ContourIsHole = new bool[polygon.NofContours];
            polygon.Contour       = new VertexList[polygon.NofContours];
            short[] holeShort = new short[polygon.NofContours];
            IntPtr  ptr       = gpc_polygon.hole;

            if (polygon.NofContours > 0)
            {
                Marshal.Copy(gpc_polygon.hole, holeShort, 0, polygon.NofContours);
            }

            for (int i = 0; i < polygon.NofContours; i++)
            {
                polygon.ContourIsHole[i] = (holeShort[i] != 0);
            }

            ptr = gpc_polygon.contour;
            for (int i = 0; i < polygon.NofContours; i++)
            {
                gpc_vertex_list gpc_vtx_list = (gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(gpc_vertex_list));
                polygon.Contour[i] = new VertexList()
                {
                    NofVertices = gpc_vtx_list.num_vertices
                };
                polygon.Contour[i].Vertex = new Vertex[polygon.Contour[i].NofVertices];
                IntPtr ptr2 = gpc_vtx_list.vertex;
                for (int j = 0; j < polygon.Contour[i].NofVertices; j++)
                {
                    gpc_vertex gpc_vtx = (gpc_vertex)Marshal.PtrToStructure(ptr2, typeof(gpc_vertex));
                    polygon.Contour[i].Vertex[j].X = gpc_vtx.x;
                    polygon.Contour[i].Vertex[j].Y = gpc_vtx.y;

                    ptr2 = (IntPtr)(((int)ptr2) + Marshal.SizeOf(gpc_vtx));
                }
                ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
            }

            return(polygon);
        }
        private static gpc_polygon PolygonTo_gpc_polygon(Polygon polygon)
        {
            gpc_polygon gpc_pol = new gpc_polygon();

            if (polygon != null)
            {
                gpc_pol.num_contours = polygon.NumContours;
                int[] hole = new int[polygon.NumContours];
                for (int i = 0; i < polygon.NumContours; ++i)
                {
                    hole[i] = (polygon.IsHole(i) ? 1 : 0);
                }
                gpc_pol.hole = Marshal.AllocCoTaskMem(polygon.NumContours * Marshal.SizeOf(hole[0]));
                if (polygon.NumContours > 0)
                {
                    Marshal.Copy(hole, 0, gpc_pol.hole, polygon.NumContours);
                    gpc_pol.contour = Marshal.AllocCoTaskMem(polygon.NumContours * Marshal.SizeOf(new gpc_vertex_list()));
                }
                IntPtr ptr = gpc_pol.contour;
                for (int i = 0; i < polygon.NumContours; ++i)
                {
                    gpc_vertex_list gpc_vtx_list = new gpc_vertex_list();
                    gpc_vtx_list.num_vertices = polygon[i].Count;
                    gpc_vtx_list.vertex       = Marshal.AllocCoTaskMem(polygon[i].Count * Marshal.SizeOf(new gpc_vertex()));
                    IntPtr ptr2 = gpc_vtx_list.vertex;
                    for (int j = 0; j < polygon[i].Count; ++j)
                    {
                        gpc_vertex gpc_vtx = new gpc_vertex();
                        gpc_vtx.x = polygon[i][j].X;
                        gpc_vtx.y = polygon[i][j].Y;
                        Marshal.StructureToPtr(gpc_vtx, ptr2, false);
                        ptr2 = (IntPtr)(((int)ptr2) + Marshal.SizeOf(gpc_vtx));
                    }
                    Marshal.StructureToPtr(gpc_vtx_list, ptr, false);
                    ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
                }
            }
            return(gpc_pol);
        }
示例#12
0
 private static extern void gpc_write_polygon([In] IntPtr fp, [In] int write_hole_flags, [In] ref gpc_polygon polygon);
示例#13
0
 private static extern void gpc_read_polygon([In] IntPtr fp, [In] int read_hole_flags, [In, Out] ref gpc_polygon polygon);
示例#14
0
 private static extern void gpc_free_polygon([In] ref gpc_polygon polygon);
示例#15
0
 private static extern void gpc_tristrip_clip([In]     GpcOperation set_operation,
                                              [In]     ref gpc_polygon subject_polygon,
                                              [In]     ref gpc_polygon clip_polygon,
                                              [In, Out] ref gpc_tristrip result_tristrip);
示例#16
0
 private static extern void gpc_polygon_to_tristrip([In]     ref gpc_polygon polygon,
                                                    [In, Out] ref gpc_tristrip tristrip);
示例#17
0
 public static extern void gpc_polygon_clip([In]     GpcOperation set_operation,
                                            [In]     ref gpc_polygon subject_polygon,
                                            [In]     ref gpc_polygon clip_polygon,
                                            [In, Out] ref gpc_polygon result_polygon);
示例#18
0
 public static extern void gpc_free_polygon([In] ref gpc_polygon polygon);
        private static gpc_polygon PolygonTo_gpc_polygon(GpcPolygon polygon)
        {
            gpc_polygon gpc_pol = new gpc_polygon();
            gpc_pol.num_contours = polygon.NofContours;

            int[] hole = new int[polygon.NofContours];
            for (int i = 0; i < polygon.NofContours; i++)
                hole[i] = (polygon.ContourIsHole[i] ? 1 : 0);
            if (hole.Length > 0)
            {
                gpc_pol.hole = Marshal.AllocCoTaskMem(polygon.NofContours * Marshal.SizeOf(hole[0]));
                Marshal.Copy(hole, 0, gpc_pol.hole, polygon.NofContours);

                gpc_pol.contour = Marshal.AllocCoTaskMem(polygon.NofContours * Marshal.SizeOf(new gpc_vertex_list()));
                IntPtr ptr = gpc_pol.contour;
                for (int i = 0; i < polygon.NofContours; i++)
                {
                    gpc_vertex_list gpc_vtx_list = new gpc_vertex_list();
                    gpc_vtx_list.num_vertices = polygon.Contour[i].NofVertices;
                    gpc_vtx_list.vertex = Marshal.AllocCoTaskMem(polygon.Contour[i].NofVertices * Marshal.SizeOf(new gpc_vertex()));
                    IntPtr ptr2 = gpc_vtx_list.vertex;
                    for (int j = 0; j < polygon.Contour[i].NofVertices; j++)
                    {
                        gpc_vertex gpc_vtx = new gpc_vertex();
                        gpc_vtx.x = polygon.Contour[i].Vertex[j].X;
                        gpc_vtx.y = polygon.Contour[i].Vertex[j].Y;
                        Marshal.StructureToPtr(gpc_vtx, ptr2, false);
                        ptr2 = (IntPtr)(((int)ptr2) + Marshal.SizeOf(gpc_vtx));
                    }
                    Marshal.StructureToPtr(gpc_vtx_list, ptr, false);
                    ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
                }
            }

            return gpc_pol;
        }
        private static GpcPolygon gpc_polygon_ToPolygon(gpc_polygon gpc_polygon)
        {
            GpcPolygon polygon = new GpcPolygon();

            polygon.NofContours = gpc_polygon.num_contours;
            polygon.ContourIsHole = new bool[polygon.NofContours];
            polygon.Contour = new GpcVertexList[polygon.NofContours];
            short[] holeShort = new short[polygon.NofContours];
            IntPtr ptr = gpc_polygon.hole;
            if (holeShort.Length > 0)
            {
                Marshal.Copy(gpc_polygon.hole, holeShort, 0, polygon.NofContours);
                for (int i = 0; i < polygon.NofContours; i++)
                    polygon.ContourIsHole[i] = (holeShort[i] != 0);

                ptr = gpc_polygon.contour;
                for (int i = 0; i < polygon.NofContours; i++)
                {
                    gpc_vertex_list gpc_vtx_list = (gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(gpc_vertex_list));
                    polygon.Contour[i] = new GpcVertexList();
                    polygon.Contour[i].NofVertices = gpc_vtx_list.num_vertices;
                    polygon.Contour[i].Vertex = new GpcVertex[polygon.Contour[i].NofVertices];
                    IntPtr ptr2 = gpc_vtx_list.vertex;
                    for (int j = 0; j < polygon.Contour[i].NofVertices; j++)
                    {
                        gpc_vertex gpc_vtx = (gpc_vertex)Marshal.PtrToStructure(ptr2, typeof(gpc_vertex));
                        polygon.Contour[i].Vertex[j].X = gpc_vtx.x;
                        polygon.Contour[i].Vertex[j].Y = gpc_vtx.y;

                        ptr2 = (IntPtr)(((int)ptr2) + Marshal.SizeOf(gpc_vtx));
                    }
                    ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
                }
            }

            return polygon;
        }
 private static void Free_gpc_polygon(gpc_polygon gpc_pol)
 {
     Marshal.FreeCoTaskMem(gpc_pol.hole);
     IntPtr ptr = gpc_pol.contour;
     for (int i = 0; i < gpc_pol.num_contours; i++)
     {
         gpc_vertex_list gpc_vtx_list = (gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(gpc_vertex_list));
         Marshal.FreeCoTaskMem(gpc_vtx_list.vertex);
         ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
     }
 }
        public static GpcPolygon ReadPolygon(string filename, bool readHoleFlags)
        {
            gpc_polygon gpc_polygon = new gpc_polygon();

            IntPtr fp = fopen(filename, "rb");
            gpc_read_polygon(fp, readHoleFlags ? ((int)1) : ((int)0), ref gpc_polygon);
            GpcPolygon polygon = gpc_polygon_ToPolygon(gpc_polygon);
            gpc_free_polygon(ref gpc_polygon);
            fclose(fp);

            return polygon;
        }