API referenceGraphics

gpcClipPoly

Perform a boolean polygon operation (difference/intersection/

C
int32_t __stdcall gpcClipPoly(IGPC IGPC_, TGPCOp Operation, PGPCPolygon SubjPoly, PGPCPolygon ClipPoly, PGPCPolygon Res);
Delphi
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.

ParameterDescription
IGPC_Context handle (unused for any per-call state).
OperationgpcDiff(0)/gpcInt(1)/gpcXor(2)/gpcUnion(3).
SubjPoly, ClipPolyRead-only input polygons (each may have multiple contours).
ResOutput: 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)

wrappers/dotnet/LumasPdf.cs
public static extern int gpcClipPoly(IntPtr IGPC_, TGPCOp Operation, IntPtr SubjPoly, IntPtr ClipPoly, IntPtr Res);
Area
Graphics
Category

Polygon Clipper

Exported names

gpcClipPoly

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.