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); }
public static Polygon VectorListsToPolygon(List <List <Vec2> > lists) { Polygon p = new Polygon(lists.Count); int index = 0; foreach (List <Vec2> list in lists) { p.SetContour(index, Vec2d.FromVec2List(list)); p.SetHole(index++, false); } return(p); }