I was using this library for a project of mine, and I came across a bug caused by the algorithm generating a triangulation that badly fails to meet the Delaunay condition.
Here is code that demonstrates the bug:
use delaunator::{triangulate, Point};
fn main {
let points_raw = [
[-1.0849334460551594, -1.0849334460551594], // 0
[-1.5265847189170323, -1.5265847189170323], // 1
[-2.095815826893781, -1.274850699584578], // 2
[-2.770865690566727, -0.9763199041819535], // 3
[-3.6843898126113546, -0.5723274031100705], // 4
[-4.403658177176129, -0.25424163117441645], // 5
[-5.02567003534954, 0.020833892521026076], // 6
[-5.701084620214019, 0.3195259804640507], // 7
[-6.561463270870451, 0.7000156846325452], // 8
[-7.31105511135829, 1.0315115642859167], // 9
[-8.0, 1.336187228503853], // 10
[-7.339371017948894, 1.1048861305058357], // 11
[-6.616986689211032, 0.8519630935920505], // 12
[-5.816767071935726, 0.5717881676590966], // 13
[-5.121128245254447, 0.3282293338915143], // 14
[-4.512948676142796, 0.11529195763725286], // 15
[-3.850960067633096, -0.11648517623155441], // 16
[-3.1594534122386113, -0.3585972436874558], // 17
[-2.288934450277422, -0.663385554827794], // 18
[-1.6751076145244035, -0.8783001664294665], // 19
];
let mut points = Vec::with_capacity(20);
for [x, y] in &points_raw {
points.push(Point { x: *x, y: *y });
}
let tris = triangulate(&points).unwrap();
println!("{:?}", tris.triangles);
}
The output is:
[5, 6, 15, 6, 14, 15, 14, 16, 15, 15, 16, 5, 6, 7, 14, 16, 4, 5, 5, 4, 6, 7, 13, 14, 16, 17, 4, 14, 17, 16, 9, 8, 7, 7, 8, 13, 17, 3, 4, 4, 3, 6, 8, 12, 13, 19, 18, 17, 17, 18, 3, 6, 9, 7, 8, 9, 12, 18, 2, 3, 9, 11, 12, 12, 11, 13, 13, 11, 14, 14, 19, 17, 18, 19, 2, 19, 1, 2, 2, 10, 3, 10, 0, 3]
Which contains the triangle [10, 0, 3]
. By plotting these points we can see that this triangle definitely shouldn't be part of the Delaunay triangulation, as the circumcircle of these points contains most of the other points:
It looks like there are other triangles in this triangulation that fail the condition. I have idea why this specific set of points causes a problem.
bug