clipper2-ts icon indicating copy to clipboard operation
clipper2-ts copied to clipboard

Polygon offsetting generating incorrect coordinates

Open jwoLondon opened this issue 1 year ago • 0 comments

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.

jwoLondon avatar May 20 '24 08:05 jwoLondon