I think this is because the author has put in a bit of a fudge to deal with the starting vertex. To avoid processing vertices that are behind the current one in the path, he marks them as visited. However, to allow the path to close, he doesn't mark the starting vertex as visited. This leads to a problem when the starting vertex is a part of a string of colinear vertices, because the cross products in that case will be zero, so when processing the second vertex in the path, it sees the starting vertex as a valid target, with a cross product of zero with the actual next vertex and a distance that is no greater than the actual next vertex. It processes the starting vertex first (since it has index 0), so the vertex it should be visiting next then gets ignored.