Skip to content

@turf/difference returns wrong geometry #2865

Open
@MauriceGutmannInit

Description

@MauriceGutmannInit

The turf.difference function consistently returns incorrect results when checking the difference between to polygons.
The actual Result contains an extra point, which is wrong.

Steps to reproduce

  1. create polygons
const sourcePoly = turf.polygon([
        [
          [28, 0],
          [40, 0],
          [40, 40],
          [29, 40],
          [28, 0],
        ],
      ]);
const targetPoly = turf.polygon([
        [
          [40, 29],
          [29, 29],
          [29, 40],
          [40, 40],
          [40, 29],
        ],
      ]);
  1. log difference polygon
const difference= turf.difference(
        turf.featureCollection([sourcePoly, targetPoly]),
      );

Expected Output:

{
          geometry: {
            coordinates: [
              [
                [29, 0],
                [40, 0],
                [40, 29],
                [29, 29],
                [29, 0],
              ],
            ],
            type: "Polygon",
          },
          properties: {},
          type: "Feature",
        },

Actual Result:

{
          geometry: {
            coordinates: [
              [
                [28, 0],
                [40, 0],
                [40, 29],
                [29, 29],
                [29, 40],
                [28, 0],
              ],
            ],
            type: "Polygon",
          },
          properties: {},
          type: "Feature",
        },

Environment
Turf.js version: 7.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions