Exemple #1
0
        private static void Free_gpc_polygon(NativeStructs.gpc_polygon gpc_pol)
        {
            Marshal.FreeCoTaskMem(gpc_pol.hole);
            IntPtr ptr = gpc_pol.contour;

            for (int i = 0; i < gpc_pol.num_contours; i++)
            {
                NativeStructs.gpc_vertex_list gpc_vtx_list = (NativeStructs.gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(NativeStructs.gpc_vertex_list));
                Marshal.FreeCoTaskMem(gpc_vtx_list.vertex);
                ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
            }
        }
Exemple #2
0
 public static void gpc_free_polygon([In] ref NativeStructs.gpc_polygon polygon)
 {
     if (Processor.Architecture == ProcessorArchitecture.X64)
     {
         X64.gpc_free_polygon(ref polygon);
     }
     else if (Processor.Architecture == ProcessorArchitecture.X86)
     {
         X86.gpc_free_polygon(ref polygon);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Exemple #3
0
 public static void gpc_polygon_clip(
     [In] NativeConstants.gpc_op set_operation,
     [In] ref NativeStructs.gpc_polygon subject_polygon,
     [In] ref NativeStructs.gpc_polygon clip_polygon,
     [In, Out] ref NativeStructs.gpc_polygon result_polygon)
 {
     if (Processor.Architecture == ProcessorArchitecture.X64)
     {
         X64.gpc_polygon_clip(set_operation, ref subject_polygon, ref clip_polygon, ref result_polygon);
     }
     else if (Processor.Architecture == ProcessorArchitecture.X86)
     {
         X86.gpc_polygon_clip(set_operation, ref subject_polygon, ref clip_polygon, ref result_polygon);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Exemple #4
0
        private static NativeStructs.gpc_polygon PolygonTo_gpc_polygon(Polygon polygon)
        {
            NativeStructs.gpc_polygon gpc_pol = new NativeStructs.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);
            }

            gpc_pol.hole = Marshal.AllocCoTaskMem(polygon.NofContours * Marshal.SizeOf(typeof(int) /*hole[0]*/));

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

            gpc_pol.contour = Marshal.AllocCoTaskMem(polygon.NofContours * Marshal.SizeOf(typeof(NativeStructs.gpc_vertex_list)));
            IntPtr ptr = gpc_pol.contour;

            for (int i = 0; i < polygon.NofContours; i++)
            {
                NativeStructs.gpc_vertex_list gpc_vtx_list = new NativeStructs.gpc_vertex_list();
                gpc_vtx_list.num_vertices = polygon.Contour[i].NofVertices;
                gpc_vtx_list.vertex       = Marshal.AllocCoTaskMem(polygon.Contour[i].NofVertices * Marshal.SizeOf(typeof(NativeStructs.gpc_vertex)));
                IntPtr ptr2 = gpc_vtx_list.vertex;
                for (int j = 0; j < polygon.Contour[i].NofVertices; j++)
                {
                    NativeStructs.gpc_vertex gpc_vtx = new NativeStructs.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);
        }
Exemple #5
0
        public static Polygon Clip(CombineMode clipMode, Polygon subject_polygon, Polygon clip_polygon)
        {
            Validate(clipMode);

            NativeConstants.gpc_op gpcOp = Convert(clipMode);

            NativeStructs.gpc_polygon gpc_polygon         = new NativeStructs.gpc_polygon();
            NativeStructs.gpc_polygon gpc_subject_polygon = PolygonTo_gpc_polygon(subject_polygon);
            NativeStructs.gpc_polygon gpc_clip_polygon    = PolygonTo_gpc_polygon(clip_polygon);

            NativeMethods.gpc_polygon_clip(gpcOp, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_polygon);

            Polygon polygon = gpc_polygon_ToPolygon(gpc_polygon);

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

            return(polygon);
        }
Exemple #6
0
        private static Polygon gpc_polygon_ToPolygon(NativeStructs.gpc_polygon gpc_polygon)
        {
            Polygon polygon = new Polygon();

            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++)
            {
                NativeStructs.gpc_vertex_list gpc_vtx_list = (NativeStructs.gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(NativeStructs.gpc_vertex_list));
                polygon.Contour[i]             = new VertexList();
                polygon.Contour[i].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++)
                {
                    NativeStructs.gpc_vertex gpc_vtx = (NativeStructs.gpc_vertex)Marshal.PtrToStructure(ptr2, typeof(NativeStructs.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);
        }
Exemple #7
0
 public static extern void gpc_free_polygon([In] ref NativeStructs.gpc_polygon polygon);
Exemple #8
0
 public static extern void gpc_polygon_clip(
     [In] NativeConstants.gpc_op set_operation,
     [In] ref NativeStructs.gpc_polygon subject_polygon,
     [In] ref NativeStructs.gpc_polygon clip_polygon,
     [In, Out] ref NativeStructs.gpc_polygon result_polygon);