Search code examples
c#clipper

There is an error when I am using Clipper(C#) to offset contours


There is an error when I am using Clipper(C#) to offset contours, Below is the paths and code:

List<List<IntPoint>> contours = new List<List<IntPoint>>() {
    new List<IntPoint>()
    {
        new IntPoint(89081288,31121153),
        new IntPoint(79573289,41300154),
        new IntPoint(89989888,51429549)
    },
    new List<IntPoint>()
    {
        new IntPoint(103433436,22509154),
        new IntPoint(103687434,32572554),
        new IntPoint(93177234,22454711)
    }
};
List<List<IntPoint>> result = new List<List<IntPoint>>();

ClipperOffset co = new ClipperOffset();
co.AddPaths(contours, JoinType.jtMiter, EndType.etClosedPolygon);
co.Execute(ref result, 1 * 1000000);

Picture is

Offset Error

Thanks a lot😀


Solution

  • Solution: Before AddPaths, ensure the contours are right, like orientation, no self-crossing ... To do that, use Clipper.SimplifyPolygons.

    co.AddPaths(Clipper.SimplifyPolygons(contours), JoinType.jtMiter, EndType.etClosedPolygon);