Esempio n. 1
0
        private static Paths PolygonToClprPaths(Polygon polygon)
        {
            Paths result = new List <List <IntPoint> >(polygon.NumContours);

            for (int j = 0; j < polygon.NumContours; ++j)
            {
                result.Add(new List <IntPoint>(polygon[j].Count));
                for (int i = 0; i < polygon[j].Count; ++i)
                {
                    Vec2d    v = polygon[j][i];
                    IntPoint p;
                    p.X = (Int32)(v.X * PrecisionScale);
                    p.Y = (Int32)(v.Y * PrecisionScale);
                    result[j].Add(p);
                }
                if (Clipper.Orientation(result[j]) == polygon.IsHole(j))
                {
                    result[j].Reverse();
                }
            }
            return(result);
        }
        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);
        }