A large part is c+p but the original will not change since it is a sample for the algorithm and it is not a lib. (And I also modified it to work with map data + don't draw on canvas.