clipper2-ts
clipper2-ts copied to clipboard
Polygon offsetting generating incorrect coordinates
While offsetting of line features works as expected, polygon offsetting seems to generate incorrect coordinates. For example, in the following which attempts to offset a simple square between [3000,3000] and [4000,4000] by 100 units:
{
const paths = new ClipperLib.Paths64();
paths.push(
ClipperLib.Clipper.makePath([
3000, 3000, 3000, 4000, 4000, 4000, 4000, 3000
])
);
const offsetter = new ClipperLib.ClipperOffset();
offsetter.addPaths(
paths,
ClipperLib.JoinType.Miter,
ClipperLib.EndType.Polygon
);
offsetter.execute(100, paths);
return paths;
}
paths contains
[
[
{x: 2900, y: 2900}
{x: 2900, y: 4000}
{x: 4000, y: 3900}
{x: 4000, y: 4000}
{x: 4100, y: 4000}
{x: 4000, y: 2900}
]
]
but I would expect it to be
[
[
{x: 2900, y: 2900}
{x: 2900, y: 4100}
{x: 4100, y: 4100}
{x: 4100, y: 2900}
]
]
Changing the JoinType generates other artefacts suggesting the core offset coordinates are being incorrectly referenced.
Similar results are generated via the top level InflatePaths function (which BTW, might also benefit from consistent camelCase naming).
As far as I can see, the tests in this package only test line features and not polygons.