mapbox / delaunator

An incredibly fast JavaScript library for Delaunay triangulation of 2D points
https://mapbox.github.io/delaunator/
ISC License
2.33k stars 142 forks source link

Halfedges not always pointing to opposite edge #11

Closed redblobgames closed 7 years ago

redblobgames commented 7 years ago

Here's a set of points that causes a test in tests.js to fail. Are collinear points a problem? I tried adding Math.random() to each point and this test still fails.

tape("delaunator: properly connected halfedges", function(t) {
    let points = [[122,270],[181,121],[195,852],[204,694],[273,525],[280,355],[31,946],
                         [319,938],[33,625],[344,93],[369,793],[38,18],[426,539],[454,239],
                         [503,51],[506,997],[516,661],[532,386],[619,889],[689,131],[730,511],
                         [747,750],[760,285],[856,83],[88,479],[884,943],[927,696],[960,472],
                         [992,253]];
    var d = new Delaunator(points);
    for (var i = 0; i < d.halfedges.length; i++) {
        var i2 = d.halfedges[i];
        if (i2 !== -1 && d.halfedges[i2] !== i) {
            t.fail('invalid halfedge connection');
        }
    }
    t.pass('halfedges are valid');
    t.end();
});

points

mourner commented 7 years ago

Hmm, weird! Let's investigate.

mourner commented 7 years ago

Reduces test case: [[516,661],[369,793],[426,539],[273,525],[204,694],[747,750],[454,239]]

mourner commented 7 years ago

An even smaller one: [[516,661],[369,793],[426,539],[273,525],[204,694],[454,390]]