Skip to content

Overlapping triangles on a simple polygon with two holes since 3.1.0 #219

Closed

Description

@EpicDima

The polygon below is simple, and the holes don't touch each other or the outer ring. earcut 3.0.2 returns 11 triangles. Since 3.1.0 it returns 7. Two of them cover the second hole, and one more lies on top of three others.

import earcut, {flatten, deviation} from 'earcut';

const data = flatten([
    [[1, 1], [0, 0], [6, 0], [2, 9]],
    [[3, 3], [4, 2], [3, 4]],
    [[4, 1], [5, 2], [5, 1]]
]);
const triangles = earcut(data.vertices, data.holes);
console.log(triangles.length / 3, deviation(data.vertices, data.holes, 2, triangles)); // 7 0.08888888888888889
Visualization Image

The first hole is bridged to (1, 1). The copy of (1, 1) made for that bridge lies on a straight line between (3, 3) and (0, 0), so filterPoints in eliminateHole removes it. The ray from the second hole then hits the vertex (1, 1) and the new edge from (3, 3) to (0, 0) at the same x, and findHoleBridge keeps the vertex, although the hole is outside its angle.

It happens on bigger inputs too. On a valid outline of a noisy raster region with 9113 holes and 65426 vertices the triangles cover 1.3% more area than the polygon.

Activity

  1. added a commit that references this issue on Nov 6, 2026
    77019d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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