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
        private static Tristrip gpc_strip_ToTristrip(gpc_tristrip gpc_strip)
        {
            Tristrip tristrip = new Tristrip();

            tristrip.NofStrips = gpc_strip.num_strips;
            tristrip.Strip     = new VertexList[tristrip.NofStrips];
            IntPtr ptr = gpc_strip.strip;

            for (int i = 0; i < tristrip.NofStrips; i++)
            {
                tristrip.Strip[i] = new VertexList();
                gpc_vertex_list gpc_vtx_list = (gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(gpc_vertex_list));
                tristrip.Strip[i].NofVertices = gpc_vtx_list.num_vertices;
                tristrip.Strip[i].Vertex      = new Vertex[tristrip.Strip[i].NofVertices];

                IntPtr ptr2 = gpc_vtx_list.vertex;
                for (int j = 0; j < tristrip.Strip[i].NofVertices; j++)
                {
                    gpc_vertex gpc_vtx = (gpc_vertex)Marshal.PtrToStructure(ptr2, typeof(gpc_vertex));
                    tristrip.Strip[i].Vertex[j].X = gpc_vtx.x;
                    tristrip.Strip[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(tristrip);
        }
Пример #3
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);
        }
Пример #4
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 TriStrip gpc_strip_ToTristrip(gpc_tristrip gpc_strip)
        {
            int      numStrips = gpc_strip.num_strips;
            TriStrip tristrip  = new TriStrip(numStrips);
            IntPtr   ptr       = gpc_strip.strip;

            for (int i = 0; i < numStrips; ++i)
            {
                gpc_vertex_list gpc_vtx_list = (gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(gpc_vertex_list));
                int             numVertices  = gpc_vtx_list.num_vertices;
                tristrip[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));
                    tristrip[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(tristrip);
        }
        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);
        }
        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;
        }