Skip to content

turf.intersect(poly1, poly2) crashes with an OOME #2833

@rogup

Description

@rogup

Running this code on v7.2.0 hangs and eventually ends in a OOME

import * as turf from '@turf/turf';
const poly1coords = [
  [-2.232359, 53.349714],
  [-2.23244, 53.349848],
  [-2.232526, 53.349986],
  [-2.23262, 53.350125],
  [-2.232699, 53.350257],
  [-2.232757, 53.350349],
  [-2.232762, 53.350357],
  [-2.232771, 53.350365],
  [-2.232777, 53.350369],
  [-2.232784, 53.350372],
  [-2.23279, 53.350374],
  [-2.232837, 53.350365],
  [-2.232833, 53.35036],
  [-2.232802, 53.350318],
  [-2.232359, 53.349714],
];
const poly2coords = [
  [-2.232359, 53.349714],
  [-2.23244, 53.349848],
  [-2.232526, 53.349986],
  [-2.23262, 53.350125],
  [-2.232699, 53.350257],
  [-2.232757, 53.350349],
  [-2.232762, 53.350357],
  [-2.232771, 53.350365],
  [-2.232777, 53.350369],
  [-2.232784, 53.350372],
  [-2.23279, 53.350374],
  [-2.232834, 53.350366],
  [-2.23283, 53.350359],
  [-2.232808, 53.350326],
  [-2.23281, 53.350329],
  [-2.232802, 53.350318],
  [-2.232359, 53.349714],
];

const poly1 = turf.polygon([poly1coords]);
const poly2 = turf.polygon([poly2coords]);

const intersection = turf.intersect(turf.featureCollection([poly1, poly2]));

The polygons are thin strips of land, almost entirely overlapping apart from the top-left corner:

Image

I've tried running this in different environments (in a Node app, on a browser) and it hits the same error

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions