Skip to content

Examples

Seth Hillbrand edited this page Oct 28, 2026 · 2 revisions

Home › Examples

Examples

C++ Sample 1:

#include "clipper2/clipper.h"
...
using namespace Clipper2Lib;
int main()
{
  Paths64 subject, clip, solution;
  subject.push_back(MakePath({100, 50, 10, 79, 65, 2, 65, 98, 10, 21}));
  clip.push_back(MakePath({98, 63, 4, 68, 77, 8, 52, 100, 19, 12}));
  solution = Intersect(subject, clip, FillRule::NonZero);    
}

C# Sample 1:

...
using Clipper2Lib;  
...
static void Main(string[] args)
{
  Paths64 subj = new Paths64();
  Paths64 clip = new Paths64();
  subj.Add(Clipper.MakePath(new int[] { 
    100, 50, 10, 79, 65, 2, 65, 98, 10, 21 }));
  clip.Add(Clipper.MakePath(new int[] { 
    98, 63, 4, 68, 77, 8, 52, 100, 19, 12 }));
  Paths64 solution = Clipper.Intersect(subj, clip, FillRule.NonZero);
}

Delphi Sample 1:

uses
  Clipper, Clipper.Core;

var 
  subject, clip, solution: TPaths64;
begin
  SetLength(subject, 1);
  subject[0] := MakePath([100, 50, 10, 79, 65, 2, 65, 98, 10, 21]);
  SetLength(clip, 1);
  clip[0] := MakePath([98, 63, 4, 68, 77, 8, 52, 100, 19, 12]);
  solution := Intersect( subject, clip, frNonZero);

  //DrawPolygons

C++ Sample 2:

#include "clipper2/clipper.h"
...
using namespace Clipper2Lib;

int main()
{
  //set up the subject and clip polygons ...
  Paths64 subject;
  subject.push_back(Ellipse(Rect64(100,100,300,300)));
  subject.push_back(Ellipse(Rect64(125,130,275,180)));
  subject.push_back(Ellipse(Rect64(125,220,275,270)));

  Paths64 clip;
  clip.push_back(Ellipse(Rect64(140,70,220,320));

  //get the intersection
  Paths64 solution = Intersect(subject, clip, FillRule::EvenOdd);

  //DrawPolygons    
}

C# Sample 2:

...
using Clipper2Lib;  
...

static void Main(string[] args)
{
  Paths64 subject = new Paths64(3);
  subject.Add(Ellipse(new Rect64(100,100,300,300)));
  subject.Add(Ellipse(new Rect64(125,130,275,180)));
  subject.Add(Ellipse(new Rect64(125,220,275,270)));

  Paths64 clip = new Paths64(1);
  clip.Add(GetEllipsePoints(new Rect64(140,70,220,320)));

  Paths64 solution = Intersect(subject, clip, FillRule.EvenOdd);

  //DrawPolygons    
}

Delphi Sample 2:

uses
  Img32, Clipper, Clipper.Core;

var
  subject, clip, solution: TPaths64;
begin

  //set up the subject and clip polygons ...
  SetLength(sub, 3);
  subject[0] := Ellipse(Rect64(100,100,300,300));
  subject[1] := Ellipse(Rect64(125,130,275,180));
  subject[2] := Ellipse(Rect64(125,220,275,270));

  SetLength(clip, 1);
  clip[0] := Ellipse(Rect64(140,70,220,320));

  //get the intersection of the subject and clip polygons ...
  solution := Intersect(subject, clip, frEvenOdd);
  //display polygons

Clone this wiki locally