Skip to content

Triangles outside a simple polygon with two holes, mirror case of #219 #221

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, and still on main after 77019d3, it returns 7, and 3 of them lie outside the polygon.

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

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

The first hole is bridged to (2, 7). The bridge continues the edge from (0, 9) in a straight line, so the second filterPoints in eliminateHole removes bridge itself. Its copy bridge2 then lies on the healed edge, and the second hole bridges into it from outside its angle. It's the same problem as #219 with the other copy of the vertex.

More polygons and visualization Image

1.

[[[2,7],[0,9],[6,6],[5,0]],[[3,6],[5,1],[4,3]],[[3,7],[4,4],[5,2]]]

2.

[[[-6,-4],[0,-5],[1,-6],[5,-4],[5,-2],[7,-2],[8,4],[0,8],[-3,9],[-8,2],[-7,1]],[[1,-4],[2,0],[3,-2]],[[-3,-2],[-4,-4],[-5,-1]],[[3,1],[5,0],[4,2]]]

3.

[[[-7,2],[-8,3],[-3,7],[1,7],[4,6],[7,-2],[9,-3],[0,-9],[-4,-8]],[[3,-2],[2,-4],[4,-2]],[[3,-1],[2,2],[3,0]],[[-2,-3],[2,-3],[0,0]]]

4.

[[[-4,-8],[1,-8],[7,1],[7,2],[8,3],[5,6],[-7,6],[-7,1],[-6,0]],[[-4,-7],[-2,-7],[-3,-6]],[[-1,2],[-1,0],[1,2]],[[-4,-2],[-2,-3],[-2,-2],[-3,-1]],[[4,-2],[3,2],[5,0]]]

Activity

  1. added a commit that references this issue on Nov 6, 2026
    934e54d
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