int32_t __stdcall gpcClipPoly(IGPC IGPC_, TGPCOp Operation, PGPCPolygon SubjPoly, PGPCPolygon ClipPoly, PGPCPolygon Res);
function gpcClipPoly(const IGPC_: IGPC; Operation: TGPCOp; SubjPoly, ClipPoly, Res: PGPCPolygon): Integer; stdcall;
Purpose. Perform a boolean polygon operation (difference/intersection/ XOR/union) between two polygons, each of which may have multiple contours (supporting holes and disjoint pieces via the standard GPC even-odd convention), writing the result into Res.
Description. Implemented via a real Greiner-Hormann polygon-clipping algorithm (correct for arbitrary simple polygons, including concave ones), not a bounding-box approximation. Operation selects the boolean op: gpcDiff (Subj − Clip), gpcInt (intersection), gpcXor (symmetric difference — implemented internally as two difference passes, (A−B) ∪ (B−A), run and accumulated separately since there is no single-pass XOR primitive in the underlying clipper), gpcUnion. Disjoint and nested input contours are resolved by geometric containment; any holes produced by the operation are emitted as additional result contours, to be interpreted with even-odd fill (matching the GPC convention this port mirrors — note the LumasPDF variant's gpc_polygon has no separate hole-flag array unlike the original C GPC library, so hole-vs-solid status is implicit in even-odd winding, not an explicit per-contour flag). SubjPoly/ClipPoly are read-only; Res is fully caller-owned output memory (see gpcAddVertex's memory-ownership note) that the caller must free.
Parameters.
| Parameter | Description |
|---|---|
IGPC_ | Context handle (unused for any per-call state). |
Operation | gpcDiff(0)/gpcInt(1)/gpcXor(2)/gpcUnion(3). |
SubjPoly, ClipPoly | Read-only input polygons (each may have multiple contours). |
Res | Output: freshly AllocMem-allocated result contours; caller must FreeMem each contour's vertex array and then the contour array. |
Return value. 0 on success; -1 if SubjPoly/ClipPoly/Res is null.
See also. gpcAddVertex.
C# (P/Invoke)
public static extern int gpcClipPoly(IntPtr IGPC_, TGPCOp Operation, IntPtr SubjPoly, IntPtr ClipPoly, IntPtr Res);
Polygon Clipper
gpcClipPoly
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.