Closed dy closed 6 years ago
Not expected, probably a bug that manifests on data with points uniformly placed on a circle.
Interesting bug. Something about symmetry? Changing the first 3.7974166882130675
to 3.79741668821306
makes it work again. (I made a page)
Likely floating point robustness issues. I'll investigate what's going on this week.
@mourner thanks for that link — the naiveLeftRight function there is something I've done in my own code and it also looks like the area function in delaunator
@redblobgames I believe the numeric issues are related to the inCircle
test, since there are 3 points on a straight line for area
to have an issue in this particular case.
I believe there's nothing we can do on Delaunator side for cases like this — small floating point numbers like this will introduce numerical instability. If I round the example above to 14 digits after the decimal point, it works correctly:
points = points.map(function (p) {
var m = 1e14;
return [Math.round(p[0] * m) / m, Math.round(p[1] * m) / m];
})
Ok, just to let know: it is not a single case, it is at least a family of cases with symmetrical points on circumference, number of points can be any.
Reopening because I found the root cause of this bug, and it’s surprisingly not about floating point error. It’s a bug in the algorithm with a very simple fix. I’ll submit it after writing a better test tomorrow.
Take circumference points:
With delaunay-triangulate we get hull:
Vertices:
With delanuator we get broken image:
Vertices:
Is that expected behavior? (for me no)