The TClipper object is used to perform boolean 'clipping' operations (intersection, union, difference and xor) on polygons. There are no restrictions on either the number nor the type of polygon that can be clipped. Polygons can have holes, be self-intersecting and even have coincident edges.
Example |
---|
uses GR32, GR32_Clipper; ... var i: integer; subj, clip, solution: TArrayOfArrayOfFloatPoint; begin setlength(subj, 2); setlength(subj[0], 4); subj[0][0] := FloatPoint(180,200); subj[0][1] := FloatPoint(260,200); subj[0][2] := FloatPoint(260,150); subj[0][3] := FloatPoint(180,150); setlength(subj[1], 3); subj[1][0] := FloatPoint(215,160); subj[1][1] := FloatPoint(230,190); subj[1][2] := FloatPoint(200,190); setlength(clip, 1); setlength(clip[0], 4); clip[0][0] := FloatPoint(190,210); clip[0][1] := FloatPoint(240,210); clip[0][2] := FloatPoint(240,130); clip[0][3] := FloatPoint(190,130); with TClipper.Create do try Add(subj, ptSubject); Add(clip, ptClip); Execute(ctIntersection, solution, pftNonZero, pftNonZero); finally free; end; //nb: DrawPolygons is a stub for your own polygon rendering code. DrawPolygons(subj, $160000FF, $600000FF); DrawPolygons(clip, $20FFFF00, $30FF0000); DrawPolygons(solution, $3000FF00, $FF006600); |