using Dijkstra shortest path algorithm to link two vertices, making the opening contour closed