Version 6 is a major upgrade from previous versions and quite a number of changes have been made to exposed structures and functions. To minimize inconvenience to existing library users, we provide here what you have to do when you change Clipper 5 to Clipper 6.
To accommodate open paths (lines), new Path and Paths structures replaces Polygon and Polygons structures. This means that you have to change calls to the following functions:
If you have used OffsetPolygons, you have to make major changes in your code, because now there is ClipperOffset class with several functions. The idea is like in Clipper. You add paths using AddPath and AddPaths and then call Execute to make actual offsetting operation. You can offset with several deltas without adding the same path(s) many times.
One of the finest new features is offsetting polylines without need to polygonize polyline by making a reverse copy. AddPath(s) function has EndType parameter, which is etClosedPolygon, if you are offsetting polygon. If you are offsetting polyline, then you have the following alternatives as EndType: etOpenSquare, etOpenRound, etOpenButt, etClosedLine.
From:
var solution = ClipperLib.OffsetPolygons(polygons, delta, ClipperLib.JoinType.jtRound, miterlimit, autofix);
To:
var co = new ClipperLib.ClipperOffset(miterlimit, arctolerance); co.AddPaths(polygons, ClipperLib.JoinType.jtRound, ClipperLib.EndType.etClosedPolygon); var solution = new ClipperLib.Paths(); co.Execute(solution, delta);
From:
function reverse_copy(poly) {
// Make reverse copy of polygons = convert polyline to a 'flat' polygon ...
var k, klen = poly.length, len, j;
for (k = 0; k < klen; k++) {
len = poly[k].length;
poly[k].length = len * 2 - 2;
for (j = 1; j <= len - 2; j++) {
poly[k][len - 1 + j] = {
X: poly[k][len - 1 - j].X,
Y: poly[k][len - 1 - j].Y
}
}
}
}
reverse_copy(polylines);
var solution = ClipperLib.OffsetPolygons(polylines, delta, ClipperLib.JoinType.jtRound, miterlimit, autofix);
To:
var co = new ClipperLib.ClipperOffset(miterlimit, arctolerance); co.AddPaths(polylines, ClipperLib.JoinType.jtRound, ClipperLib.EndType.etOpenRound); var solution = new ClipperLib.Paths(); co.Execute(solution, delta);
Read more in Offsetting tutorial and documentation. There is also a quick starter example.
ExPolygons has been replaced with the PolyTree & PolyNode classes to more fully represent the parent-child relationships of the polygons returned by Clipper. If you want to use still ExPolygons (and not PolyTree only) you have to make the following change:
From:
var expolygons = new ClipperLib.ExPolygons(); cpr.Execute(cliptype, expolygons, subject_filltype, clip_filltype);
To:
var polytree = new ClipperLib.PolyTree(); cpr.Execute(cliptype, polytree, subject_filltype, clip_filltype); var expolygons = ClipperLib.JS.PolyTreeToExPolygons(polytree);
These changes should be enough to migrate from Javascript Clipper 5 to 6. If you need more information of the above, please read <a href="documentation.